Sign in Get started

Annotations

Read, save and delete an image's annotations; rename, merge or delete classes across a dataset; import COCO, Pascal VOC or YOLO labels. Saving overwrites.

View as Markdown
On this page

Annotations are Pictograph JSON: the class is name (never class), and a polygon is a list of rings (paths). In REST the image’s path follows the dataset: .../annotations/road-signs/val/img-001.jpg.

get

An image’s annotations, typed.

Source: Annotations.get

Arg Type Default Notes
dataset str required Dataset name or id
image str required Image path (addressing)
annotations = client.annotations.get(
    dataset="road-signs",
    image="img-001.jpg",
)
for ann in annotations:
    print(ann.name, ann.type)
pictograph annotations get road-signs img-001.jpg
curl -s "https://api.pictograph.io/api/v1/developer/annotations/road-signs/img-001.jpg" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY"

Returns list[Annotation]

Annotation
Annotation = (
    BBoxAnnotation
    | PolygonAnnotation
    | PolylineAnnotation
    | KeypointAnnotation
)

save

Replace an image’s annotations with the list you send. Needs a member key.

Source: Annotations.save

Arg Type Default Notes
dataset str required Dataset name or id
image str required Image path (addressing)
annotations Sequence[Annotation] required Full list to store; validated before sending and again on the server
from pictograph import BBoxAnnotation, BoundingBox, PolygonAnnotation, PolygonGeometry, Point

result = client.annotations.save(
    dataset="road-signs",
    image="img-001.jpg",
    annotations=[
        BBoxAnnotation(
            id="b41e7d90-5c62-4a38-8e15-9d3f2a7c6b81",
            name="person",
            bounding_box=BoundingBox(x=100, y=200, w=50, h=80),
        ),
        PolygonAnnotation(
            id="c52f8ea1-6d73-4b49-9f26-ae4038d7c592",
            name="car",
            polygon=PolygonGeometry(paths=[
                [Point(x=0, y=0), Point(x=10, y=0), Point(x=10, y=10)],
            ]),
        ),
    ],
)
print(result.previous_count, "to", result.new_count, result.status)
# annotations.json holds the list REST sends as "annotations".
pictograph annotations save road-signs img-001.jpg --file annotations.json
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/road-signs/img-001.jpg" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "annotations": [
      {"id": "b41e7d90-5c62-4a38-8e15-9d3f2a7c6b81", "name": "person", "type": "bbox",
       "bounding_box": {"x": 100, "y": 200, "w": 50, "h": 80}},
      {"id": "c52f8ea1-6d73-4b49-9f26-ae4038d7c592", "name": "car", "type": "polygon",
       "polygon": {"paths": [[{"x": 0, "y": 0}, {"x": 10, "y": 0}, {"x": 10, "y": 10}]]}}
    ]
  }'

Returns SaveResult

SaveResult · 4 fields
class SaveResult(BaseModel):
    """Outcome of Annotations.save."""
    image_id: str
    previous_count: int
    new_count: int
    status: str

A polygon may leave out its bounding_box; it is computed on save. Saving never changes the image’s stage.

bulk_save

Replace the annotations of up to 200 images of one dataset in one call. An image that isn’t in the dataset is listed in failed; the rest still save. Needs a member key.

Source: Annotations.bulk_save

Arg Type Default Notes
dataset str required Dataset name or id
saves Mapping[str, Sequence[Annotation]] required Image path to its annotation list, up to 200 images
from pictograph import BBoxAnnotation, BoundingBox

result = client.annotations.bulk_save(
    dataset="road-signs",
    saves={
        "001.jpg": [
            BBoxAnnotation(id="b41e7d90-5c62-4a38-8e15-9d3f2a7c6b81", name="person",
                           bounding_box=BoundingBox(x=100, y=200, w=50, h=80)),
        ],
        "val/002.jpg": [
            BBoxAnnotation(id="c52f8ea1-6d73-4b49-9f26-ae4038d7c592", name="car",
                           bounding_box=BoundingBox(x=10, y=20, w=30, h=40)),
        ],
    },
)
print(result.saved_count, "saved,", len(result.failed), "failed")
for fail in result.failed:
    print(fail.image_id, fail.error)
# saves.json maps each image's path to its annotation list, like `saves`.
pictograph annotations bulk-save road-signs --file saves.json
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/bulk" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "dataset": "road-signs",
    "saves": [
      {"image": "001.jpg", "annotations": [
        {"id": "b41e7d90-5c62-4a38-8e15-9d3f2a7c6b81", "name": "person", "type": "bbox",
         "bounding_box": {"x": 100, "y": 200, "w": 50, "h": 80}}
      ]},
      {"image": "val/002.jpg", "annotations": [
        {"id": "c52f8ea1-6d73-4b49-9f26-ae4038d7c592", "name": "car", "type": "bbox",
         "bounding_box": {"x": 10, "y": 20, "w": 30, "h": 40}}
      ]}
    ]
  }'

