Command line interface (CLI) (original) (raw)

Overview

A simple command line interface for working with CVAT. At the moment it implements a basic feature set but may serve as the starting point for a more comprehensive CVAT administration tool in the future.

The following subcommands are supported:

Installation

To install an official release of CVAT CLI, use this command:

We support Python versions 3.9 and higher.

Usage

The general form of a CLI command is:

$ cvat-cli <common options> <resource> <action> <options>

where:

You can list available subcommands and options using the --help option:

$ cvat-cli --help # get help on available common options and resources
$ cvat-cli <resource> --help # get help on actions for the given resource
$ cvat-cli <resource> <action> --help # get help on action-specific options

The CLI implements alias subcommands for some task actions, so that, for example, cvat-cli ls works the same way as cvat-cli task ls. These aliases are provided for backwards compatibility and are deprecated. Use the task <action> form instead.

Examples - tasks

Create

Description of the options you can find inCreating an annotation task section.

For create a task you need file contain labels in the json format, you can create a JSON label specification by using the label constructor.

Example JSON labels file

[
    {
        "name": "cat",
        "attributes": []
    },
    {
        "name": "dog",
        "attributes": []
    }
]
cvat-cli task create "new task" --labels labels.json local file1.jpg file2.jpg  
cvat-cli --server-host https://example.com --auth user-1 task create "task 1" \  
--labels labels.json local image1.jpg  
cvat-cli --org myorg task create "task 1" --labels labels.json local file1.jpg  
cvat-cli --auth user-1:password task create "task 1" --project_id 1 \  
remote https://github.com/opencv/opencv/blob/master/samples/data/vtest.avi?raw=true  
cvat-cli task create "task 1 sort random" --labels '[{"name": "cat"},{"name": "dog"}]' --chunk_size 8 \  
--sorting-method random --frame_step 10 --copy_data --use_zip_chunks share //share/dataset_1/video.avi  
cvat-cli --auth user-2 task create "task from dataset_1" --labels labels.json \  
--bug_tracker https://bug-tracker.com/0001 --image_quality 75 --annotation_path annotation.xml \  
--annotation_format "CVAT 1.1" local dataset_1/images/  
cvat-cli task create "segmented task 1" --labels labels.json --overlap 5 --segment_size 100 \  
--start_frame 5 --stop_frame 705 --use_cache \  
remote https://github.com/opencv/opencv/blob/master/samples/data/vtest.avi?raw=true  
cvat-cli task create "task with filtered cloud storage data" --labels '[{"name": "car"}]'\  
--use_cache --cloud_storage_id 1 --filename_pattern "test_images/*.jpeg" share manifest.jsonl  
cvat-cli task create "task with filtered cloud storage data" --labels '[{"name": "car"}]'\  
--use_cache --cloud_storage_id 1 --filename_pattern "*" share manifest.jsonl  

Delete

cvat-cli --auth user-1:password task delete 100 101 102  

List

cvat-cli --org myorg task ls  
cvat-cli task ls --json > list_of_tasks.json  

Frames

cvat-cli task frames --outdir images --quality compressed 119 12 15 22  

Export as a dataset

cvat-cli task export-dataset --format "CVAT for images 1.1" 103 output.zip  
cvat-cli task export-dataset --format "COCO 1.0" 104 output.zip  

Import annotations from a dataset

cvat-cli task import-dataset --format "CVAT 1.1" 105 annotation.xml  

Back up a task

cvat-cli task backup 136 task_136.zip  

Create from backup

cvat-cli task create-from-backup task_backup.zip  

Auto-annotate

This command provides a command-line interface to the auto-annotation API.

It can auto-annotate using AA functions implemented in one of the following ways:

  1. As a Python module directly implementing the AA function protocol. Such a module must define the required attributes at the module level.
    For example:
import cvat_sdk.auto_annotation as cvataa  
spec = cvataa.DetectionFunctionSpec(...)  
def detect(context, image):  
    ...  
  1. As a Python module implementing a factory function named create. This function must return an object implementing the AA function protocol. Any parameters specified on the command line using the -p option will be passed to create.
    For example:
import cvat_sdk.auto_annotation as cvataa  
class _MyFunction:  
    def __init__(...):  
        ...  
    spec = cvataa.DetectionFunctionSpec(...)  
    def detect(context, image):  
        ...  
def create(...) -> cvataa.DetectionFunction:  
    return _MyFunction(...)  
cvat-cli task auto-annotate 137 --function-module cvat_sdk.auto_annotation.functions.torchvision_detection \  
    -p model_name=str:fasterrcnn_resnet50_fpn_v2 -p box_score_thresh=float:0.5  
cvat-cli task auto-annotate 138 --function-file path/to/my_func.py  

Note that this command does not modify the Python module search path. If your function module needs to import other local modules, you must add your module directory to the search path if it isn’t there already.

PYTHONPATH=path/to/my-project cvat-cli task auto-annotate 139 --function-module my_func  

Examples - projects

Create

While creating a project, you may optionally define its labels. The project create command accepts labels in the same format as the task create command; see that command’s examples for more information.

cvat-cli project create "new project" --labels labels.json  
cvat-cli project create "new project" --dataset_file coco.zip --dataset_format "COCO 1.0"  

Delete

cvat-cli project delete 100 101 102  

List

cvat-cli project ls --json > list_of_projects.json  

Examples - functions

Note: The functionality described in this section can only be used with the CVAT Enterprise or CVAT Cloud.

Create

cvat-cli function create-native "Faster R-CNN" \  
    --function-module cvat_sdk.auto_annotation.functions.torchvision_detection \  
    -p model_name=str:fasterrcnn_resnet50_fpn_v2  
cvat-cli function run-agent <ID printed by previous command> \  
    --function-module cvat_sdk.auto_annotation.functions.torchvision_detection \  
    -p model_name=str:fasterrcnn_resnet50_fpn_v2  

These commands accept functions that implement theauto-annotation function interfacefrom the SDK, same as the task auto-annotate command. See that command’s examples for information on how to implement these functions and specify them in the command line.

Delete

cvat-cli function delete 100 101