I am trying to train Mask RCNN on a custom dataset of floorplans. I am following this article on Medium to do this: https://medium.com/analytics-vidhya/a-simple-guide-to-maskrcnn-custom-dataset-implementation-27f7eab381f2 .
After having some issues with annotation formats and packages I got around to training the model. However, I stumbled upon the following error code:
Traceback (most recent call last): File "custom.py", line 391, in <module> train(model) File "custom.py", line 222, in train layers='heads') File "C:...Custom_MaskRCNN-mastermrcnnmodel.py", line 2356, in train self.compile(learning_rate, self.config.LEARNING_MOMENTUM) File "C:...Custom_MaskRCNN-mastermrcnnmodel.py", line 2201, in compile self.keras_model.add_metric(loss, name) AttributeError: 'Model' object has no attribute 'add_metric'
I could not find anything about this error and was hoping someone could help out or give me an indication on how to fix this.
Advertisement
Answer
As we can see, the requirements file does not specify an exact TF & Keras version but, only a lower limit.
#requirements.txt numpy scipy Pillow cython matplotlib scikit-image tensorflow>=1.3.0 keras>=2.0.8 opencv-python h5py imgaug IPython[all]
When your env was created, the most recent versions of TensorFlow & Keras would have got installed. The ‘add_metric’ method might be deprecated or moved to another class in the the latest version that got installed, as there have been major version updates to these frameworks. Please note that the author of the repo associated with this article has not been updated it in the last two years. Even the author of the original repo which this repo is based on, has not yet updated it (Original repo: https://github.com/matterport/Mask_RCNN). It is very likely that you’re going to face more errors once the current one is solved.
One way to solve this issue would be to downgrade TF and Keras versions (tensorflow to 1.3.0, keras to 2.0.8 may resolve it).
The best course of action would be to port the code using the official conversion tools provided by TensorFlow to convert the TF1.x code to TF2.x or to use a repo in which the code has already been converted.
MaskRCNN Repo with Updated TF and Keras: https://github.com/ahmedfgad/Mask-RCNN-TF2
Hope that helps! Cheers :)