Returns BulkSaveResult

BulkSaveResult · 2 fields
class BulkSaveResult(BaseModel):
    """Outcome of Annotations.bulk_save."""
    saved: list[SaveResult]
    failed: list[BulkSaveFailure]

    # Number of images successfully saved.
    @property
    def saved_count(self) -> int: ...

delete

Remove every annotation from an image. Needs an admin key.

Source: Annotations.delete

Arg Type Default Notes
dataset str required Dataset name or id
image str required Image path (addressing)
result = client.annotations.delete(
    dataset="road-signs",
    image="img-001.jpg",
)
print(result.deleted_count)
pictograph annotations delete road-signs img-001.jpg --yes
curl -s -X DELETE "https://api.pictograph.io/api/v1/developer/annotations/road-signs/img-001.jpg" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY"

Returns DeleteResult

DeleteResult · 2 fields
class DeleteResult(BaseModel):
    """Outcome of Annotations.delete."""
    image_id: str
    deleted_count: int

rename_class

Rename a class in the class list and on every annotation that carries it. Needs a member key.

Source: Annotations.rename_class

Arg Type Default Notes
dataset str required Dataset name or id
class_name str required Current class name
new_name str required New class name
result = client.annotations.rename_class(
    dataset="road-signs",
    class_name="car",
    new_name="vehicle",
)
print(result.annotations_updated, "annotations across", result.images_updated, "images")
# result.config_updated is True when the class list entry was renamed too
pictograph annotations rename-class road-signs car vehicle
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/rename-class" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "class_name": "car", "new_name": "vehicle"}'

Returns RenameClassResult

RenameClassResult · 6 fields
class RenameClassResult(BaseModel):
    """Outcome of Annotations.rename_class."""
    dataset_id: str
    old_name: str
    new_name: str
    images_updated: int
    annotations_updated: int
    config_updated: bool

Renaming onto a name the dataset already has for that annotation type is a 409; merge the two instead. A class only on annotations, not in the class list, still renames (config_updated false).

merge_class

Every annotation of class_name becomes into, and class_name leaves the class list. Needs a member key.

Source: Annotations.merge_class

Arg Type Default Notes
dataset str required Dataset name or id
class_name str required Class to merge away
into str required Class to keep
result = client.annotations.merge_class(
    dataset="road-signs",
    class_name="auto",
    into="vehicle",
)
print(result.annotations_updated, "annotations reassigned to", result.target_name)
pictograph annotations merge-class road-signs auto vehicle
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/merge-class" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "class_name": "auto", "into": "vehicle"}'

Returns MergeClassResult

MergeClassResult · 6 fields
class MergeClassResult(BaseModel):
    """Outcome of Annotations.merge_class."""
    dataset_id: str
    source_name: str
    target_name: str
    images_updated: int
    annotations_updated: int
    config_updated: bool

delete_class

Remove a class from the class list; its annotations stay unless delete_annotations=True. Needs a member key.

Source: Annotations.delete_class

Arg Type Default Notes
dataset str required Dataset name or id
class_name str required Class to delete
class_type str | None None Only the class entry of this annotation type (a name can exist once per type)
delete_annotations bool False Also remove every annotation of the class
# the class list only (its annotations stay)
client.annotations.delete_class(
    dataset="road-signs",
    class_name="obsolete",
)

# and every annotation of the class
result = client.annotations.delete_class(
    dataset="road-signs",
    class_name="obsolete",
    delete_annotations=True,
)
print(result.annotations_removed, "annotations removed")
pictograph annotations delete-class road-signs obsolete --with-annotations --yes
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/delete-class" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "class_name": "obsolete", "delete_annotations": true}'

Returns DeleteClassResult

DeleteClassResult · 5 fields
class DeleteClassResult(BaseModel):
    """Outcome of Annotations.delete_class."""
    dataset_id: str
    name: str
    config_updated: bool
    images_updated: int
    annotations_removed: int

import_coco

Save a COCO file’s annotations onto the dataset’s images, matched by filename. Replaces each matched image’s annotations.

Source: Annotations.import_coco

Arg Type Default Notes
dataset str required Dataset name or id
coco dict[str, Any] | str | Path required COCO dict, file path or JSON string
create_missing_classes bool True Add classes the file uses but the dataset lacks, typed by their first annotation
save_chunk int 200 Images per save request (max 200)
max_workers int 8 Save requests in flight at once (1 saves in order)
report = client.annotations.import_coco(
    dataset="road-signs",
    coco="./instances_train.json",
)
print(report.images_matched, "matched;", report.unmatched_files, "unmatched")
pictograph annotations import-coco road-signs ./instances_train.json
# `import_coco` parses the COCO file on your machine, matches each
# record to an image by filename, then writes them in one call:
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/bulk" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "saves": [{"image": "001.jpg", "annotations": [ ... ]}]}'

