FastSAM is an image segmentation model trained using 2% of the data in the Segment Anything Model SA-1B dataset.
FastSAM overcomes the computation requirements barrier associated with using SAM by employing a decoupled approach. FastSAM divided the segmentation task into two sequential stages: all-instance segmentation and prompt-guided selection.
To use FastSAM with autodistill, you need to install the following dependency:
pip install autodistill-fastsam
Then, use this code to run inference:
from autodistill_fastsam import FastSAM
from autodistill.detection import CaptionOntology
# define an ontology to map class names to our FastSAM prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
# then, load the model
base_model = FastSAM(
ontology=CaptionOntology(
{
"person": "person",
"a forklift": "forklift"
}
)
)
results = base_model.predict("image.jpeg")