This is an implementation of Mask R-CNN on Python 3, Keras, and TensorFlow based on Matterport's version. The model generates bounding boxes and segmentation masks for each instance of an object in the image, with Feature Pyramid Network (FPN) + ResNet-101 as backbones.
AP@.50:.05:.95
and PASCAL VOC metric AP@.50
. For more information, read here.It is recommended to organize the dataset folder, testing image/video folder and model weight under same folder as the below structure:
├── notebooks # several notebooks from Matterport's Mask R-CNN
├── dataset # place the dataset here
│ └── <dataset_name>
│ ├── train
│ │ ├── <image_file 1> # accept .jpg or .jpeg file
│ │ ├── <image_file 2>
│ │ ├── ...
│ │ └── via_export_json.json # corresponded single annotation file, must be named like this
│ ├── val
│ └── test
├── logs # log folder
├── mrcnn # model folder
├── test # test folder
│ ├── image
│ └── video
├── trained_weight # pre-trained model and trained weight folder
| ...
├── environment.yml # environment setup file
├── README.md
├── dataset.py # dataset configuration
├── evaluation.py # weight evaluation
└── training.py # training model
conda env create -f environment.yml
conda activate mask-rcnn
Training:
* Train a new model starting from pre-trained weights
python3 training.py --dataset=/path/to/dataset --weight=/path/to/pretrained/weight.h5
* Resume training a model
python3 training.py --dataset=/path/to/dataset --continue_train=/path/to/latest/weights.h5
python3 evaluation.py --dataset=/path/to/dataset --weights=/path/to/pretrained/weight.h5
Testing
* Image
python3 image_detection.py --dataset=/path/to/dataset --weights=/path/to/pretrained/weight.h5 --image=/path/to/image/directory
* Video (update weight path and dataset path in mrcnn.visualize_cv2)
python3 video_detection.py --video_path = /path/to/testing/video/dir/
Annotation generating:
python3 annotating_generation.py --dataset=/path/to/dataset --weights=/path/to/pretrained/weight.h5 --image=/path/to/image/directory
View training plot:
tensorboard --logdir=logs/path/to/trained/dir
Annotated image for this implementation is created by VGG Image Annotator with format structure:
{ 'filename': '<image_name>.jpg',
'regions': {
'0': {
'region_attributes': {},
'shape_attributes': {
'all_points_x': [...],
'all_points_y': [...],
'name': <class_name>}},
... more regions ...
},
'size': <image_size>
}