How to Set up Virtual Environment in Anaconda for Image Annotation with LabelImg

Ofinni Oluwaseun Abel
Analytics Vidhya
Published in
6 min readJun 13, 2020

OUTLINE

  • Objective
  • Understanding Image Annotation
  • Different types of Image Annotation
  • Introduction to LabelImg and How to Download the Package
  • Why an Environment is required and How to Setup the Environment
  • Activating the Environment and adding the LabelImg’s directory
  • Installing Pyqt, adding Resources and launching the LabelImg Software
  • What should you do now?

Objective

The focus of this article is to teach you how to create the required environment in Anaconda for your labelImg — an Image Annotation tool. You will also be introduced to Image annotation and labelImg as image annotation tool and the need for an environment just in case you are not familiar with them. Whereas you will get resources that show you how to annotate, this Article will not be dwelling on that. The knowledge from this short article will help you in setting up a conda environment, building your custom Image dataset from scratch, most importantly launching labelImg software on your device.

Understanding Image Annotation

Image Annotation in Machine Learning or Computer Vision is the process of labelling image data with predetermined labels in order to provide the Computer vision or Machine learning model the information on objects represented in an image.

The algorithm would then use the annotated data to learn and recognize similar patterns when presented with new data. Image annotation is a critical part of computer vision.

Source: KDnuggets

The computer vision industry advances almost every minute, thus, the demand for quality and reliable data for training or improving their models kept rising. It might as well interest you to know that, many companies across the World that value Quality, Speed, Scale, Security, and the need to prevent internal biases are already outsourcing their Data Annotation tasks.

“Properly annotated data is very important for the development of autonomous vehicles, computer vision for aerial drones, and many other AI and robotics applications.” — SAS

More also, quality data will continue to be in demand as Computer Vision and Machine Learning keeps evolving. Therefore, the quality of data and the need to minimize the bias in current and future data cannot be underemphasized.

Different types of Image Annotation

  • Bounding box: This is the commonest. The annotation that requires labellers to draw a box around key objects within the image.
  • Polygon annotation: It’s usually used for more precise annotation for items that are irregularly shaped.
  • Line annotation: It is primarily used when a section that needs to be delineated is too small or thin and isn’t achievable by bounding box
  • Point annotation: Point annotation involves the accurate plotting of key points at specified locations on an image. It’s mostly used for facial recognition and sentiment analysis.
  • Semantic Segmentation: This type requires separating an image into sections and classifying each pixel in every segment to the corresponding class label of its object.

Introduction to LabelImg

I will basically describe LabelImg as a graphical image annotation tool. It is written in Python programming language and uses Qt for its graphical interface. Annotations are saved as XML files in PASCAL VOC format, the format used by ImageNet. Besides, it also supports YOLO format. Shall we dive into the practical?

How to Download labelImg

  • Download and install Anaconda (Python 3+) if you do not have it already.
  • Download the ZIP file of labelImg from this Link and unzip it to a preferred location. If you prefer to clone it from GitHub, you can clone from this Link — I will not be discussing much around cloning. You can check out how to Clone GitHub Repo.

Why Virtual Environment is important and how to create one

Virtual environments are useful in Python because they help in creating an isolated space for you to experiment with new versions of third-party modules, new directions with code you’re writing yourself, different versions of Python itself, etc., all without polluting the system’s preinstalled Python version, or whatever you call the “normal” version of Python.

I often prefer to ensure that all my packages are up-to-date by updating them monthly. It is more like a routine check for me, lol. I will explain below the process for creating a python environment in Anaconda Prompt.

  • Launch your Anaconda Prompt
  • Check your Conda version and update, this is likely to take time to finish.
  • Check the list of available Python versions so that you can specify correctly the version to use for your new environment.
  • Create your new environment with any name and Python version of choice. I chose labeller as my new environment name and Python version 3.8.3.
conda -V #It is good practice to check the version of your Conda
conda update conda #Only run this code if it is necessary to update
conda search “^python$” #Check the list of available Python Version
conda create -n labeller python=3.8.3 anaconda #Create the new Env

Activating the Environment and adding the LabelImg’s directory

  • Activate the new environment and let’s prepare to install the labelImg package into the new environment.
conda activate labeller #Activate the new environment with this code

Now that we have activated our new environment. We need to bring the package into our new environment to make it work.

Basically, what you should do here now, go back to the unzipped labelImg folder and copy the file path.

Click on the location where the arrow is and copy the highlighted texts.

Installing Pyqt, adding Resources and launching the LabelImg Software

From the clip below, you will need to change directory using “cd ..” and paste the copied directory as you can see in the first line. The second line will install pyqt to the new environment. I have pyqt already installed, that’s why it says All requested packages already installed. Check the codes below and follow the steps

conda install pyqt=5 # Install pyqt for graphical interface
pyrcc5 -o libs/resources.py resources.qrc # add resources required
python labelImg.py # We will launch our software with this line

Adding the directory is very simple and it takes no time but pyqt might take some time depending on the bandwidth of your internet.

You have added the directory and installed pyqt=5 here.

Simply add the resources required for labelImg to the directory and launch the Software.

What we have been waiting for is finally here! Now you can annotate like a Pro!

Image Labeled with labelImg
A Sample

Without a doubt, annotating images with LabelImg is very easy. Do not forget that there are only two options to save with which are XML files in PASCAL VOC format and TXT for YOLO format.

What should you do now?

Thanks for coming to my Corner. I look forward to seeing you in my next posts. Hug ya!

--

--

Ofinni Oluwaseun Abel
Analytics Vidhya

Enthusiastic about innovative ideas and technology. This attribute helps me learn new things confessedly speaking.