Skip to content

Refactored Mask R-CNN for object detection and instance segmentation on TensorFlow 2.

Notifications You must be signed in to change notification settings

maxw1489/Mask_RCNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mask-RCNN TensorFlow 2

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.

Getting started

  1. Clone the repo.

  2. 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
  3. 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.

  4. 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
  5. To train Mask-RCNN on a custom data copy the balloon folder and adjust everything you need to your dataset.

Known-Warnings

The warnings are annoying but doesn't harm anything:

  • ... Error in PredictCost() for the op: op: "CropAndResize" ...
  • ... UserWarning: Converting sparse IndexedSlices ...

Known-Issues

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!

Compatability-Issues

  • 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.

About

Refactored Mask R-CNN for object detection and instance segmentation on TensorFlow 2.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages