labelr 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- labelr/__init__.py +0 -0
- labelr/__main__.py +4 -0
- labelr/annotate.py +107 -0
- labelr/apps/__init__.py +0 -0
- labelr/apps/datasets.py +227 -0
- labelr/apps/projects.py +353 -0
- labelr/apps/users.py +36 -0
- labelr/check.py +86 -0
- labelr/config.py +1 -0
- labelr/export.py +270 -0
- labelr/main.py +269 -0
- labelr/sample.py +186 -0
- labelr/triton/object_detection.py +241 -0
- labelr/types.py +16 -0
- labelr-0.1.0.dist-info/LICENSE +661 -0
- labelr-0.1.0.dist-info/METADATA +160 -0
- labelr-0.1.0.dist-info/RECORD +20 -0
- labelr-0.1.0.dist-info/WHEEL +5 -0
- labelr-0.1.0.dist-info/entry_points.txt +2 -0
- labelr-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: labelr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: datasets>=3.2.0
|
|
9
|
+
Requires-Dist: imagehash>=4.3.1
|
|
10
|
+
Requires-Dist: label-studio-sdk>=1.0.8
|
|
11
|
+
Requires-Dist: more-itertools>=10.5.0
|
|
12
|
+
Requires-Dist: openfoodfacts>=2.3.4
|
|
13
|
+
Requires-Dist: protobuf>=5.29.1
|
|
14
|
+
Requires-Dist: typer>=0.15.1
|
|
15
|
+
Provides-Extra: ultralytics
|
|
16
|
+
Requires-Dist: ultralytics>=8.3.49; extra == "ultralytics"
|
|
17
|
+
Provides-Extra: triton
|
|
18
|
+
Requires-Dist: tritonclient>=2.52.0; extra == "triton"
|
|
19
|
+
|
|
20
|
+
# Labelr
|
|
21
|
+
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
28
|
+
It currently allows to:
|
|
29
|
+
|
|
30
|
+
- create Label Studio projects
|
|
31
|
+
- upload images to Label Studio
|
|
32
|
+
- pre-annotate the tasks either with an existing object detection model run by Triton, or with Yolo-World (through Ultralytics)
|
|
33
|
+
- perform data quality checks on Label Studio
|
|
34
|
+
- export the data to Hugging Face Dataset or to local disk
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Python 3.10 or higher is required to run this CLI.
|
|
39
|
+
You need to install the CLI manually for now, there is no project published on Pypi.
|
|
40
|
+
To do so:
|
|
41
|
+
|
|
42
|
+
We recommend to install the CLI in a virtual environment. You can either use pip or conda for that.
|
|
43
|
+
|
|
44
|
+
### Pip
|
|
45
|
+
|
|
46
|
+
Create the virtualenv:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python3 -m venv labelr
|
|
50
|
+
source labelr/bin/activate
|
|
51
|
+
```
|
|
52
|
+
### Conda
|
|
53
|
+
|
|
54
|
+
With conda:
|
|
55
|
+
```bash
|
|
56
|
+
conda create -n labelr python=3.12
|
|
57
|
+
conda activate labelr
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then, clone the repository and install the requirements:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone git@github.com:openfoodfacts/openfoodfacts-ai.git
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
We assume in the following that you have installed the CLI in a virtual environment, and defined the following alias in your shell configuration file (e.g. `.bashrc` or `.zshrc`):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
alias labelr='${VIRTUALENV_DIR}/bin/python3 ${PROJECT_PATH}/main.py'
|
|
74
|
+
```
|
|
75
|
+
or if you are using conda:
|
|
76
|
+
```bash
|
|
77
|
+
alias labelr='${CONDA_PREFIX}/bin/python3 ${PROJECT_PATH}/main.py'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
with `${VIRTUALENV_DIR}` the path to the virtual environment where you installed the CLI and `${PROJECT_PATH}` the path to the root of the project, for example:
|
|
81
|
+
```bash
|
|
82
|
+
${PROJECT_PATH} = /home/user/openfoodfacts-ai/ml_utils/ml_utils_cli
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
### Label Studio integration
|
|
88
|
+
|
|
89
|
+
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](https://labelstud.io/guide/install.html).
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
#### Create a project
|
|
96
|
+
|
|
97
|
+
Once you have a Label Studio instance running, you can create a project with the following command:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
labelr projects create --title my_project --api-key API_KEY --config-file label_config.xml
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
#### Create a dataset file
|
|
106
|
+
|
|
107
|
+
If you have a list of images, for an object detection task, you can quickly create a dataset file with the following command:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
labelr projects create-dataset-file --input-file image_urls.txt --output-file dataset.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
where `image_urls.txt` is a file containing the URLs of the images, one per line, and `dataset.json` is the output file.
|
|
114
|
+
|
|
115
|
+
#### Import data
|
|
116
|
+
|
|
117
|
+
Next, import the generated data to a project with the following command:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
labelr projects import-data --project-id PROJECT_ID --dataset-path dataset.json
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
where `PROJECT_ID` is the ID of the project you created.
|
|
124
|
+
|
|
125
|
+
#### Pre-annotate the data
|
|
126
|
+
|
|
127
|
+
To accelerate annotation, you can pre-annotate the images with an object detection model. We support two pre-annotation backends:
|
|
128
|
+
|
|
129
|
+
- 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.
|
|
130
|
+
|
|
131
|
+
- Ultralytics: you can use the [Yolo-World model from Ultralytics](https://github.com/ultralytics/ultralytics), Ultralytics should be installed in the same virtualenv.
|
|
132
|
+
|
|
133
|
+
To pre-annotate the data with Triton, use the following command:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
labelr projects add-prediction --project-id PROJECT_ID --backend ultralytics --labels 'product' --labels 'price tag' --label-mapping '{"price tag": "price-tag"}'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
where `labels` is the list of labels to use for the object detection task (you can add as many labels as you want).
|
|
140
|
+
For Ultralytics, you can also provide a `--label-mapping` option to map the labels from the model to the labels of the project.
|
|
141
|
+
|
|
142
|
+
By default, for Ultralytics, the `yolov8x-worldv2.pt` model is used. You can change the model by setting the `--model-name` CLI option.
|
|
143
|
+
|
|
144
|
+
#### Export the data
|
|
145
|
+
|
|
146
|
+
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:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
labelr datasets export --project-id PROJECT_ID --from ls --to ultralytics --output-dir output --label-names 'product,price-tag'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
To export the data to a Hugging Face dataset, use the following command:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
labelr datasets export --project-id PROJECT_ID --from ls --to huggingface --repo-id REPO_ID --label-names 'product,price-tag'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
where `REPO_ID` is the ID of the Hugging Face repository where the dataset will be uploaded (ex: `openfoodfacts/food-detection`).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
labelr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
labelr/__main__.py,sha256=G4e95-IfhI-lOmkOBP6kQ8wl1x_Fl7dZlLOYr90K83c,66
|
|
3
|
+
labelr/annotate.py,sha256=8O9SO2thevo_Aa6etIUxCz2xJVXB4MwuSHj4jxz8sqQ,3441
|
|
4
|
+
labelr/check.py,sha256=3wK6mE0UsKvoBNm0_lyWhCMq7gxkv5r50pvO70damXY,2476
|
|
5
|
+
labelr/config.py,sha256=3RXF_NdkSuHvfVMGMlYmjlw45fU77zQkLX7gmZq7NxM,64
|
|
6
|
+
labelr/export.py,sha256=tcOmVnOdJidWfNouNWoQ4OJgHMbbG-bLFHkId9huiS0,10170
|
|
7
|
+
labelr/main.py,sha256=1_cZoJLBMpUV-lnaKb1XaVff4XxWjpIUZbSNQh44tPE,8715
|
|
8
|
+
labelr/sample.py,sha256=cpzvgZWVU6GzwD35tqGKEFVKAgqQbSHlWW6IL9FG15Q,5918
|
|
9
|
+
labelr/types.py,sha256=CahqnkLnGj23Jg0X9nftK7Jiorq50WYQqR8u9Ln4E-k,281
|
|
10
|
+
labelr/apps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
labelr/apps/datasets.py,sha256=DXU8XZx0iEHDI5SvUeI8atCKSUmj9YJwO6xTgMZDgEI,7936
|
|
12
|
+
labelr/apps/projects.py,sha256=HpulSciBVTk1sSR1uXjtHytny9t-rN8wiaQ5llNBX6Y,12420
|
|
13
|
+
labelr/apps/users.py,sha256=twQSlpHxE0hrYkgrJpEFbK8lYfWnpJr8vyfLHLtdAUU,909
|
|
14
|
+
labelr/triton/object_detection.py,sha256=QKUOWiYFH72omyZH4SdbA56JDiVA_e_N8YCSQarkzWQ,7409
|
|
15
|
+
labelr-0.1.0.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
16
|
+
labelr-0.1.0.dist-info/METADATA,sha256=tBsu8c-LehNqjPNiCG3XjRLboQNeq2RSy9JZiv4v9Dc,6528
|
|
17
|
+
labelr-0.1.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
18
|
+
labelr-0.1.0.dist-info/entry_points.txt,sha256=OACukVeR_2z54i8yQuWqqk_jdEHlyTwmTFOFBmxPp1k,43
|
|
19
|
+
labelr-0.1.0.dist-info/top_level.txt,sha256=bjZo50aGZhXIcZYpYOX4sdAQcamxh8nwfEh7A9RD_Ag,7
|
|
20
|
+
labelr-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
labelr
|