The repository provides a refactored version of the original Mask-RCNN without the need for any references to the TensorFlow v1 or the standalone Keras packages anymore! Thus, the Mask-RCNN can now be executed on any recent TensorFlow version (tested onto TF 2.9.1 env.) and the eager execution can be tuned on/off for debugging anytime. Additionally, the DataGenerator is refactored providing the same results using use_multiprocessing=False/True.
The project was created to improve the old well known network while having fun breaking it, learning many crazy aspectes of TensorFlow and Python, and simply enjoying coding. I want also to thank akTwelve for providing a great starting point I could build on. For full explanation on Mask-RCNN refer to the original repo and to the original medium article.
-
Clone the repo.
-
Download the test images and the COCO weights from the original Mask-RCNN repo:
cd Mask_RCNN git clone https://github.com/matterport/Mask_RCNN.git original_repo mv original_repo/images . rm -rf original_repo wget -P weights https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5
-
Create and run a docker environment (or create a local one based on the dependencies in the DockerFile).
Create a docker image:
cd Mask_RCNN docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) -f DockerFile -t mrcnn:tf2 .
Run a docker container:
cd Mask_RCNN docker run --name mrcnn --gpus all --rm -it -v $(pwd):/home/ai/dev -ip 8321:8321 -w /home/ai/dev mrcnn:tf2 jupyter notebook --no-browser --ip 0.0.0.0 --port=8321
Execute the model trained on COCO in jupyter notebook:
samples/demo.ipynb. -
To get started with a real example take a look at the samples/balloon notebooks in the project. Before running them download the dataset:
cd Mask_RCNN wget -P data https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip unzip data/balloon_dataset.zip -d data -
To train Mask-RCNN on a custom data copy the balloon folder and adjust everything you need to your dataset.
The warnings are annoying but doesn't harm anything:
- ... Error in PredictCost() for the op: op: "CropAndResize" ...
- ... UserWarning: Converting sparse IndexedSlices ...
The model doesn't train well using the configuration USE_MINI_MASK=True. This is probably due to tf.round(ouput_resized_mask) operation in the training graph. However, there are no problems using USE_MINI_MASK=False!
- model.py/MaskRCNN/ancestor looks to be obsolete because the KerasTensor doesn't support the op member calling since TF 2.4 anymore. Consequently, all ancestor callings are disabled and remarked in the coresponding notebooks.
Built on this repository
- First make an environment with tensorflow, can follow the given link
- Then install required dependencies.
- Then clone the repo.
scripts/folder has the scripts required to train/test the model, data and weights.samples/folder has the sample notebooks from the original repository.data/andweights/folders are required to train/tune the model.logs/is needed for checking the model training and testing results.- For any inquiries open an issue.
Thank you for your time!