SAM3 auto-annotation
Draft labels with SAM3 point, box and text prompts on one image or a whole dataset, then review them before you export and train a model.
On this page
SAM3 draws a label from a point, a box or a phrase. Every label it draws is a draft: review it, then export and train.
One image
from pictograph import Client, PromptResult
client = Client()
result: PromptResult = client.auto_annotate.text(
dataset="Road Signs",
image="img-001.jpg",
text_prompt="stop sign",
)
client.annotations.save(
dataset="Road Signs",
image="img-001.jpg",
annotations=result.annotations,
)
- Text labels every match of a phrase.
- Box labels what one box holds.
- Point labels one object; more points add to or carve from its mask.
client.auto_annotate.point(
dataset="Road Signs",
image="img-001.jpg",
x=240,
y=180,
name="stop_sign",
negative_points=[(120, 300)],
)
client.auto_annotate.box(
dataset="Road Signs",
image="img-001.jpg",
box={"x": 120, "y": 90, "w": 200, "h": 200},
name="stop_sign",
)
Each returns a PromptResult whose annotations you save, edit or export
(arguments). For an image outside a dataset,
client.sam3.predict runs the same prompts and saves nothing.
A whole dataset
from pictograph import AnnotateReport, Client
client = Client()
report: AnnotateReport = client.auto_annotate.dataset(
dataset="Road Signs",
classes=[("stop_sign", "bbox"), ("yield", "polygon")],
)
print(f"{report.annotations_added} annotations across {report.images_processed} images")
pictograph auto-annotate dataset "Road Signs" --classes "stop_sign:bbox,yield:polygon"
One job drafts the dataset (or one folder, with directory=) and saves the results
(arguments).
Naming the classes
Each class is a name and an output_type: polygon (a mask), bbox (its box) or tag (an
image-level label). Any of these forms works:
from pictograph import BatchClass
classes = [("stop_sign", "bbox"), ("yield", "polygon")]
classes = [{"name": "stop_sign", "output_type": "bbox"}]
classes = [BatchClass(name="stop_sign", output_type="bbox")]
A bare string is refused: it has no output type.
Skip or redraft
Images that already have annotations are skipped, so a rerun fills only the gaps.
overwrite=True drafts every image again, keeping its annotations and dropping any draft that
repeats one of them.
More ways to draft
- Your own model -
model="road-signs-detector"drafts with a model you trained. - From an example - draw a few polygons on one image;
similarlabels every object like them. - Small objects -
sahi=Trueruns SAM3 over overlapping tiles (SAHI). - Listed images -
batchdrafts only those;quoteprices a run first.
Review before you export
Drafts aren’t training data until a person checks them. Start with the images whose drafts scored under 0.5, fix them in the editor, then approve each image or send it back with a note:
pictograph images list "Road Signs" --min-confidence-lt 0.5 # drafts scored under 0.5
pictograph images review "Road Signs" 001.jpg # approve
pictograph images review "Road Signs" 002.jpg --request-changes --note "missed the sign on the left"
Then export the dataset and train a model on the export.
Errors
| Status | Exception | Cause |
|---|---|---|
| 404 | NotFoundError |
The dataset or image doesn’t exist |
| 402 | PaymentRequiredError |
The run costs more than your balance |
| 422 | ValidationError |
A class has no output type, or one other than polygon, bbox or tag |
An image that fails is listed in report.failures, never raised. report.images_capped
counts images held back by max_images or the per-run cap; run again to draft them.