Instance Segmentation Using Mask-RCNN

Milind Rastogi
The Startup
Published in
6 min readAug 2, 2020

In this article, I will be creating my own trained model for detecting potholes. For detection, I will be using the instance segmentation technique using the Mask-RCNN with the help of Supervisely.

Before creating our model lets get to know what tools and techniques we are using.

What is Instance Segmentation?

instance segmentation

Instance segmentation is a technique used for detecting by masking or covering a detected object pixel to pixel. Instance segmentation is very useful in Automatic car as we get pixel to pixel result which increases the accuracy of less accidents

Mask-RCNN

Mask-RCNN is a deep neural network aimed to solve instance segmentation problem in machine learning or computer vision. There are two stages of Mask RCNN. First, it generates proposals about the regions where there might be an object based on the input image. Second, it predicts the class of the object, refines the bounding box and generates a mask in pixel level of the object based on the first stage proposal.

Mask-RCNN is actually a trained model but in this article I will be showing you how to fine tune or train the Mask-RCNN model for your own custom objects.

Mask-RCNN structure

What is Supervisely and how to use it ?

Supervisely is a web platform used for solving computer vision problem. With the help of supervisely we can annotate our images very easily and after annotating our image we can easily train our data on any deep learning model without coding.

Yes you read it write we can do any object detection task in supervisely without coding.

Supervisely Workflow

So we have discussed about all the tools and techniques. Let’s directly jump to the practical part.

How to Use Mask R-CNN in Supervisely for Object Detection ?

In this practical, I will be detecting road potholes by masking the detected area.

Collecting and Annotating the Dataset

I have collected the datasset from Kaggle’s Pothole image dataset. You can collect the dataset from here.

Now let’s use supervisely for annotating the images. Before annotating let’s import the data in supervisely.

First create a workspace in supervisely

creating a workspace

Then import the data from your pc. For importing click on the import and then click the start import button.

For annotating the images , click on projects >> Pothole dataset >>From the drop down menu click on Start annotation.

I will be using the Bitmap annotation. Now annotate only that area which you want to detect.

Bitmap annotation

Data augmentation with DTL

After annotating all the images it’s time to augment our data. Augmentation is a technique used for increasing the data samples by doing some small changes like horizontal flipping , vertical flipping , rotating , mirroring , shearing etc to the collected dataset.

In supervisely , I will take help of dtl(Data transformation language) for augmenting the data. You can refer the below json code as a dtl.

select the run DTL option
DTL workflow

Now click the start button. After clicking we can see that a new images folder is created. So our Data augmentation part is done . Let’s move to the next part.

Training Mask-RCNN with Augmented data

I will be using the Mask-RCNN model for training the pothole images.

So click on the neural network option , you will see the list of neural network models . Then Add the Mask-RCNN(keras+TF)(COCO) model.

clone the neural network

Now train the neural network by clicking on Train button

But training our NN gives us error. It gives error because we haven’t given the required agents or the resources. I will be using the aws cloud to give proper agents

Now click on the Cluster page link for creating a cluster

new cluster is created
Requirements for our agent

Using Aws cloud instance for training our model

For using aws services you must have an aws account.

For running an EC2 instance follow the below steps:

  1. First go to AWS EC2 service then click on Launch Instance.After that we are going to select a instance which has Linux , Docker , GPU , Nvidia-Docker.
  2. Select the Deep Learning AMI (Ubuntu 18.04)

3. We are going to select the GPU instance named as p2.xlarge

4. Now go the configure instance and do the following configurations

5. Give a minimum of 90Gib storage.

6. Now after creating a key launch the instance. For logging into your instance use ssh command

instance is launched

For training copy and paste the curl command from supervisely on our ec2 instance.

Running the bash command

Wait for the complete setup to install

Now go to the supervisely train the Mask -RCNN model

First all the images will be downloaded in our instance

Model starts training

We can also see the training graph and logs of our model

So after training your model don’t forget to stop your instance as aws charges on per hourly basis.

Finally after training we can test our model by uploading some testing images. Here is the result of our model , I think it works pretty well.

Pothole image segmentation

Thank you for reading!

I hop you liked my article . Please clap , share and comment.

--

--