Skip to main content
The CVAT SDK provides an auto-annotation framework that allows you to apply machine learning models to automatically annotate tasks.

Installation

For auto-annotation with built-in functions, install the pytorch extra:

Overview

The auto-annotation system supports two types of functions:
  • Detection Functions: Apply a model independently to each frame
  • Tracking Functions: Track shapes across multiple frames

Detection Functions

Detection functions process each image independently and return annotations.

Using annotate_task

The main entry point for auto-annotation:

Function Parameters

Client
required
Connected CVAT client
int
required
ID of the task to annotate
DetectionFunction
required
Detection function to apply
ProgressReporter
default:"None"
Progress reporter for tracking progress
bool
default:"False"
If True, remove existing annotations before adding new ones
bool
default:"False"
If True, ignore function labels not in the task. If False, raise error.
float | None
default:"None"
Confidence threshold (0-1) passed to the function. Function may apply its own default.
bool
default:"False"
If True, function must convert mask shapes to polygons

Creating Detection Functions

Function Interface

A detection function must implement the DetectionFunction protocol:

Detection Function Spec

The spec defines what labels your function supports:

Creating Annotations

Use helper functions to create annotations:

Detection Function Context

The context provides frame-specific information:

Built-in Detection Functions

The SDK includes Torchvision-based detection functions:

Object Detection

Instance Segmentation

Classification

Keypoint Detection

Custom Model Example

Here’s a complete example with a custom YOLOv5 model:

Label Mapping

When your function labels don’t exactly match task labels:

Progress Reporting

Track progress with tqdm:

Error Handling

Limitations

Current auto-annotation limitations:
  • Only 2D image tasks are supported (not video)
  • Only detection functions are fully implemented
  • Tracking functions are defined but not yet integrated

Best Practices

  1. Test on Small Tasks: Start with a small task to verify your function works correctly
  2. Use Confidence Thresholds: Set appropriate confidence thresholds to filter low-quality predictions
  3. Clear Existing Annotations Carefully: Use clear_existing=True only when you’re sure
  4. Handle Label Mapping: Ensure your function labels match task labels, or use allow_unmatched_labels=True
  5. Monitor Progress: Use progress reporters for long-running operations
  6. Validate Spec: Make sure your DetectionFunctionSpec has unique IDs and valid attributes

Next Steps