Object Detection using Mask-RCNN on a Custom Dataset

Anshraj Shrivastava
5 min readJul 14, 2020

--

https://s3.ap-south-1.amazonaws.com/techleerimages/27161df8-36b0-445a-a106-23f76090e0d4.png

Mask RCNN is a deep neural network aimed to solve the instance segmentation problem in machine learning or computer vision. In other words, it can separate different objects in an image or a video. You give it an image, it gives you the object bounding boxes, classes, and masks.

Generally, when we detect the object (suppose using CNN) there we just draw a boundary around the object but here we will use the segmentation technique. Segmentation is of two types: Semantic Segmentation & Instance Segmentation.

In Semantic, all the objects of the same type are initialized with the same color. In Instance, all the object of the same type is initialized with a different color.

In the above diagram, we can see the difference between both the segmentation by the different color schemes of the chairs.

Here we can see the difference between object detection and the segmentation.

We Would be using Supervise.ly in this project.

Supervise.ly is a powerful platform for computer vision development, where individual researchers and large teams can annotate and experiment with datasets and neural networks.

Before starting we have to log in to this . It provides many models like UNet, Mask RCNN, YOLO, ResNet, and more. And here we will give our dataset to the model.

But supervise.ly doesn’t contain any RAM or CPU to train and test the model and here comes the role of Cloud it can be any cloud, I used AWS here which will give the other necessary resources.

Steps of Mask R-CNN:-

  1. Create Dataset
  2. Do annotation
  3. Dump data in the model
  4. Training the model
  5. Testing / Validation

Task:

Aim: Training Mask-RCNN pre-trained model on a newly created dataset to detect objects from the images with the help of Supervise.ly tools.

Technologies used: Mask-RCNN, Supervise.ly, TensorFlow, DeepLearning, Transfer Learning, OpenCV, AWS Cloud.

Step 1: Log in to Supervise.ly and go to “Import” for importing images.

https://supervise.ly/

Step 2: Drag and drop the images of the object that you want the model to detect and gave a name to the dataset and then Create. Then this dataset would be available in “Projects”.

Created Image Dataset of dogs.

Step 3: Click on the three dots on the dataset and select “Start Annotation”.

Step 4: Select the Polygon object tool and gave the name of the class and a hotkey to it. Then start marking the boundaries of the object. Also, add a Tag to the object. Do this over all the images in the dataset.

Step 5: Now from the three dots on the dataset select “Run DTL” and “From Scratch”.

Step 6: Now You can write your own DTL code or can also re-use my code. ( In case for using my code some changes would be required such as source, etc). Then Start.

My DTL Code:

[
{
“dst”: “$data”,
“src”: [
“Console Dataset/*”
],
“action”: “data”,
“settings”: {
“classes_mapping”: “default”
}
},
{
“dst”: “$flip_vert”,
“src”: [
“$data”
],
“action”: “flip”,
“settings”: {
“axis”: “vertical”
}
},
{
“dst”: “Console Dataset_Aug”,
“src”: [
“$data”,
“$resized_result”,
“$resized_result2”,
“$noise_result”,
“$flip_vert”
],
“action”: “supervisely”,
“settings”: {}
},
{
“action”: “resize”,
“src”: [
“$data”
],
“dst”: “$resized_result”,
“settings”: {
“width”: 800,
“height”: -1,
“aspect_ratio”: {
“keep”: true
}
}
},
{
“action”: “noise”,
“src”: [
“$data”
],
“dst”: “$noise_result”,
“settings”: {
“mean”: 10,
“std”: 60
}
},
{
“action”: “resize”,
“src”: [
“$data”
],
“dst”: “$resized_result2”,
“settings”: {
“width”: 300,
“height”: -1,
“aspect_ratio”: {
“keep”: true
}
}
}
]

Step 7: Wait till the code is running and that could be seen on Tasks. After this is done you can see a new dataset would be created in Projects with more number of images as of previous.

Step 8: Goto Neural Networks and Add a Mask R-CNN COCO model and go fo training.

Step 9: You would see the following message or your screen. This is due to we haven’t attached any agent for training the model ex: AWS cloud.

Step 10: Goto Cluster’s and add an agent. and the following could be seen are the requirements for the agents for the training model.

Step 11: Launch an AWS cloud of EC2 type p2 instance that satisfies the requirement as of above for deep learning.

Step 12: On terminal of your os execute following commands:

ssh -l ec2-user -i mykey.pem IP

sudo su — root

yum install docker

systemctl restart docker

Note:

a. Run terminal on the location where the security key of your AWS cloud is present.

b. In above commands mykey.pem refers to the security key of your AWS cloud.

c. IP refers to the IP address of the launched AWS instance.

Step 13: On terminal of your os execute the command that is given on supervise.ly on agent view.

Step 14: Start training of the mask-R-CNN model from the neural network.

Step 15: After training is completed you can test your model by going for test option and there import new test images and start.

So, Now this model will be able to detect your new object from an image using Mask-R-CNN.

My Github Repository: https://github.com/rajansh87/Object-Detection-using-Mask-RCNN-on-a-Custom-Dataset

Thank You

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response