Esri / raster-deep-learning

ArcGIS built-in python raster functions for deep learning to get you started fast.
Apache License 2.0
186 stars 87 forks source link

ValueError: Layer #389 (named "mrcnn_bbox_fc") #19

Closed Karl-Keller closed 5 years ago

Karl-Keller commented 5 years ago

In Pro 2.3.3, attempting to run the trained MaskRCNN coco model, mask_rcnn_coco.h5, runs into this issue loading weights:

File "c:\Users\kkeller2\AppData\Local\Programs\ArcGIS\Pro\Resources\Raster\Functions\System\DeepLearning\ObjectDetector.py", line 48, in initialize self.child_object_detector.initialize(model, model_as_file) File "c:\Users\kkeller2\AppData\Local\Programs\ArcGIS\Pro\Resources\Raster\Functions\System\DeepLearning\Keras\MaskRCNN.py", line 46, in initialize self.model.load_weights(model_path, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"]) File "C:\Users\kkeller2\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\Lib\site-packages\mrcnn\model.py", line 2119, in load_weights saving.load_weights_from_hdf5_group_by_name(f, layers) File "C:\Users\kkeller2\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\Lib\site-packages\keras\engine\saving.py", line 1149, in load_weights_from_hdf5_group_by_name str(weight_values[i].shape) + '.') ValueError: Layer #389 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc/kernel:0' shape=(1024, 8) dtype=float32_ref> has shape (1024, 8), but the saved weight has shape (1024, 324).

I added the exclusion list in the MaskRCNN call to 'load_weights' on the basis of issues from the Matterport site here: https://github.com/matterport/Mask_RCNN/issues/849

Although, all those examples were in 'training' rather than 'inference' mode. And it made no difference because mrcnn_bbox_fc is still in the layers list after the filter call. (?)

Any insights on this would be much appreciated.

Karl-Keller commented 5 years ago

This error was resolved by expanding the definition of my config class like this to include NUM_CLASSES explicitly. Thanks to @Alexlastname on the Matterport site who suggested a relationship to the number of classes.

class InferenceConfig(ParkingNetConfig): NAME = "parking_pretrained_model_config" IMAGES_PER_GPU = 1 GPU_COUNT = 1 NUM_CLASSES = 1 + 80 DETECTION_MIN_CONFIDENCE = 0.6