class SegmentAnything2ImageModel(fosam.SegmentAnythingModel): (source)
Constructor: SegmentAnything2ImageModel(config)
Wrapper for running Segment Anything 2 inference on images.
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-2-hiera-tiny-image-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 from fiftyone import ViewField as F dataset = foz.load_zoo_dataset("quickstart") dataset = dataset.filter_labels("ground_truth", F("label") == "person") # 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-2-hiera-tiny-image-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-2-hiera-tiny-image-torch") # Automatic segmentation dataset.apply_model(model, label_field="auto") session = fo.launch_app(dataset)
Parameters | |
config | a SegmentAnything2ImageModelConfig |
Method | __init__ |
Undocumented |
Method | _forward |
Undocumented |
Method | _load |
Undocumented |
Method | _load |
Undocumented |
Method | _load |
Undocumented |
Instance Variable | _output |
Undocumented |
Inherited from SegmentAnythingModel
:
Method | predict |
Performs prediction on the given iterable of data. |
Method | _download |
Undocumented |
Method | _forward |
Undocumented |
Method | _forward |
Undocumented |
Method | _forward |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _parse |
Undocumented |
Instance Variable | _curr |
Undocumented |
Instance Variable | _curr |
Undocumented |
Instance Variable | _curr |
Undocumented |
Inherited from TorchSamplesMixin
(via SegmentAnythingModel
):
Method | predict |
Performs prediction on the given data. |
Inherited from SamplesMixin
(via SegmentAnythingModel
, TorchSamplesMixin
):
Method | needs |
Undocumented |
Property | needs |
A dict mapping model-specific keys to sample field names. |
Instance Variable | _fields |
Undocumented |
Inherited from TorchImageModel
(via SegmentAnythingModel
, TorchSamplesMixin
, SamplesMixin
):
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | preprocess |
Undocumented |
Instance Variable | config |
Undocumented |
Property | classes |
The list of class labels for the model, if known. |
Property | device |
The torch:torch.torch.device that the model is using. |
Property | has |
Whether this instance can generate logits. |
Property | mask |
The mask targets for the model, if any. |
Property | media |
The media type processed by the model. |
Property | num |
The number of classes for the model, if known. |
Property | preprocess |
Whether to apply preprocessing transforms for inference, if any. |
Property | ragged |
Whether transforms may return tensors of different sizes. If True, then passing ragged lists of images to predict_all may not be not allowed. |
Property | skeleton |
The keypoint skeleton for the model, if any. |
Property | transforms |
A torchvision.transforms function that will be applied to each input before prediction, if any. |
Property | using |
Whether the model is using GPU. |
Property | using |
Whether the model is using half precision. |
Method | _build |
Undocumented |
Method | _build |
Undocumented |
Method | _load |
Undocumented |
Method | _parse |
Undocumented |
Method | _parse |
Undocumented |
Method | _parse |
Undocumented |
Method | _predict |
Applies a forward pass to the given iterable of data and returns the raw model output with no processing applied. |
Instance Variable | _benchmark |
Undocumented |
Instance Variable | _classes |
Undocumented |
Instance Variable | _device |
Undocumented |
Instance Variable | _mask |
Undocumented |
Instance Variable | _model |
Undocumented |
Instance Variable | _no |
Undocumented |
Instance Variable | _preprocess |
Undocumented |
Instance Variable | _ragged |
Undocumented |
Instance Variable | _skeleton |
Undocumented |
Instance Variable | _transforms |
Undocumented |
Instance Variable | _using |
Undocumented |
Instance Variable | _using |
Undocumented |
Inherited from TorchEmbeddingsMixin
(via SegmentAnythingModel
, TorchSamplesMixin
, SamplesMixin
, TorchImageModel
):
Method | embed |
Generates an embedding for the given data. |
Method | embed |
Generates embeddings for the given iterable of data. |
Method | get |
Returns the embeddings generated by the last forward pass of the model. |
Property | has |
Whether this instance has embeddings. |
Instance Variable | _as |
Undocumented |
Instance Variable | _embeddings |
Undocumented |
Inherited from LogitsMixin
(via SegmentAnythingModel
, TorchSamplesMixin
, SamplesMixin
, TorchImageModel
, TorchEmbeddingsMixin
, EmbeddingsMixin
, TorchModelMixin
):
Method | store |
Undocumented |
Property | store |
Whether the model should store logits in its predictions. |
Instance Variable | _store |
Undocumented |
Inherited from Model
(via SegmentAnythingModel
, TorchSamplesMixin
, SamplesMixin
, TorchImageModel
, TorchEmbeddingsMixin
, EmbeddingsMixin
, TorchModelMixin
, LogitsMixin
):
Property | can |
Whether this instance can generate prompt embeddings. |