Skip to main content

A command-line tool to manage labeling tasks with Label Studio.

Project description

Labelr

Labelr a command line interface that aims to provide a set of tools to help data scientists and machine learning engineers to deal with ML data annotation, data preprocessing and format conversion.

This project started as a way to automate some of the tasks we do at Open Food Facts to manage data at different stages of the machine learning pipeline.

The CLI currently is integrated with Label Studio (for data annotation), Ultralytics (for object detection) and Hugging Face (for model and dataset storage). It only works with some specific tasks (object detection only currently), but it's meant to be extended to other tasks in the future.

It currently allows to:

  • create Label Studio projects
  • upload images to Label Studio
  • pre-annotate the tasks either with an existing object detection model run by Triton, or with Yolo-World (through Ultralytics)
  • perform data quality checks on Label Studio
  • export the data to Hugging Face Dataset or to local disk

Installation

Python 3.10 or higher is required to run this CLI.

To install the CLI, simply run:

pip install labelr

We recommend to install the CLI in a virtual environment. You can either use pip or conda for that.

There are two optional dependencies that you can install to use the CLI:

  • ultralytics: pre-annotate object detection datasets with an ultralytics model (yolo, yolo-world)
  • triton: pre-annotate object detection datasets using a model served by a Triton inference server

To install the optional dependencies, you can run:

pip install labelr[ultralytics,triton]

Usage

Label Studio integration

To create a Label Studio project, you need to have a Label Studio instance running. Launching a Label Studio instance is out of the scope of this project, but you can follow the instructions on the Label Studio documentation.

By default, the CLI will use Open Food Facts Label Studio instance, but you can change the URL by setting the --label-studio-url CLI option.

For all the commands that interact with Label Studio, you need to provide an API key using the --api-key CLI option. You can get an API key by logging in to the Label Studio instance and going to the Account & Settings page.

Create a project

Once you have a Label Studio instance running, you can create a project easily. First, you need to create a configuration file for the project. The configuration file is an XML file that defines the labeling interface and the labels to use for the project. You can find an example of a configuration file in the Label Studio documentation.

For an object detection task, a command allows you to create the configuration file automatically:

labelr projects create-config --labels 'label1' --labels 'label2' --output-file label_config.xml

where label1 and label2 are the labels you want to use for the object detection task, and label_config.xml is the output file that will contain the configuration.

Then, you can create a project on Label Studio with the following command:

labelr projects create --title my_project --api-key API_KEY --config-file label_config.xml

where API_KEY is the API key of the Label Studio instance (API key is available at Account page), and label_config.xml is the configuration file of the project.

Create a dataset file

If you have a list of images, for an object detection task, you can quickly create a dataset file with the following command:

labelr projects create-dataset-file --input-file image_urls.txt --output-file dataset.json

where image_urls.txt is a file containing the URLs of the images, one per line, and dataset.json is the output file.

Import data

Next, import the generated data to a project with the following command:

labelr projects import-data --project-id PROJECT_ID --dataset-path dataset.json

where PROJECT_ID is the ID of the project you created.

Pre-annotate the data

To accelerate annotation, you can pre-annotate the images with an object detection model. We support two pre-annotation backends:

  • Triton: you need to have a Triton server running with a model that supports object detection. The object detection model is expected to be a yolo-v8 model. You can set the URL of the Triton server with the --triton-url CLI option.

  • Ultralytics: you can use the Yolo-World model from Ultralytics, Ultralytics should be installed in the same virtualenv.

To pre-annotate the data with Triton, use the following command:

labelr projects add-prediction --project-id PROJECT_ID --backend ultralytics --labels 'product' --labels 'price tag' --label-mapping '{"price tag": "price-tag"}'

where labels is the list of labels to use for the object detection task (you can add as many labels as you want). For Ultralytics, you can also provide a --label-mapping option to map the labels from the model to the labels of the project.

By default, for Ultralytics, the yolov8x-worldv2.pt model is used. You can change the model by setting the --model-name CLI option.

Export the data

Once the data is annotated, you can export it to a Hugging Face dataset or to local disk (Ultralytics format). To export it to disk, use the following command:

labelr datasets export --project-id PROJECT_ID --from ls --to ultralytics --output-dir output --label-names 'product,price-tag'

where output is the directory where the data will be exported. Currently, label names must be provided, as the CLI does not support exporting label names from Label Studio yet.

To export the data to a Hugging Face dataset, use the following command:

labelr datasets export --project-id PROJECT_ID --from ls --to huggingface --repo-id REPO_ID --label-names 'product,price-tag'

where REPO_ID is the ID of the Hugging Face repository where the dataset will be uploaded (ex: openfoodfacts/food-detection).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labelr-0.3.0.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labelr-0.3.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file labelr-0.3.0.tar.gz.

File metadata

  • Download URL: labelr-0.3.0.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for labelr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b27a682084eccea7eb2d79fab98ead4160afe07204ee271c0fac35a427d38479
MD5 e3ca580a01b413598d2eb11ab3839c9a
BLAKE2b-256 c3266a28a5db84401a13460361f10fcf7fba88b6ae1c48019704ee12c761f2e9

See more details on using hashes here.

File details

Details for the file labelr-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: labelr-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for labelr-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f276653451a3a731a9ecf375b2aa7029f825d7574e0bede6c9196bbd8d3ffbb6
MD5 4aa8c0d5fad2e88f96de5d39df76ce8c
BLAKE2b-256 0bfe97beab41ce8cc00cd903ffce1c11178f5914c3edc14ae08dad16db2dc258

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page