Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 090b5a6

Browse files
conflict resolved
1 parent 245d1bd commit 090b5a6

File tree

3 files changed

+582
-0
lines changed

3 files changed

+582
-0
lines changed

README.rst

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
LabelImg
2+
========
3+
4+
.. image:: https://img.shields.io/pypi/v/labelimg.svg
5+
:target: https://pypi.python.org/pypi/labelimg
6+
7+
.. image:: https://img.shields.io/travis/tzutalin/labelImg.svg
8+
:target: https://travis-ci.org/tzutalin/labelImg
9+
10+
.. image:: /resources/icons/app.png
11+
:width: 200px
12+
:align: center
13+
14+
LabelImg is a graphical image annotation tool.
15+
16+
It is written in Python and uses Qt for its graphical interface.
17+
18+
Annotations are saved as XML files in PASCAL VOC format, the format used
19+
by `ImageNet <http://www.image-net.org/>`__. Besides, it also supports YOLO format
20+
21+
.. image:: https://raw.githubusercontent.com/tzutalin/labelImg/master/demo/demo3.jpg
22+
:alt: Demo Image
23+
24+
.. image:: https://raw.githubusercontent.com/tzutalin/labelImg/master/demo/demo.jpg
25+
:alt: Demo Image
26+
27+
`Watch a demo video <https://youtu.be/p0nR2YsCY_U>`__
28+
29+
Installation
30+
------------------
31+
32+
33+
Build from source
34+
~~~~~~~~~~~~~~~~~
35+
36+
Linux/Ubuntu/Mac requires at least `Python
37+
2.6 <https://www.python.org/getit/>`__ and has been tested with `PyQt
38+
4.8 <https://www.riverbankcomputing.com/software/pyqt/intro>`__. However, `Python
39+
3 or above <https://www.python.org/getit/>`__ and `PyQt5 <https://pypi.org/project/PyQt5/>`__ are strongly recommended.
40+
41+
42+
Ubuntu Linux
43+
^^^^^^^^^^^^
44+
45+
Python 3 + Qt5
46+
47+
.. code:: shell
48+
49+
sudo apt-get install pyqt5-dev-tools
50+
sudo pip3 install -r requirements/requirements-linux-python3.txt
51+
make qt5py3
52+
python3 labelImg.py
53+
python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
54+
55+
macOS
56+
^^^^^
57+
58+
Python 3 + Qt5
59+
60+
.. code:: shell
61+
62+
brew install qt # Install qt-5.x.x by Homebrew
63+
brew install libxml2
64+
65+
or using pip
66+
67+
pip3 install pyqt5 lxml # Install qt and lxml by pip
68+
69+
make qt5py3
70+
python3 labelImg.py
71+
python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
72+
73+
74+
Python 3 Virtualenv (Recommended)
75+
76+
Virtualenv can avoid a lot of the QT / Python version issues
77+
78+
.. code:: shell
79+
80+
brew install python3
81+
pip3 install pipenv
82+
pipenv run pip install pyqt5==5.12.1 lxml
83+
pipenv run make qt5py3
84+
pipenv run python3 labelImg.py
85+
[Optional] rm -rf build dist; python setup.py py2app -A;mv "dist/labelImg.app" /Applications
86+
87+
Note: The Last command gives you a nice .app file with a new SVG Icon in your /Applications folder. You can consider using the script: build-tools/build-for-macos.sh
88+
89+
90+
Windows
91+
^^^^^^^
92+
93+
Install `Python <https://www.python.org/downloads/windows/>`__,
94+
`PyQt5 <https://www.riverbankcomputing.com/software/pyqt/download5>`__
95+
and `install lxml <http://lxml.de/installation.html>`__.
96+
97+
Open cmd and go to the `labelImg <#labelimg>`__ directory
98+
99+
.. code:: shell
100+
101+
pyrcc4 -o libs/resources.py resources.qrc
102+
For pyqt5, pyrcc5 -o libs/resources.py resources.qrc
103+
104+
python labelImg.py
105+
python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
106+
107+
Windows + Anaconda
108+
^^^^^^^^^^^^^^^^^^
109+
110+
Download and install `Anaconda <https://www.anaconda.com/download/#download>`__ (Python 3+)
111+
112+
Open the Anaconda Prompt and go to the `labelImg <#labelimg>`__ directory
113+
114+
.. code:: shell
115+
116+
conda install pyqt=5
117+
conda install -c anaconda lxml
118+
pyrcc5 -o libs/resources.py resources.qrc
119+
python labelImg.py
120+
python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
121+
122+
Get from PyPI but only python3.0 or above
123+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124+
This is the simplest (one-command) install method on modern Linux distributions such as Ubuntu and Fedora.
125+
126+
.. code:: shell
127+
128+
pip3 install labelImg
129+
labelImg
130+
labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
131+
132+
133+
Use Docker
134+
~~~~~~~~~~~~~~~~~
135+
.. code:: shell
136+
137+
docker run -it \
138+
--user $(id -u) \
139+
-e DISPLAY=unix$DISPLAY \
140+
--workdir=$(pwd) \
141+
--volume="/home/$USER:/home/$USER" \
142+
--volume="/etc/group:/etc/group:ro" \
143+
--volume="/etc/passwd:/etc/passwd:ro" \
144+
--volume="/etc/shadow:/etc/shadow:ro" \
145+
--volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
146+
-v /tmp/.X11-unix:/tmp/.X11-unix \
147+
tzutalin/py2qt4
148+
149+
make qt4py2;./labelImg.py
150+
151+
You can pull the image which has all of the installed and required dependencies. `Watch a demo video <https://youtu.be/nw1GexJzbCI>`__
152+
153+
154+
Usage
155+
-----
156+
157+
Steps (PascalVOC)
158+
~~~~~~~~~~~~~~~~~
159+
160+
1. Build and launch using the instructions above.
161+
2. Click 'Change default saved annotation folder' in Menu/File
162+
3. Click 'Open Dir'
163+
4. Click 'Create RectBox'
164+
5. Click and release left mouse to select a region to annotate the rect
165+
box
166+
6. You can use right mouse to drag the rect box to copy or move it
167+
168+
The annotation will be saved to the folder you specify.
169+
170+
You can refer to the below hotkeys to speed up your workflow.
171+
172+
Steps (YOLO)
173+
~~~~~~~~~~~~
174+
175+
1. In ``data/predefined_classes.txt`` define the list of classes that will be used for your training.
176+
177+
2. Build and launch using the instructions above.
178+
179+
3. Right below "Save" button in the toolbar, click "PascalVOC" button to switch to YOLO format.
180+
181+
4. You may use Open/OpenDIR to process single or multiple images. When finished with a single image, click save.
182+
183+
A txt file of YOLO format will be saved in the same folder as your image with same name. A file named "classes.txt" is saved to that folder too. "classes.txt" defines the list of class names that your YOLO label refers to.
184+
185+
Note:
186+
187+
- Your label list shall not change in the middle of processing a list of images. When you save an image, classes.txt will also get updated, while previous annotations will not be updated.
188+
189+
- You shouldn't use "default class" function when saving to YOLO format, it will not be referred.
190+
191+
- When saving as YOLO format, "difficult" flag is discarded.
192+
193+
Create pre-defined classes
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
You can edit the
197+
`data/predefined\_classes.txt <https://github.com/tzutalin/labelImg/blob/master/data/predefined_classes.txt>`__
198+
to load pre-defined classes
199+
200+
Hotkeys
201+
~~~~~~~
202+
203+
+--------------------+--------------------------------------------+
204+
| Ctrl + u | Load all of the images from a directory |
205+
+--------------------+--------------------------------------------+
206+
| Ctrl + r | Change the default annotation target dir |
207+
+--------------------+--------------------------------------------+
208+
| Ctrl + s | Save |
209+
+--------------------+--------------------------------------------+
210+
| Ctrl + d | Copy the current label and rect box |
211+
+--------------------+--------------------------------------------+
212+
| Ctrl + Shift + d | Delete the current image |
213+
+--------------------+--------------------------------------------+
214+
| Space | Flag the current image as verified |
215+
+--------------------+--------------------------------------------+
216+
| w | Create a rect box |
217+
+--------------------+--------------------------------------------+
218+
| d | Next image |
219+
+--------------------+--------------------------------------------+
220+
| a | Previous image |
221+
+--------------------+--------------------------------------------+
222+
| del | Delete the selected rect box |
223+
+--------------------+--------------------------------------------+
224+
| Ctrl++ | Zoom in |
225+
+--------------------+--------------------------------------------+
226+
| Ctrl-- | Zoom out |
227+
+--------------------+--------------------------------------------+
228+
| ↑→↓← | Keyboard arrows to move selected rect box |
229+
+--------------------+--------------------------------------------+
230+
231+
**Verify Image:**
232+
233+
When pressing space, the user can flag the image as verified, a green background will appear.
234+
This is used when creating a dataset automatically, the user can then through all the pictures and flag them instead of annotate them.
235+
236+
**Difficult:**
237+
238+
The difficult field is set to 1 indicates that the object has been annotated as "difficult", for example, an object which is clearly visible but difficult to recognize without substantial use of context.
239+
According to your deep neural network implementation, you can include or exclude difficult objects during training.
240+
241+
How to reset the settings
242+
~~~~~~~~~~~~~~~~~~~~~~~~~
243+
244+
In case there are issues with loading the classes, you can either:
245+
246+
1. From the top menu of the labelimg click on Menu/File/Reset All
247+
2. Remove the `.labelImgSettings.pkl` from your home directory. In Linux and Mac you can do:
248+
`rm ~/.labelImgSettings.pkl`
249+
250+
251+
How to contribute
252+
~~~~~~~~~~~~~~~~~
253+
254+
Send a pull request
255+
256+
License
257+
~~~~~~~
258+
`Free software: MIT license <https://github.com/tzutalin/labelImg/blob/master/LICENSE>`_
259+
260+
Citation: Tzutalin. LabelImg. Git code (2015). https://github.com/tzutalin/labelImg
261+
262+
Related and additional tools
263+
~~~~~~~
264+
265+
1. `ImageNet Utils <https://github.com/tzutalin/ImageNet_Utils>`__ to
266+
download image, create a label text for machine learning, etc
267+
2. `Use Docker to run labelImg <https://hub.docker.com/r/tzutalin/py2qt4>`__
268+
3. `Generating the PASCAL VOC TFRecord files <https://github.com/tensorflow/models/blob/4f32535fe7040bb1e429ad0e3c948a492a89482d/research/object_detection/g3doc/preparing_inputs.md#generating-the-pascal-voc-tfrecord-files>`__
269+
4. `App Icon based on Icon by Nick Roach (GPL) <https://www.elegantthemes.com/>`__
270+
5. `Setup python development in vscode <https://tzutalin.blogspot.com/2019/04/set-up-visual-studio-code-for-python-in.html>`__
271+
6. `The link of this project on iHub platform <https://code.ihub.org.cn/projects/260/repository/labelImg>`__
272+
7. `Convert annotation files to CSV format or format for Google Cloud AutoML <https://github.com/tzutalin/labelImg/tree/master/tools>`__
273+
274+
275+
276+
Stargazers over time
277+
~~~~~~~~~~~~~~~~~~~~
278+
279+
.. image:: https://starchart.cc/tzutalin/labelImg.svg
280+

