Skip to main content
The CVAT SDK provides PyTorch dataset adapters that allow you to use CVAT tasks directly for training deep learning models.

Installation

Install the SDK with PyTorch support:
This installs:
  • torch - PyTorch framework
  • torchvision - Computer vision utilities
  • scikit-image - Image processing
  • numpy - Array operations

TaskVisionDataset

The TaskVisionDataset class wraps a CVAT task as a PyTorch VisionDataset.

Basic Usage

Constructor Parameters

Client
required
Connected CVAT client instance
int
required
ID of the task to load
Callable
default:"None"
Transform function applied to both image and target. Takes (image, target) and returns transformed (image, target).
Callable
default:"None"
Transform function applied only to images
Callable
default:"None"
Transform function applied only to targets
Mapping[str, int]
default:"None"
Custom mapping from label names to indices. If not provided, labels are mapped to indices automatically.
UpdatePolicy
default:"IF_MISSING_OR_STALE"
When to update the local cache. Options: IF_MISSING_OR_STALE, NEVER, ALWAYS.

Working with Samples

Each sample is a tuple of (image, target):

Target Structure

The Target object contains frame annotations:

Custom Label Mapping

Control how label IDs map to indices:

Transforms

Apply torchvision transforms:

Joint Transforms

For transforms that need to modify both image and annotations:

Caching Behavior

The dataset caches task data locally:
Cache location is controlled by the client config:

Training Example: Object Detection

Training Example: Classification

Limitations

The current PyTorch adapter has some limitations:
  • Only tasks with image data are supported (not video)
  • Track annotations are not accessible (only shapes, tags)
  • Deleted frames are automatically omitted

ProjectVisionDataset

For working with entire projects:

Next Steps