Custom-Instance-Segmentation
Image Segmentation is an important field in computer vision, it is applied in different fields of life. PixelLib is a library created to allow easy application of segmentation to real life problems. Segmentation with coco model is limited as you cannot perform segmentation beyond the 80 classes available in coco.
It is now possible to train your custom objects’ segmentation model with PixelLib Library with just 7 Lines of Code.
Install PixelLib and its dependencies:
Install Tensorflow with:(PixelLib supports tensorflow 2.0 and above)
- pip install tensorflow
Install imgaug with:
- pip install imgaug
Install PixelLib with
- pip install pixellib
The steps required to train a custom model.
STEP1:
Prepare your dataset:
Our goal is to create a model that can perform instance segmentation and object detection on custom images. Collect images for the objects you want to detect and annotate your dataset for custom training. Labelme is the tool employed to perform polygon annotation of objects. Create a root directory or folder and within it create train and test folder. Separate the images required for training (a minimum of 300) and test. Put the images you want to use for training in the train folder and put the images you want to use for testing in the test folder. You will annotate both images in the train and test folder.
Image Annotation With Labelme
Labelme is one of the most convenient annotation tool for polygon annotation. This article explains how to use labelme for annotation of objects. Install labelme and its dependencies.
On Windows:
pip install pyqt5
pip install labelme
On Ubuntu 14.04 / Ubuntu 16.04:
sudo apt-get install python3-pyqt5
sudo pip3 install labelme
In your PC’s anaconda or command prompt just type labelme and labelme’s GUI will be displayed as a separate window.
In the GUI interface click on Open Dir, the second-left corner icon to open directory of the images you intend to annotate.
When you click on open Dir you can choose the folder containing the images.
It will show the first image in the folder you selected.
We intend to annotate the squirrel in this image, click on the create polygons, the seventh-left corner icon of the GUI interface. Drag your mouse to the object in the image.
Start annotating by moving the mouse round the object. Please take note of the starting point because we are going to close the polygon at the starting point. The annotation was started at the neck of the squirrel.
Finalize the annotation at the starting point i.e the neck of the squirrel(when you reached the starting point to join the polygon lines it will show this white circle). We finished the polygon annotation of the squirrel, we have to save it. You click the save icon(fifth-left corner icon) to save it.
It saved annotation in a json format. By default the json file is saved in the image name and in the same directory as the image. Do not alter the name of the saved json file and the directory in which it is saved.
Note: You should ensure that the images and the json files are saved in the same directory. The train images and json files generated by labelme must be in the same train folder. Do not store the json files in a separate folder and do not change the default name of the json’s file corresponding to the image name. The image and json’s file corresponding to it must have the same name. e.g image.jpg and image.json.