tools/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Additional tools
2+
3+
## Convert the label files to CSV
4+
5+
### Introduction
6+
To train the images on [Google Cloud AutoML](https://cloud.google.com/automl), we should prepare the specific csv files follow [this format](https://cloud.google.com/vision/automl/object-detection/docs/csv-format).
7+
8+
`label_to_csv.py` can convert the `txt` or `xml` label files to csv file. The labels files should strictly follow to below structure.
9+
10+
### Structures
11+
* Images
12+
To train the object detection tasks, all the images should upload to the cloud storage and access it by its name. All the images should stay in the **same buckets** in cloud storage. Also, different classes should have their own folder as below.
13+
```
14+
<bucket_name> (on the cloud storage)
15+
| -- class1
16+
| | -- class1_01.jpg
17+
| | -- class1_02.jpg
18+
| | ...
19+
| -- class2
20+
| | -- class2_01.jpg
21+
| | -- class2_02.jpg
22+
| | ...
23+
| ...
24+
```
25+
Note, URI of the `class1_01.jpg` is `gs://<bucket_name>/class1/class1_01.jpg`
26+
* Labels
27+
There are four types of training data - `TRAINING`, `VALIDATION`, `TEST` and `UNASSIGNED`. To assign different categories, we should create four directories.
28+
Inside each folder, users should create the class folders with the same name in cloud storage (see below structure).
29+
```
30+
labels (on PC)
31+
| -- TRAINING
32+
| | -- class1
33+
| | | -- class1_01.txt (or .xml)
34+
| | | ...
35+
| | -- class2
36+
| | | -- class2_01.txt (or .xml)
37+
| | | ...
38+
| | ...
39+
| -- VALIDATION
40+
| | -- class1
41+
| | | -- class1_02.txt (or .xml)
42+
| | | ...
43+
| | -- class2
44+
| | | -- class2_02.txt (or .xml)
45+
| | | ...
46+
| | ...
47+
| -- TEST
48+
| | (same as TRAINING and VALIDATION)
49+
| -- UNASSIGNED
50+
| | (same as TRAINING and VALIDATION)
51+
```
52+
53+
### Usage
54+
55+
To see the argument of `label_to_csv.py`,
56+
```commandline
57+
python label_to_csv.py -h
58+
```
59+
60+
```commandline
61+
usage: label_to_csv.py [-h] -p PREFIX -l LOCATION -m MODE [-o OUTPUT]
62+
[-c CLASSES]
63+
64+
optional arguments:
65+
-h, --help show this help message and exit
66+
-p PREFIX, --prefix PREFIX
67+
Bucket of the cloud storage path
68+
-l LOCATION, --location LOCATION
69+
Parent directory of the label files
70+
-m MODE, --mode MODE 'xml' for converting from xml and 'txt' for converting
71+
from txt
72+
-o OUTPUT, --output OUTPUT
73+
Output name of csv file
74+
-c CLASSES, --classes CLASSES
75+
Label classes path
76+
```
77+
78+
For example, if mine bucket name is **test**, the location of the label directory is **/User/test/labels**, the mode I choose from is **txt**, the output name and the class path is same as default.
79+
```commandline
80+
python label_to_csv.py \
81+
-p test\
82+
-l /User/test/labels \
83+
-m txt
84+
```
85+
86+
The output file is `res.csv` by default. Afterwards, upload the csv file to the cloud storage and you can start training!
87+

0 commit comments

Comments
 (0)