Label images for Machine Learning with python open-source tool. Everything you need is Python set up and the image labeling package installed with Conda or pip. I will show you exactly how to do all that.

Prerequisites:

If you need more help installing Miniconda and setting up python environments for data science experimentation head over to my blog explaining just that!

Create a Python environment

Before installing the leading tool we want to have a clean python environment we can work with.

We can create a clean Python environment with the Conda CLI.

Open a terminal with Conda avaiable. You can test if conda is correctly installed by calling conda in your terminal. In windows it is recomended to use the anaconda comandpromt which is available after installing miniconda on your pc.

To create a new environment execute the following command.

conda create --name data_labeling_tool python 3.7
create a conda python environment using the conda create command
Create a conda python environment using the conda create command

You should now have a clean python environment where we will install the labeling tool.

Before installing a new python package we need to activate the environment where the package should be installed.

conda activate data_labeling_tool 
activate a conda python environment using the conda activate command
Activate a conda python environment using the conda activate command

Install the image labeling package

The previously created Python environment should now be active.

an activated conda python environment
An activated conda python environment

We can now install additional packages to the active environment.

pip install label-studio 
install the label-studio package using the pip install command
Install the label-studio package using the pip install command

When the package is installed you can start the image labeling tool.

label-studio start my_project --init
Command starting the image labeling studio tool on port 8080 on localhost
Command starting the image labeling studio tool on port 8080 on localhost

This command will start the tool on port 8080, it will automatically open in your default browser. Furthermore, if you need to start the tool a second time for the same project, in this example that would be “my_project” you can just leave out the –init part in the command.

the image labeling studio tool started in the browser
The image labeling studio tool started in the browser

Depending on which folder you are in when you start the project the first time with the –init switch, in that folder, there should now be a folder called “my_project”.

The project folder my_project created on your local disk
The project folder my_project created on your local disk

Configure the image labeling project

Before we can start labeling images, the project has to be configured. To do that click on “Setup” on the welcome screen.

start configuring the labeling project from the welcome screen
Start configuring the labeling project from the welcome screen

You can now define your configuration by editing the XML describing what type of labeling you want and what labels you need. We want to label objects in images using bounding boxes.

updating the XML code to describe the labeling configuration
Updating the XML code to describe the labeling configuration

Replace the content in the “Labeling Config” text box with the following and save.

<View>
  <Image name="img" value="$image"></Image>
  <RectangleLabels name="tag" toName="img">
    <Label value="YOUR_LABEL_NAME_01"></Label>
    <Label value="YOUR_LABEL_NAME_02" background="blue"></Label>
  </RectangleLabels>
</View>

Remember to replace the value “YOUR_LABEL_NAME_01” and “YOUR_LABEL_NAME_02” with the label names your want to use.

Import image data

You can now proceed with importing the images you need to label. To do that you can go back to the welcome screen and click “Import”.

start importing images to the labeling project from the welcome screen
Start importing images to the labeling project from the welcome screen

On the next screen, you will be able to import the data you need to label. The easiest way to import the data is to drag and drop all the images.

upload your data by using drag and drop
Upload your data by using drag and drop

When the upload is done, you can click Start Labeling.

after completing the data import start the labeling process
After completing the data import start the labeling process

All uploaded images will now also be present in folder my_project/upload.

imported images are present in the upload folder
Imported images are present in the upload folder

On the labeling screan you can easilly label as many objects as you like on each image. You first have to click the label you want to use then draw rectangles for that label on the image.

click on a label and draw rectangles to as many objects as needed
Click on a label and draw rectangles to as many objects as needed

When there are no more images to label you can either find all labeled data in the folder my_project/completion or you have the option to export the labeled data.

the labeling data are present in the completions folder
The labeling data are present in the completions folder

That’s it, you can now load the JSON files in your machine learning pipeline together with your images and use the images and the related object labels to train your object detection model.

If you are interested in working with machine learning using Python, then head over to my course Introduction to Machine Learning End-to-End. When you finish this course you will have a complete working code, which you can use for other projects!