I have tried to implement the basic Mask_RCNN model on my custom dataset. I have done a few augmentations on images. Followed the basic pattern for mask rcnn. I trained the system first and then tried testing. The results for mAp are always 0.0 and predictions are showing like this.enter image description here I am trying to identify the score for cars but this is the end result. If anybody has any suggestions, help me.

- 1
- 2
-
Show us the code. – Adarsh Wase Nov 17 '21 at 08:33
-
@AdarshWase I have used basic training inference code for mask rcnn on my dataset. – Aakriti Sharma Nov 17 '21 at 21:22
-
inference_config = InferenceConfig() model = modellib.MaskRCNN(mode="inference", model_dir = DEFAULT_LOGS_DIR, config=inference_config) # Load trained weights print("Loading weights from ", model_path) model.load_weights(model_path, by_name=True) image_id = random.choice(dataset_train.image_ids) original_image, image_meta, gt_class_id, gt_bbox, gt_mask =\ modellib.load_image_gt(dataset_train, inference_config, image_id, use_mini_mask=False) – Aakriti Sharma Nov 18 '21 at 01:11
-
log("original_image", original_image) log("image_meta", image_meta) log("gt_class_id", gt_class_id) log("gt_bbox", gt_bbox) log("gt_mask", gt_mask) visualize.display_instances(original_image, gt_bbox, gt_mask, gt_class_id, dataset_train.class_names, figsize=(8, 8)) results = model.detect([original_image], verbose=1) r = results[0] visualize.display_instances(original_image, r['rois'], r['masks'], r['class_ids'], dataset_train.class_names, r['scores'], ax=get_ax()) – Aakriti Sharma Nov 18 '21 at 01:13
-
Please provide enough code so others can better understand or reproduce the problem. – Community Nov 22 '21 at 22:42
2 Answers
Although I am not sure exactly what your issue is without more information I posit that it is similar to an issue I have encountered when using the matterport repo on tf-gpu 2.7. Along with a a bunch of other updates you need to make to configure this repo to work on tf2 you must also amend the loading of the weights.
In the demo.ipynb notebook you will see code for the loading the weights as follows:
# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
# Load weights trained on MS-COCO
# model.load_weights(COCO_MODEL_PATH, by_name=True)
To enable the fix replace the above code with the following:
from keras.backend import manual_variable_initialization
manual_variable_initialization(True)
# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
# Load weights trained on MS-COCO
# model.load_weights(COCO_MODEL_PATH, by_name=True)
import tensorflow.compat.v1 as tf
tf.keras.Model.load_weights(model.keras_model, COCO_MODEL_PATH, by_name=True)
This should enable the demo to work correctly. The root issue is due to inaccurate initialization of weights within Keras, which is handled by enabling manual initialization. By just doing that the weights will not load correctly with the current load_weights function wihtin mrcnn.model.py Therefore, we can bypass it by implementing a pure Keras loading of the weights via the above code.
I hope this helps someone! It took me days to figure this out!

- 61
- 1
-
No criticism intended for your answer, which looks well thought out, but please do avoid answering low-quality questions like this one. [A good question](https://stackoverflow.com/help/how-to-ask) should, at a minimum, include a [mre] and a clearly articulated error condition. – miken32 Nov 29 '21 at 19:51
When you loading the weight, instead of using model.load_weight(...)
, Use this:
model.keras_model.load_weight(...) .
This will surely work as I was also facing this same problem. The main reason was matterporn mrcnn load_weight
does not load weight correctly.

- 1,966
- 3
- 10
- 22

- 1
- 3