preface

Labelme is a very useful free tagging software, and bloggers read a lot of other blogs, some are straight translations, some are not comprehensive. It’s a little difficult for beginners to get started. Therefore, this paper mainly introduces how to use Labelme in detail.

Tip: The following is the text of this article

A,labelmeWhat is?

Labelme is a graphical image annotation tool written in Python and using Qt for its graphical interface. To put it bluntly, it has an interface, like software, that you can interact with, but it’s started from the command line, which is slightly more difficult to use than software. Its interface is shown as follows:

Link: Labelme Github.

It has many features, including:

  • Mark the image in the form of polygon, rectangle, circle, multi-segment line, line segment and point (can be used for target detection, image segmentation and other tasks).
  • The image is annotated in the form of flag (which can be used for image classification and cleaning tasks).
  • Video annotation
  • Generate data sets in VOC format
  • Generate data sets in COCO format (for instance segmentation)

Two, quick installation and use

Installation tutorials are all referenced by Labelme Github.

2.1 Windows installation

The steps on the official website are as follows:

# python3
conda create --name=labelme python=3.6
source activate labelme
# conda install -c conda-forge pyside2
# conda install pyqt
# pip install pyqt5 # pyqt5 can be installed via pip on python3
pip install labelme
# or you can install everything by conda command
# conda install labelme -c conda-forge
Copy the code

commentary

  1. forlabelmeCreate a Conda environment named condalableme

  1. Activating the environment

Windows activate Labelme or conda activate Labelme

Seldom use Windows, correct me if I am wrong.

Actually, in this step, I ran into a problem

C:\Windows\system32> conda activate labelme
 
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
 
    $ conda init <SHELL_NAME>
 
Currently supported shells are:
 - bash
 - fish
 - tcsh
 - xonsh
 - zsh
 - powershell
 
See 'conda init --help' for more information and options.
 
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
Copy the code

Initialization of conda, not very understand, finally through the blog to solve 1

The first way I did it

  • First of all to seeconda envThe address of the

  • Mine’s on drive D, so let’s switch to drive D first
  • Conda. bat activate anaconda\envs\labelme

  • Reactivate and you’ll be fine
  1. Install PyQt, as described in the introductionlabelmeIs Qt based, so it must be installedconda/pip install pyqt
  2. pip install labelme

The 2.2 Linux installation

# Ubuntu 14.04 / Ubuntu 16.04
# Python2
# sudo apt-get install python-qt4 # PyQt4
sudo apt-get install python-pyqt5  # PyQt5
sudo pip install labelme
# Python3
sudo apt-get install python3-pyqt5  # PyQt5
sudo pip3 install labelme

# or install standalone executable from:
# https://github.com/wkentaro/labelme/releases
Copy the code

Note: Before using the above installation, as with Winsows, labelme conda environment needs to be created.

2.3 Mac OS Installation

# macOS Sierra
brew install pyqt  # Maybe PyQt5 I used PIP installation
pip install labelme  # both python2/3 should work

# or install standalone executable/app from:
# https://github.com/wkentaro/labelme/releases
Copy the code

Note: THESE three systems I have successfully installed, rest assured ~

Dummy successfully installed

There are these bags as follows

Next time, type Labelme on the command line to open the software. Strictly speaking, it is a GUI interface written in PyQt5.

3. Interface description

As you can see, the interface is pretty neat.

Let’s talk about how to use it. In medical image analysis, I mainly study classification and segmentation, so I focus on explaining how to label classification label and segmentation label.

Create class labels for images

4.1 Parameter Description

Using Labelme –help will show you how to use Labelme, which includes the following parameters

We explain several important parameter Settings

  • --output: Indicates the file storage location. If you give a parameter ending in. Json, a label is written to the file. This means that if you specify the location using.json, only one image can be annotated. If the location does not end in.json, the program assumes it is a directory. Comments are stored in this directory with the name corresponding to the image on which they are annotated.
  • --Flags: Creates category labels for the image, separated by commas.
  • --nosortlabels: Indicates whether to sort labels

For example:

Labelme image1. PNG –output image1.json –flags 0,1

Where image1.png is the address of the image, not the name. Notice the difference, because MY current path is in the current folder where the image is stored, so I type in the name to find the image directly. If your current path is not in the image folder, you need to give the full path of the image, for example :F:\labelmeImage\image1. PNG –output image1.json is to store the labeled result in image1.json file. Because I’m tagging a single image, I end with.json. If you’re tagging a folder, don’t end with.json, just type in the folder you want to store it in. Flags: specify which tags you are classifying, 0,1 indicates two categories. It can also be written as multiple classes, 0,1,2,3,4. Other characters can also be used, such as negative, positive, or cat, dog. And so on ~

View demo: video cannot be added here, go to the public account to view

4.1 Create category labels for all files in a Folder

The command line enters labeme and gives the classification label. After opening the interface on the right side of the picture, import the folder, you can click the image and annotate it. After labeling one image, it is necessary to save it before labeling the second image. If there is no output location, it will be saved in the image folder by default, with the same name as the image and ending with.json.

View demo: video cannot be added here, go to the public account to view

4.2 Creating Split Labels for all files in a folder

Create a split label using the polygon tool, box out the desired area. Experimental data were obtained from Labelme Github





General steps:

  1. runlabelmeAfter that, open the folder
  2. Use the Polygon tool to outline the target
  3. Create the label after the sketch is complete
  4. Fine-tune the bezel. Click Edit polygon, there’s a lot to do. As shown in the picture
  5. The last stored

View demo: video cannot be added here, go to the public account to view

The above is a simple demonstration. The official experiments are as follows:

1. First download the semantic_segmentation folder.

Link: github.com/wkentaro/la… .



Note: the following experiments are terminals opened under this folder

2. Annotate files

labelme data_annotated --labels labels.txt --nodata --validatelabel exact --config '{shift_auto_shape_color: -2}'
Copy the code



The author has labeled it, so let’s open it up.

3. Label format conversion

Since the annotated file is in JSON format, we convert it to an image format or some other format. Use the code labelme2VOC.py given by the author. The main conversion formats are: class name file, jpeg of the original image, NPY of the segmented image, PNG, and JPG of the segmented image superimposed on the original image.



/ labelme2VOC. py data_annotated data_dataset_VOC –labels labels. TXT python labelme2voc.py data_annotated data_dataset_voc –labels labels.txt

In case of error: If the command line cannot modify the code, it is recommended to directly modify the parameter configuration in the Python file, and then run it.

V. Other issues

5.1 How Can I Quickly View a Split JSON File

labelme_draw_json 2011_000003.json
Copy the code

5.2 turn the PNG json

labelme_json_to_dataset apc2016_obj3.json -o apc2016_obj3_json
Copy the code

Json: indicates the JSON file to be converted. Apc2016_obj3_json: indicates the address to save the converted file

PNG: Image file.label. PNG: uint8 label file.label_viz.png: uint8 Visualization of label.png. label_names.txt: Label names for values in label.png.

This is similar to the format conversion described in section 4, where python files are free to change their Settings to suit their needs, while the built-in method is not allowed to change.

Go to Github to read more. That’s it for today.

Even if the work is busy again, insist on sharing, see here, do not like, attention, encourage about 😂

Gongzhonghao: Medical image artificial intelligence combat camp


  1. www.freesion.com/article/842…↩