I'm doing a research on "Mask R-CNN
for Object Detection and Segmentation". So I have read the original research paper which presents Mask R-CNN
for object detection, and also I found few implementations of Mask R-CNN
, here and here (by Facebook AI research team called detectron). But they all have used coco datasets for testing.
But I'm quite a bit of confusing for training above implementations with custom data-set which has a large set of images and for each image there is a subset of masks images for marking the objects in the corresponding image.
So I'm pleasure if anyone can post useful resources or code samples for this task.
Note: My dataset has following structure,
It consists with a large number of images and for each image, there are separate image files highlighting the object as a white patch in a black image.
Here is an example image and it's masks:
Image;
Masks;
I have trained https://github.com/matterport/Mask_RCNN 's model for instance segmentation to run on my dataset.
My assumption is that you have all the basic setup done and the model is already running with default dataset and now you want it to run for custom dataset.
Following are the steps
via_region_data.json
inside the individual dataset folder. For eg for training images it would look attrain\via_region_data.json
. You can also change it if you want..py
file (for balloon it will be balloon.py), change the following variablesROOT_DIR
: the absolute path where you have cloned the projectDEFAULT_LOGS_DIR
: This folder will get bigger in size so change this path accordingly (if you are running your code in a low disk storage VM). It will store the.h5
file as well. It will make subfolder inside the log folder with timestamp attached to it..h5
files are roughly 200 - 300 MB per epoch. But guess what this log directory is Tensorboard compatible. You can pass the timestamped subfolder as--logdir
argument while running tensorboard..py
file also has two classes - one class with suffix asConfig
and another class with suffix asDataset
.NAME
: a name for your project.NUM_CLASSES
: it should be one more than your label class because background is also considered as one labelDETECTION_MIN_CONFIDENCE
: by default 0.9 (decrease it if your training images are not of very high quality or you don't have much training data)STEPS_PER_EPOCH
etcYou can now run it directly from terminal
For complete information of the command line arguments for the above line you can see it as a comment at the top of this
.py
file.These are the things which I could recall, I would like to add more steps as I remember. Maybe you can let me know if you are stuck at any particular step, I will elaborate that particular step.
VGG Polygon Schema
Width and Height are optional
Sample load_mask function
For the image segmentation task, there are two ways to provide mask images to the training code.
In Mask R-CNN, you have to follow 2.
Our Mac OS X app RectLabel can export both of mask images.
An index color image which color table corresponds to the object class id.
Gray image for each object which consists of 0:background and 255:foreground.
We provide python code examples of how to load mask images and set to the TFRecord file for the Mask R-CNN code.
COCO JSON file to TFRecord with mask images
https://github.com/ryouchinsa/Rectlabel-support/blob/master/rectlabel_create_coco_tf_record.py
PASCAL VOC XML files to TFRecord with mask images
https://github.com/ryouchinsa/Rectlabel-support/blob/master/rectlabel_create_pascal_tf_record.py
We hope this would help.
So first of all, you need to extract the bounding boxes of each image. That task has to be manually, or you can use tools like OpenCV
edit for open cv
Again for the segments in white, you have to do the best technique with any tool of your choice, I'd do it with OpenCV. The code may be really specific because it can be approached with different techniques. There's no other way because you've got no annotation but masks.
Now you've got your image and your box in a format (x, y, width, height).
Detectron has a JSON file format such as: https://pastebin.com/ewaaC5Bm
Now, you can create a JSON like that with the
images
value, because you've got that information.Since we don't have any segmentation (in your example), let's clarify the parameters that
annotations
are taking:category_id
: This is the id of the category. You can see in the pastebin that the only category I showed hadid = 32
. You'd need to add more categories according to your dataset.bbox
: This is the box we talked about above: [x, y, width, height]Now for
iscrowd
,area
andsegmentation
we can apparently take two approaches: this or this.That way segmentation won't be considered (or will be considered but ignored).
Good luck.