Skip to content
Open
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file.

## Unreleased

### Added

- Auto Label with a saved Workflow:
`Project.autolabel("batch-id", model="vehicle-detector", model_type="workflow", workflow_output="predictions", class_mapping={"car": "vehicle"})`
and `roboflow autolabel start --model-type workflow --workflow-output
predictions --class-mapping '{"car": "vehicle"}'`. `model` is the
Workflow's URL, `class_mapping` maps each class it outputs to a project
class (classes left out are dropped), and every mapped class starts at
`confidence` (0.5 when omitted) unless `confidence_thresholds` sets it.
`workflow_inputs` / `--workflow-inputs` fill the Workflow's other inputs
([#594](https://github.com/roboflow/roboflow-python/pull/594)).
- Label by Example:
`Project.autolabel("batch-id", model="gemini-4-argon-boxes", reference_examples=["image-id-1", "image-id-2"])`
and `roboflow autolabel start --reference-example image-id-1
--reference-example image-id-2` show the model up to 10 labeled images of
the project, with their boxes of the job's classes, before every image it
labels. `Project.autolabel_preview` and `roboflow autolabel preview` take
them too, and `roboflow autolabel models` marks the models that take them
(`takesReferenceExamples` in `Workspace.autolabel_models()`)
([#595](https://github.com/roboflow/roboflow-python/pull/595)).

## 1.7.5

### Added
Expand Down
26 changes: 23 additions & 3 deletions CLI-COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,17 @@ roboflow autolabel start -p my-keypoints --batch-id <batch-id> -m my-keypoints/2
--keypoint-confidence 0.7
roboflow autolabel start -p my-actions --batch-id <video-batch-id> -m video-segment \
--ontology '{"a person jumps": "jump"}' --model-options '{"sampleFps": 2}'
roboflow autolabel start -p my-project --batch-id <batch-id> -m vehicle-detector --model-type workflow \
--workflow-output predictions --class-mapping '{"car": "vehicle", "truck": "vehicle"}' --confidence 0.4
roboflow autolabel start -p my-project --batch-id <batch-id> -m gemini-4-argon-boxes \
--ontology '{"a green umbrella": "umbrella"}' --reference-example <image-id> --reference-example <image-id>
roboflow autolabel job <job-id>
roboflow autolabel job <job-id> -p other-workspace/my-project
```

`models` lists the catalog for the workspace (id, the project types each
model labels, availability, credits per image, default). `preview` runs one
model labels, availability, credits per image, default, and whether it takes
reference examples). `preview` runs one
image through a model for free so you can compare candidates before spending
credits. `start` creates the job and prints
`jobId` and `annotationJobId`; poll it with `job`. Pass the ontology either as
Expand All @@ -358,7 +363,11 @@ model whose project types in `models` include `keypoint-detection` (ex:
`gemini-4-argon-keypoints`), which places the keypoints of each class skeleton;
classes without a skeleton get no labels. With a trained keypoint model,
`--keypoint-confidence` sets the lowest confidence a keypoint needs to be saved
as visible (server default 0.6). Action-recognition projects
as visible (server default 0.6). `--reference-example`, repeated for up to 10
images, shows the model labeled images of the project as examples (Label by
Example): each must be in the project's dataset, not only in a batch or in
review, with a box of the job's classes, and only the models marked in the
`EXAMPLES` column of `models` take them. Action-recognition projects
label a batch of up to 50 videos with `-m video-segment` (it is not in
`models`): the ontology maps one action description to each class, and the
class must already exist in the project. `--model-options '{"sampleFps": n}'`
Expand All @@ -368,7 +377,14 @@ unchanged (`preserved: true` in `job`).
Video jobs do not take the image options (`--num-images`, `--confidence`,
`--no-nms`, `--existing-annotations preserve|merge`, ...); the server refuses
them. `job` shows video progress in `framesSampled` / `framesPlanned` and per
video in `videos`. `job` looks the id up in
video in `videos`. `--model-type workflow` labels the batch with the published
version of a saved Workflow: `-m` is its URL (from `roboflow workflow list`), `--workflow-output`
names the output that holds the predictions, and `--class-mapping` maps each
class the Workflow outputs to the project class it is saved as (classes left
out are dropped). Every mapped project class starts at `--confidence` (0.5 when
omitted), or set them one by one with `--confidence-thresholds`. Pass the
Workflow's other inputs with `--workflow-inputs` JSON, and its image input with
`--workflow-image-input` when it is not named `image`. `job` looks the id up in
your default workspace, so when the job was started with a `workspace/project`
shorthand pass the same `-p` to `job`.

Expand All @@ -379,6 +395,10 @@ models = workspace.autolabel_models()["models"]
preview = project.autolabel_preview("sam3-rle", "sample.jpg", ontology={"cat": "cat"})
job = project.autolabel("batch-id", model="gpt-6-2-sol-boxes", ontology={"a cat": "cat"},
size_filter={"minWidth": 20, "minHeight": 20})
job = project.autolabel("batch-id", model="vehicle-detector", model_type="workflow",
workflow_output="predictions", class_mapping={"car": "vehicle"})
job = project.autolabel("batch-id", model="gemini-4-argon-boxes", ontology={"a green umbrella": "umbrella"},
reference_examples=["image-id-1", "image-id-2"])
project.autolabel_job(job["jobId"])["status"]
```

Expand Down
40 changes: 37 additions & 3 deletions roboflow/adapters/rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,15 @@ def _autolabel_response(response):
return _json_response_or_raise(response)


def _reference_examples_payload(image_ids):
"""``referenceExamples``: each labeled image of the project the model sees, by its id."""
if image_ids is None:
return None
if isinstance(image_ids, str):
image_ids = [image_ids]
return [{"imageId": image_id} for image_id in image_ids]


def list_autolabel_models(api_key, workspace_url):
"""Fetch the foundation-model catalog for hosted auto-labeling.

Expand All @@ -1551,13 +1560,16 @@ def preview_autolabel(
image,
ontology=None,
confidence_threshold=None,
reference_examples=None,
):
"""Preview one image with a foundation model before starting a job.

Calls ``POST /:workspace/:project/autolabel/preview``. Free: no job is
created and no credits are spent. ``image`` is
``{"type": "url" | "base64", "value": ...}`` and ``ontology`` is keyed by
prompt: ``{"kitten": "cat"}`` labels prompt matches as class ``cat``.
``reference_examples`` lists the ids of labeled images of the project the
model sees as examples (Label by Example); see ``Project.autolabel``.
Returns
``{model, predictions, summary, blockErrors?}``.
"""
Expand All @@ -1566,6 +1578,8 @@ def preview_autolabel(
payload["ontology"] = ontology
if confidence_threshold is not None:
payload["confidenceThreshold"] = confidence_threshold
if reference_examples is not None:
payload["referenceExamples"] = _reference_examples_payload(reference_examples)
response = http.post(
f"{API_URL}/{workspace_url}/{project_url}/autolabel/preview",
params={"api_key": api_key},
Expand All @@ -1591,15 +1605,26 @@ def start_autolabel_job(
existing_annotations=None,
keypoint_confidence_threshold=None,
size_filter=None,
reference_examples=None,
workflow_id=None,
selected_output_name=None,
image_input_name=None,
input_values=None,
class_mapping=None,
):
"""Start a hosted auto-label job over a batch.

Calls ``POST /:workspace/:project/autolabel``. ``model_type`` is sent
as-is: a catalog id from ``list_autolabel_models`` (for example
``gpt-6-2-sol-boxes`` or ``sam3-rle``) or ``custom_roboflow`` with the
Roboflow model id in ``model_options["modelId"]``, or ``video-segment``
to label a batch of videos in an action-recognition project (see
``Project.autolabel``). ``ontology`` is keyed by prompt:
to label a batch of videos in an action-recognition project, or
``workflow`` to run the saved Workflow whose URL slug is ``workflow_id``
(see ``Project.autolabel``). A Workflow job sends ``workspaceName`` (this
workspace), ``selectedOutputName``, ``classMapping`` (Workflow class to
project class) and ``confidenceThresholds`` with a threshold for every
class it maps to, and optionally ``imageInputName`` (the worker defaults
it to ``image``) and ``inputValues``. ``ontology`` is keyed by prompt:
``{"kitten": "cat"}`` labels prompt matches as class ``cat``.
The backend fans
``default_confidence`` out across the ontology when
Expand All @@ -1611,7 +1636,9 @@ def start_autolabel_job(
predicted keypoint needs to be saved as visible; the server default is
0.6. ``size_filter`` is sent as ``sizeFilter``: any of ``minWidth``,
``maxWidth``, ``minHeight`` and ``maxHeight`` in image pixels, e.g.
``{"minWidth": 20, "maxWidth": 400}``. Returns
``{"minWidth": 20, "maxWidth": 400}``. ``reference_examples`` lists the
ids of labeled images of the project the model sees as examples (Label by
Example), sent as ``referenceExamples``. Returns
``{jobId, annotationJobId, message}``.

Raises:
Expand All @@ -1628,6 +1655,13 @@ def start_autolabel_job(
"modelOptions": model_options,
"keypointConfidenceThreshold": keypoint_confidence_threshold,
"sizeFilter": size_filter,
"referenceExamples": _reference_examples_payload(reference_examples),
"workflowId": workflow_id,
"workspaceName": workspace_url if workflow_id is not None else None,
"selectedOutputName": selected_output_name,
"imageInputName": image_input_name,
"inputValues": input_values,
"classMapping": class_mapping,
}
payload.update({key: value for key, value in optional.items() if value is not None})
payload.update(existing_annotations_flags(existing_annotations))
Expand Down
88 changes: 80 additions & 8 deletions roboflow/cli/handlers/autolabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def preview(
confidence: Annotated[
Optional[float], typer.Option("--confidence", help="Detection threshold from 0.0 to 1.0 (sam3 only)")
] = None,
reference_examples: Annotated[
Optional[list[str]],
typer.Option(
"--reference-example",
help="Label by Example: ID of a labeled image of the project the model sees as an example; repeat for "
"up to 10. Only models with EXAMPLES in 'autolabel models' take them",
),
] = None,
) -> None:
"""Preview one image with a foundation model. Free: no job is created. Not available for video-segment."""
args = ctx_to_args(ctx, project=project)
Expand All @@ -54,6 +62,7 @@ def preview(
image=resolved_image,
ontology=resolved_ontology,
confidence_threshold=confidence,
reference_examples=reference_examples,
),
)

Expand All @@ -71,12 +80,17 @@ def start(
"-m",
"--model",
help="Foundation model ID from 'autolabel models', a Roboflow model ID with --model-type roboflow, "
"a saved Workflow's URL (from 'workflow list') with --model-type workflow, "
"or 'video-segment' for a batch of videos in an action-recognition project",
),
],
model_type: Annotated[
str,
typer.Option("--model-type", help="'foundational' (hosted foundation model) or 'roboflow' (trained model)"),
typer.Option(
"--model-type",
help="'foundational' (hosted foundation model), 'roboflow' (trained model) or 'workflow' (saved "
"Workflow; needs --workflow-output and --class-mapping)",
),
] = "foundational",
classes: Annotated[
Optional[list[str]],
Expand All @@ -94,11 +108,16 @@ def start(
Optional[int], typer.Option("--num-images", help="Number of images to label (default: whole batch)")
] = None,
confidence: Annotated[
Optional[float], typer.Option("--confidence", help="Confidence threshold applied to every class")
Optional[float],
typer.Option("--confidence", help="Confidence threshold applied to every class (Workflow jobs: default 0.5)"),
] = None,
confidence_thresholds: Annotated[
Optional[str],
typer.Option("--confidence-thresholds", help="JSON per-class thresholds, e.g. '{\"cat\": 0.5}'"),
typer.Option(
"--confidence-thresholds",
help="JSON per-class thresholds, e.g. '{\"cat\": 0.5}'. For a Workflow job, one for every project "
"class in --class-mapping",
),
] = None,
no_nms: Annotated[bool, typer.Option("--no-nms", help="Disable non-max suppression")] = False,
reviewer: Annotated[
Expand Down Expand Up @@ -147,18 +166,68 @@ def start(
max_height: Annotated[
Optional[float], typer.Option("--max-height", help="Drop labels whose box is taller, in image pixels")
] = None,
class_mapping: Annotated[
Optional[str],
typer.Option(
"--class-mapping",
help="Workflow jobs: JSON object mapping each class the Workflow outputs to the project class it is "
'saved as, e.g. \'{"car": "vehicle"}\', or @mapping.json. Classes left out are dropped',
),
] = None,
workflow_output: Annotated[
Optional[str],
typer.Option("--workflow-output", help="Workflow jobs: the Workflow output that holds the predictions"),
] = None,
workflow_inputs: Annotated[
Optional[str],
typer.Option(
"--workflow-inputs",
help="Workflow jobs: JSON values for the Workflow's other inputs, e.g. '{\"confidence\": 0.3}', "
"or @inputs.json",
),
] = None,
workflow_image_input: Annotated[
Optional[str],
typer.Option(
"--workflow-image-input", help="Workflow jobs: the Workflow input that takes the image (default: image)"
),
] = None,
reference_examples: Annotated[
Optional[list[str]],
typer.Option(
"--reference-example",
help="Label by Example: ID of a labeled image of the project the model sees as an example; repeat for "
"up to 10. Only models with EXAMPLES in 'autolabel models' take them",
),
] = None,
) -> None:
"""Start a hosted auto-label job over a batch of images, or of videos with -m video-segment."""
"""Start a hosted auto-label job over a batch of images, or of videos with -m video-segment.

With --model-type workflow, a saved Workflow labels the images: -m is its URL, --workflow-output names the
output with the predictions and --class-mapping maps its classes to project classes.
"""
args = ctx_to_args(ctx, project=project)
resolved_ontology = _parse_ontology(args, ontology, classes)
resolved_thresholds = _parse_json_option(args, "--confidence-thresholds", confidence_thresholds)
resolved_options = _parse_json_option(args, "--model-options", model_options)
resolved_mapping = _parse_json_option(args, "--class-mapping", class_mapping)
resolved_inputs = _parse_json_option(args, "--workflow-inputs", workflow_inputs)
bounds = {"minWidth": min_width, "maxWidth": max_width, "minHeight": min_height, "maxHeight": max_height}
size_filter = {key: value for key, value in bounds.items() if value is not None} or None
from roboflow.util.autolabel_utils import resolve_model
from roboflow.util.autolabel_utils import resolve_model, resolve_workflow

def start_job(key: str, workspace: str, proj: str) -> Any:
wire_model_type, wire_options = resolve_model(model, model_type, resolved_options)
thresholds, workflow = resolve_workflow(
model,
model_type,
workflow_output=workflow_output,
class_mapping=resolved_mapping,
workflow_inputs=resolved_inputs,
workflow_image_input=workflow_image_input,
confidence=confidence,
confidence_thresholds=resolved_thresholds,
)
return _rfapi().start_autolabel_job(
key,
workspace,
Expand All @@ -168,7 +237,7 @@ def start_job(key: str, workspace: str, proj: str) -> Any:
ontology=resolved_ontology,
num_images_to_label=num_images,
default_confidence=confidence,
confidence_thresholds=resolved_thresholds,
confidence_thresholds=thresholds,
run_nms=False if no_nms else None,
reviewer_email=reviewer,
model_options=wire_options,
Expand All @@ -179,6 +248,8 @@ def start_job(key: str, workspace: str, proj: str) -> Any:
),
keypoint_confidence_threshold=keypoint_confidence,
size_filter=size_filter,
reference_examples=reference_examples,
**workflow,
)

_project_command(args, start_job)
Expand Down Expand Up @@ -319,13 +390,14 @@ def table(data: Any) -> str:
"default": "yes" if model.get("isDefault") else "",
"credits": model.get("creditsPerImage", ""),
"ontology": model.get("ontologyFormat", ""),
"examples": "yes" if model.get("takesReferenceExamples") else "",
}
for model in data.get("models", [])
]
return format_table(
rows,
columns=["id", "name", "project_types", "available", "default", "credits", "ontology"],
headers=["ID", "NAME", "PROJECT TYPES", "AVAILABLE", "DEFAULT", "CREDITS/IMAGE", "ONTOLOGY"],
columns=["id", "name", "project_types", "available", "default", "credits", "ontology", "examples"],
headers=["ID", "NAME", "PROJECT TYPES", "AVAILABLE", "DEFAULT", "CREDITS/IMAGE", "ONTOLOGY", "EXAMPLES"],
)

_workspace_command(args, lambda key, workspace: _rfapi().list_autolabel_models(key, workspace), text=table)
Loading
Loading