Segment Anything 3 model for use with Autodistill.
Project description
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autodistill_sam3-0.1.0.tar.gz.
File metadata
- Download URL: autodistill_sam3-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4277cf1b038c23a46c47a8ae692131700c345a6d5f3553d1103db7f7a99e1d5a
|
|
| MD5 |
a4d931e047e82ba3cc9dc2c70be98ab3
|
|
| BLAKE2b-256 |
60f85f38a24414dc68f381ba57543c9d270fcb353e4bc6ecebec77e1123fa6d4
|
File details
Details for the file autodistill_sam3-0.1.0-py3-none-any.whl.
File metadata
- Download URL: autodistill_sam3-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c079ff874fd694b58ae97b59426204833b2e36d34254cc464324e08d5eeb2d9d
|
|
| MD5 |
2eea175b9c4e219c5731ecc673bd0e3f
|
|
| BLAKE2b-256 |
039a852d3bb97cf9bad89b3ebec3d6ad094295f55d5d5ec9bc4728213a7019f9
|