Returns AnnotationImportReport

AnnotationImportReport · 7 fields
class AnnotationImportReport(BaseModel):
    """Outcome of an Annotations.import_coco / `import_pascal_voc` / `import_yolo` call."""
    dataset_name: str
    images_matched: int = 0
    images_saved: int = 0
    annotations_saved: int = 0
    unmatched_files: list[str] = []
    failures: list[AnnotationImportFailure] = []
    unconverted: list[str] = []

    @property
    def success(self) -> bool: ...

import_pascal_voc

Save per-image Pascal VOC XML onto the dataset’s images. Replaces each matched image’s annotations.

Source: Annotations.import_pascal_voc

Arg Type Default Notes
dataset str required Dataset name or id
xml_by_filename Mapping[str, str] required Each image’s VOC XML, keyed by image filename (a.jpg) or XML filename (a.xml); an exact name wins, else the one image with that stem
create_missing_classes bool True Add classes the files use but the dataset lacks
save_chunk int 200 Images per save request (max 200)
max_workers int 8 Save requests in flight at once (1 saves in order)
report = client.annotations.import_pascal_voc(
    dataset="road-signs",
    xml_by_filename={"img-001.jpg": Path("./img-001.xml").read_text()},
)
print(report.images_matched, "matched;", report.unmatched_files, "unmatched")
# Every .xml under the folder; each lands on the image its <filename> names.
pictograph annotations import-voc road-signs ./Annotations
# `import_pascal_voc` parses the PASCAL VOC file on your machine, matches each
# record to an image by filename, then writes them in one call:
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/bulk" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "saves": [{"image": "001.jpg", "annotations": [ ... ]}]}'

Returns AnnotationImportReport

AnnotationImportReport · 7 fields
class AnnotationImportReport(BaseModel):
    """Outcome of an Annotations.import_coco / `import_pascal_voc` / `import_yolo` call."""
    dataset_name: str
    images_matched: int = 0
    images_saved: int = 0
    annotations_saved: int = 0
    unmatched_files: list[str] = []
    failures: list[AnnotationImportFailure] = []
    unconverted: list[str] = []

    @property
    def success(self) -> bool: ...

import_yolo

Save per-image YOLO label text onto the dataset’s images. Replaces each matched image’s annotations.

Source: Annotations.import_yolo

Arg Type Default Notes
dataset str required Dataset name or id
labels Mapping[str, str] required Each image’s YOLO label text, keyed by image filename (a.jpg) or label filename (a.txt); an exact name wins, else the one image with that stem
class_names Sequence[str] required Class names in index order (YOLO class 0 is the first)
create_missing_classes bool True Add classes the files use but the dataset lacks
save_chunk int 200 Images per save request (max 200)
max_workers int 8 Save requests in flight at once (1 saves in order)
report = client.annotations.import_yolo(
    dataset="road-signs",
    labels={"img-001.jpg": Path("./img-001.txt").read_text()},
    class_names=["stop", "yield", "speed-limit"],
)
print(report.images_matched, "matched;", report.unmatched_files, "unmatched")
# Every .txt under the folder (a.txt labels a.jpg); the class names come from
# --classes, or the export's data.yaml / classes.txt / obj.names.
pictograph annotations import-yolo road-signs ./labels --classes "stop,yield,speed-limit"
# `import_yolo` parses the YOLO file on your machine, matches each
# record to an image by filename, then writes them in one call:
curl -s -X POST "https://api.pictograph.io/api/v1/developer/annotations/bulk" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "road-signs", "saves": [{"image": "001.jpg", "annotations": [ ... ]}]}'

Returns AnnotationImportReport

AnnotationImportReport · 7 fields
class AnnotationImportReport(BaseModel):
    """Outcome of an Annotations.import_coco / `import_pascal_voc` / `import_yolo` call."""
    dataset_name: str
    images_matched: int = 0
    images_saved: int = 0
    annotations_saved: int = 0
    unmatched_files: list[str] = []
    failures: list[AnnotationImportFailure] = []
    unconverted: list[str] = []

    @property
    def success(self) -> bool: ...

Common errors

Status Exception Cause
403 ForbiddenError A key below member (save, bulk_save, class operations) or admin (delete)
404 NotFoundError The dataset or image doesn’t exist in your organization
409 ConflictError rename_class onto a name the dataset has for the same annotation type
422 ValidationError class instead of name, a flat polygon array, or an unknown field
Copied to clipboard