Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Segment Anything to the model zoo! #3330

Merged
merged 19 commits into from
Jul 25, 2023
Merged

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Jul 22, 2023

Polishes up @Rusteam's work from #3019.

Segment Anything is now officially available in the FiftyOne Model Zoo! 📈

Box prompt example

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset(
    "quickstart", max_samples=25, shuffle=True, seed=51
)

model = foz.load_zoo_model("segment-anything-vitb-torch")

# Prompt with boxes
dataset.apply_model(
    model,
    label_field="segmentations",
    prompt_field="ground_truth",
)

session = fo.launch_app(dataset)

Keypoint prompt example

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset(
    "coco-2017",
    split="validation",
    label_types="detections",
    classes=["person"],
    max_samples=25,
    only_matching=True,
)

# Generate some keypoints
model = foz.load_zoo_model("keypoint-rcnn-resnet50-fpn-coco-torch")
dataset.default_skeleton = model.skeleton
dataset.apply_model(model, label_field="gt")

model = foz.load_zoo_model("segment-anything-vitb-torch")

# Prompt with keypoints
dataset.apply_model(
    model,
    label_field="segmentations",
    prompt_field="gt_keypoints",
)

session = fo.launch_app(dataset)

Automatic segmentation example

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset(
    "quickstart", max_samples=5, shuffle=True, seed=51
)

model = foz.load_zoo_model("segment-anything-vitb-torch")

# Automatic segmentation
dataset.apply_model(model, label_field="auto")

session = fo.launch_app(dataset)

@brimoor brimoor added feature Work on a feature request model zoo Issues related to the Model Zoo labels Jul 22, 2023
@brimoor brimoor requested a review from a team July 22, 2023 02:07
@brimoor brimoor self-assigned this Jul 22, 2023
Copy link
Contributor

@jacobmarks jacobmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and it works on my machine 👍 . The one thing worth noting is that it doesn't install segment-anything for you. You need to install the package for it to work. Might consider adding the instructions:

pip install git+https://github.com/facebookresearch/segment-anything.git

@brimoor
Copy link
Contributor Author

brimoor commented Jul 25, 2023

LGTM and it works on my machine 👍 . The one thing worth noting is that it doesn't install segment-anything for you. You need to install the package for it to work. Might consider adding the instructions:

pip install git+https://github.com/facebookresearch/segment-anything.git

FYI- without segment-anything installed, this command:

import fiftyone.zoo as foz

model = foz.load_zoo_model("segment-anything-vitb-torch")

should show a helpful error message:

PackageError: The requested operation requires that 'segment-anything' is installed on your machine.

If you think this error is inaccurate, you can set `fiftyone.config.requirement_error_level` to 1 (warning) or 2 (ignore).
See https://docs.voxel51.com/user_guide/config.html for details.

If you want the dependency to be automatically installed, one can use:

model = foz.load_zoo_model("segment-anything-vitb-torch", install_requirements=True)

@brimoor brimoor merged commit 1eafa36 into release/v0.21.5 Jul 25, 2023
@brimoor brimoor deleted the feature/sam branch July 25, 2023 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request model zoo Issues related to the Model Zoo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants