Autodistill Segment Anything 3 Module
This repository contains the code supporting the Segment Anything 3 base model for use with Autodistill.
Segment Anything 3 (SAM3), developed by Meta Research, is a state-of-the-art zero-shot image segmentation model. You can prompt SAM3 with image regions and open text prompts.
Autodistill currently supports using text prompts to auto-label images for use in fine-tuning smaller vision models, such as an RF-DETR object detection model.
The Autodistill SAM 3 package only works on a GPU.
Read the full Autodistill documentation.
Read the SAM3 Autodistill documentation.
Installation
To use SAM3 with Autodistill, you need to install the following dependency:
pip3 install autodistill-sam3
Quickstart
from autodistill_sam3 import SegmentAnything3
from autodistill.detection import CaptionOntology
from autodistill.helpers import load_image
import supervision as sv
# define an ontology to map class names to our SAM 3 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 = SegmentAnything3(
ontology=CaptionOntology(
{
"fruit": "fruit",
"leaf": "leaf"
}
)
)
# run inference on a single iamge
detections = base_model.predict("image.jpg")
image = load_image("image.jpg", return_format="cv2")
# visualise results
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
mask_annotator = sv.MaskAnnotator()
annotated_frame = mask_annotator.annotate(
scene=image.copy(),
detections=detections
)
annotated_frame = label_annotator.annotate(
scene=annotated_frame,
detections=detections,
labels=[base_model.ontology.classes()[class_id] for class_id in detections.class_id]
)
sv.plot_image(annotated_frame)
# label a folder of images
base_model.label("./images_to_label", extension=".jpeg")
License
SAM 3 is licensed under a custom SAM license. See the SAM 3 license in the official facebookresearch/sam3 repository.
🏆 Contributing
We love your input! Please see the core Autodistill contributing guide to get started. Thank you 🙏 to all our contributors!
Release files for autodistill-sam3 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autodistill_sam3-0.1.0.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autodistill_sam3-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / autodistill_sam3-0.1.0.tar.gz
| Download URL | autodistill_sam3-0.1.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4277cf1b038c23a46c47a8ae692131700c345a6d5f3553d1103db7f7a99e1d5a
|
|
BLAKE2b-256 checksum How to use checksums |
60f85f38a24414dc68f381ba57543c9d270fcb353e4bc6ecebec77e1123fa6d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / autodistill_sam3-0.1.0-py3-none-any.whl
| Download URL | autodistill_sam3-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c079ff874fd694b58ae97b59426204833b2e36d34254cc464324e08d5eeb2d9d
|
|
BLAKE2b-256 checksum How to use checksums |
039a852d3bb97cf9bad89b3ebec3d6ad094295f55d5d5ec9bc4728213a7019f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|