Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.

### Added

- Docs for video Auto Label on action-recognition projects:
`Project.autolabel(batch_id, model="video-segment", ontology={"a person jumps": "jump"},
model_options={"sampleFps": 2})` and
`roboflow autolabel start -p <project> --batch-id <batch> -m video-segment --model-options '{"sampleFps": 2}'`
label a batch of videos, and `Workspace.autolabel_job` documents the video
progress fields (`framesPlanned`, `framesSampled`, `videos`, ...). Needs a
Roboflow API release with action-recognition Auto Label
([#585](https://github.com/roboflow/roboflow-python/pull/585)).
- `Project.autolabel(..., keypoint_confidence_threshold=0.75)` and
`roboflow autolabel start --keypoint-confidence 0.75` set the lowest confidence
a predicted keypoint needs to be saved as visible when a keypoint-detection
Expand Down
14 changes: 13 additions & 1 deletion CLI-COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ roboflow autolabel start -p my-project --batch-id <batch-id> -m my-project/3 --m
roboflow autolabel start -p my-project --batch-id <batch-id> -m sam3-rle --existing-annotations merge
roboflow autolabel start -p my-keypoints --batch-id <batch-id> -m my-keypoints/2 --model-type roboflow \
--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 job <job-id>
roboflow autolabel job <job-id> -p other-workspace/my-project
```
Expand All @@ -342,7 +344,17 @@ them, and `merge` keeps them and skips a prediction that overlaps an existing
annotation of the same class (IoU of at least 0.5), so objects that are already
labeled aren't duplicated. Keypoint-detection projects are labeled with a trained
keypoint model; `--keypoint-confidence` sets the lowest confidence a keypoint
needs to be saved as visible (server default 0.6). `job` looks the id up in
needs to be saved as visible (server default 0.6). 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}'`
sets the frames per second the model sees (0.5 to 12, default 8). The job
replaces each video's segments, but leaves a video with frame annotations
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
your default workspace, so when the job was started with a `workspace/project`
shorthand pass the same `-p` to `job`.

Expand Down
9 changes: 6 additions & 3 deletions roboflow/adapters/rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,10 @@ def start_autolabel_job(
Calls ``POST /:workspace/:project/autolabel``. ``model_type`` is sent
as-is: a catalog id from ``list_autolabel_models`` (for example
``gpt-6-astra-boxes`` or ``sam3-rle``) or ``custom_roboflow`` with the
Roboflow model id in ``model_options["modelId"]``. ``ontology`` is keyed
by prompt: ``{"kitten": "cat"}`` labels prompt matches as class ``cat``.
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:
``{"kitten": "cat"}`` labels prompt matches as class ``cat``.
The backend fans
``default_confidence`` out across the ontology when
``confidence_thresholds`` is omitted and defaults ``num_images_to_label``
Expand Down Expand Up @@ -1589,7 +1591,8 @@ def start_autolabel_job(
def get_autolabel_job(api_key, workspace_url, job_id):
"""Fetch per-subjob status and progress for a hosted auto-label job.

Calls ``GET /:workspace/autolabel/jobs/:jobId``.
Calls ``GET /:workspace/autolabel/jobs/:jobId``. Video jobs add
progress fields; ``Workspace.autolabel_job`` lists them.
"""
response = http.get(
f"{API_URL}/{workspace_url}/autolabel/jobs/{job_id}",
Expand Down
18 changes: 12 additions & 6 deletions roboflow/cli/handlers/autolabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def preview(
Optional[float], typer.Option("--confidence", help="Detection threshold from 0.0 to 1.0 (sam3 only)")
] = None,
) -> None:
"""Preview one image with a foundation model. Free: no job is created."""
"""Preview one image with a foundation model. Free: no job is created. Not available for video-segment."""
args = ctx_to_args(ctx, project=project)
resolved_ontology = _parse_ontology(args, ontology, classes)
resolved_image = _parse_image(args, image)
Expand All @@ -62,13 +62,16 @@ def preview(
def start(
ctx: typer.Context,
project: Annotated[str, typer.Option("-p", "--project", help="Project ID")],
batch_id: Annotated[str, typer.Option("--batch-id", help="Source batch ID containing the images to label")],
batch_id: Annotated[
str, typer.Option("--batch-id", help="Source batch ID containing the images (or videos) to label")
],
model: Annotated[
str,
typer.Option(
"-m",
"--model",
help="Foundation model ID from 'autolabel models', or a Roboflow model ID with --model-type roboflow",
help="Foundation model ID from 'autolabel models', a Roboflow model ID with --model-type roboflow, "
"or 'video-segment' for a batch of videos in an action-recognition project",
),
],
model_type: Annotated[
Expand Down Expand Up @@ -104,7 +107,9 @@ def start(
model_options: Annotated[
Optional[str],
typer.Option(
"--model-options", help='JSON model options, e.g. \'{"outputFormat": "polygon"}\', or @options.json'
"--model-options",
help='JSON model options, e.g. \'{"outputFormat": "polygon"}\', or @options.json. '
"For video-segment, only '{\"sampleFps\": 2}' (0.5 to 12 frames per second, default 8)",
),
] = None,
existing_annotations: Annotated[
Expand All @@ -113,7 +118,8 @@ def start(
"--existing-annotations",
help="What to do with annotations already on the batch images: 'replace' (default) removes "
"them, 'preserve' keeps them and adds every prediction, 'merge' keeps them and skips "
"predictions that overlap an existing annotation of the same class",
"predictions that overlap an existing annotation of the same class. video-segment accepts only "
"'replace'",
),
] = None,
preserve_existing: Annotated[
Expand All @@ -129,7 +135,7 @@ def start(
),
] = None,
) -> None:
"""Start a hosted auto-label job over a batch of images."""
"""Start a hosted auto-label job over a batch of images, or of videos with -m video-segment."""
args = ctx_to_args(ctx, project=project)
resolved_ontology = _parse_ontology(args, ontology, classes)
resolved_thresholds = _parse_json_option(args, "--confidence-thresholds", confidence_thresholds)
Expand Down
37 changes: 32 additions & 5 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,8 @@ def autolabel_preview(
) -> Dict:
"""Preview one image with a foundation model before starting an auto-label job.

Image models only: ``video-segment`` has no preview.

Previews are free: no job is created and no credits are spent. Use it to
compare the candidates from ``Workspace.autolabel_models()`` on a sample
image and start the real job with the winner.
Expand Down Expand Up @@ -1377,13 +1379,22 @@ def autolabel(
existing_annotations: Optional[str] = None,
keypoint_confidence_threshold: Optional[float] = None,
) -> Dict:
"""Start a hosted auto-label job over a batch of images.
"""Start a hosted auto-label job over a batch of images, or of videos.

Action-recognition projects label a batch of videos with
``model="video-segment"`` (not listed by ``Workspace.autolabel_models()``).
The job labels every video in the batch (the server refuses a batch of
more than 50 videos) and replaces each video's existing segments; a
video that has frame annotations is left unchanged. Only ``ontology``, ``model_options={"sampleFps": n}``
and ``reviewer_email`` apply; the server refuses the image-only
options and ``existing_annotations="preserve"`` or ``"merge"``.

Args:
batch_id: Source batch containing the images to auto-label.
batch_id: Source batch containing the images (or videos) to auto-label.
model: For ``model_type="foundational"``, a model id from
``Workspace.autolabel_models()`` (e.g. ``"gpt-6-astra-boxes"``,
``"sam3-rle"``, ``"sam3-polygon"``, ``"gemini-3-8-flash-boxes"``). For
``"sam3-rle"``, ``"sam3-polygon"``, ``"gemini-3-8-flash-boxes"``),
or ``"video-segment"`` on an action-recognition project. For
``model_type="roboflow"``, a Roboflow model id such as
``"project-slug/3"`` or ``"workspace-slug/model-id"``.
model_type: ``"foundational"`` (hosted foundation model, sent as-is;
Expand All @@ -1397,6 +1408,11 @@ def autolabel(
prompts are sent to the model; for ``ontologyFormat="classes"``
only the class names are used. Defaults to the dataset's classes
(or the trained model's classes for ``model_type="roboflow"``).
For ``"video-segment"``, the key is the action description the
model reads (``{"a person jumps": "jump"}``), one description
per class; every class must already exist in the project, and a
class given by its own name
(or in a list) uses the project's saved class description.
num_images: Number of images from the batch to label. Defaults to
the whole batch.
confidence: Confidence threshold applied to every class (mirrors
Expand All @@ -1407,7 +1423,9 @@ def autolabel(
reviewer_email: Reviewer for the resulting annotation job. Must be a
workspace member; defaults to the workspace owner.
model_options: Model-specific options, e.g.
``{"outputFormat": "polygon"}`` for segmentation output.
``{"outputFormat": "polygon"}`` for segmentation output. For
``"video-segment"``, only ``{"sampleFps": n}``: the frames per
second the model sees, from 0.5 to 12 (server default 8).
preserve_existing_annotations: Deprecated, use
``existing_annotations="preserve"``. ``True`` is the same as
that mode; ``existing_annotations`` wins when both are set.
Expand Down Expand Up @@ -1435,6 +1453,12 @@ def autolabel(
>>> job = project.autolabel("batch-id", model="gpt-6-astra-boxes",
... ontology={"a cat": "cat", "a dog": "dog"})
>>> project.autolabel_job(job["jobId"])["status"]

Label a batch of videos in an action-recognition project:

>>> job = project.autolabel("video-batch-id", model="video-segment",
... ontology={"a person jumps": "jump"},
... model_options={"sampleFps": 2})
"""
if preserve_existing_annotations is not None:
replacement = "preserve" if preserve_existing_annotations else "replace"
Expand Down Expand Up @@ -1465,7 +1489,10 @@ def autolabel(
)

def autolabel_job(self, job_id: str) -> Dict:
"""Get status and per-subjob progress for an auto-label job started with ``autolabel``."""
"""Get status and progress for an auto-label job started with ``autolabel``.

See ``Workspace.autolabel_job`` for the response fields, including video jobs.
"""
return rfapi.get_autolabel_job(self.__api_key, self.__workspace, job_id)

def get_batches(self) -> Dict:
Expand Down
18 changes: 18 additions & 0 deletions roboflow/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,8 +1773,26 @@ def autolabel_job(self, job_id: str) -> dict:
"""
Get status and per-subjob progress for a hosted auto-label job.

The job ``status`` goes ``pending`` -> ``processing_completion`` ->
``done``; the annotation job (``annotationJobId``) then waits for review.

Video jobs (``model="video-segment"``) also carry ``mediaType: "video"``,
``classes`` (``[{name, description?}]``), ``sampling``
(``{sampleFps, windowSeconds, overlapSeconds}``), ``framesPlanned``,
``framesSampled`` and ``videos``: one entry per video id with
``status`` (``pending``, ``done`` or ``failed``), ``windows`` and, as
the video progresses, ``framesSeen``, ``segments``, ``windowsFailed``,
``unanalysedIntervals`` or ``error``. ``preserved: true`` means the
video had frame annotations, so the job wrote no segments to it;
``truncated: true`` means the job kept only the longest segments.
``numImages`` counts the videos.

Args:
job_id: the ``jobId`` returned by ``Project.autolabel``.

Example:
>>> job = ws.autolabel_job(job_id)
>>> job["status"], job.get("framesSampled"), job.get("framesPlanned")
"""
return rfapi.get_autolabel_job(self.__api_key, self.url, job_id)

Expand Down
23 changes: 23 additions & 0 deletions tests/cli/test_autolabel_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ def test_foundational_start(self, _resolve, mock_api):
keypoint_confidence_threshold=None,
)

@patch("roboflow.util.http.requests.post")
@patch(_RESOLVE_PROJECT, return_value=("key", "ws", "proj"))
def test_video_segment_start_sends_only_the_video_fields(self, _resolve, mock_post):
# video-segment is not in the models catalog; the server owns validation, so nothing client-side may block it,
# and the server refuses any image-only field, so none may leak into the body.
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = {"jobId": "job-1"}
result = runner.invoke(
app,
["autolabel", "start", "-p", "ws/proj", "--batch-id", "videos-1", "-m", "video-segment"]
+ ["--ontology", '{"a person jumps": "jump"}', "--model-options", '{"sampleFps": 2}'],
)
self.assertEqual(result.exit_code, 0, result.output)
self.assertEqual(
mock_post.call_args.kwargs["json"],
{
"batchId": "videos-1",
"modelType": "video-segment",
"ontology": {"a person jumps": "jump"},
"modelOptions": {"sampleFps": 2},
},
)

@patch("roboflow.adapters.rfapi.start_autolabel_job", return_value={"jobId": "job-1"})
@patch(_RESOLVE_PROJECT, return_value=("key", "ws", "proj"))
def test_legacy_preserve_existing_flag(self, _resolve, mock_api):
Expand Down
Loading