Utils for Label Studio

Annocation Export

To export annotations from a LabelStudio project, use the cvtk lsexport command. Specify the project ID (--project) and the path for the export file (--output). Additionally, user may need to specify the hostname (--host) and port number (--port). To access Label Studio and extract data from its database, user must provide the Label Studio API key using the --apikey option.

cvtk ls-export --project 0 \
    --output ./output/instances.coco.json \
    --host http://localhost \
    --port 8080 \
    --apikey f6dea26f0a0f81883e04681b4e649c600fe50fc

Executing this command will export the annotations from the project with ID 0 and save them to the designated file (./output/instances.coco.json).

Note that, user can also set the API KEY as an environment variable (LABEL_STUDIO_API_KEY). By doing this, the command will automatically use the API key stored in the environment variable for authentication.

export LABEL_STUDIO_API_KEY=f6dea26f0a0f81883e04681b4e649c600fe50fc

cvtk ls-export --project 0 \
    --output ./output/instances.coco.json \
    --host http://localhost \
    --port 8080 \

ML-Assisted Labeling

The cvtk package allows users to modify the source code generated by cvtk for use in Label Studio’s ML-Assisted Labeling. For example, let’s say the user have generated det.py` for object detection using cvtk.

cvtk create --script det.py --task det

Next, user can run the cvtk ls-backend command to generate the source code and other necessary files for ML-Assisted Labeling in the directory specified by --project argumnet.

export LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/path/to/doc/root

cvtk ls-backend --project lsbackend \
    --source det.py \
    --label ./path/to/label \
    --model ./model/mmdet_20240806.py \
    --weights ./model/mmdet_20240806.pth

Then, navigate to the lsbackend directory and start the server to make it accessible from Label Studio.

gunicorn --bind 0.0.0.0:8020  main:app