matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.68k stars 11.7k forks source link

ValueError in Mask R-CNN Demo #2824

Closed knagasaka closed 2 years ago

knagasaka commented 2 years ago

When I was trying Mask R-CNN Demo, I got valueerror after running kernel below.


model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config) model.load_weights(COCO_MODEL_PATH, by_name=True)

Error I got is below.


ValueError Traceback (most recent call last) Input In [3], in <cell line: 2>() 1 # Create model object in inference mode. ----> 2 model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config) 4 # Load weights trained on MS-COCO 5 model.load_weights(COCO_MODEL_PATH, by_name=True)

File ~/Mask_RCNN/mrcnn/model.py:1838, in MaskRCNN.init(self, mode, config, model_dir) 1836 self.model_dir = model_dir 1837 self.set_log_dir() -> 1838 self.keras_model = self.build(mode=mode, config=config)

File ~/Mask_RCNN/mrcnn/model.py:2044, in MaskRCNN.build(self, mode, config) 2035 mrcnn_class_logits, mrcnn_class, mrcnn_bbox =\ 2036 fpn_classifier_graph(rpn_rois, mrcnn_feature_maps, input_image_meta, 2037 config.POOL_SIZE, config.NUM_CLASSES, 2038 train_bn=config.TRAIN_BN, 2039 fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE) 2041 # Detections 2042 # output is [batch, num_detections, (y1, x1, y2, x2, class_id, score)] in 2043 # normalized coordinates -> 2044 detections = DetectionLayer(config, name="mrcnn_detection")( 2045 [rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta]) 2047 # Create masks for detections 2048 detection_boxes = KL.Lambda(lambda x: x[..., :4])(detections)

File ~/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:951, in Layer.call(self, *args, **kwargs) 945 # Functional Model construction mode is invoked when Layers are called on 946 # symbolic KerasTensors, i.e.: 947 # >> inputs = tf.keras.Input(10) 948 # >> outputs = MyLayer()(inputs) # Functional construction mode. 949 # >> model = tf.keras.Model(inputs, outputs) 950 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list): --> 951 return self._functional_construction_call(inputs, args, kwargs, 952 input_list) 954 # Maintains info about the Layer.call stack. 955 call_context = base_layer_utils.call_context()

File ~/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:1090, in Layer._functional_construction_call(self, inputs, args, kwargs, input_list) 1086 if keras_tensor.keras_tensors_enabled(): 1087 with call_context.enter( 1088 layer=self, inputs=inputs, build_graph=True, training=training_value): 1089 # Check input assumptions set after layer building, e.g. input shape. -> 1090 outputs = self._keras_tensor_symbolic_call( 1091 inputs, input_masks, args, kwargs) 1093 if outputs is None: 1094 raise ValueError('A layer\'s call method should return a ' 1095 'Tensor or a list of Tensors, not None ' 1096 '(layer: ' + self.name + ').')

File ~/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:822, in Layer._keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs) 820 return nest.map_structure(keras_tensor.KerasTensor, output_signature) 821 else: --> 822 return self._infer_output_signature(inputs, args, kwargs, input_masks)

File ~/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py:863, in Layer._infer_output_signature(self, inputs, args, kwargs, input_masks) 857 with autocast_variable.enable_auto_cast_variables( 858 self._compute_dtype_object): 859 # Build layer if applicable (if the build method has been 860 # overridden). 861 # TODO(kaftan): do we maybe_build here, or have we already done it? 862 self._maybe_build(inputs) --> 863 outputs = call_fn(inputs, *args, **kwargs) 865 self._handle_activity_regularization(inputs, outputs) 866 self._set_mask_metadata(inputs, outputs, input_masks, 867 build_graph=False)

File ~/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py:670, in convert..decorator..wrapper(*args, **kwargs) 668 except Exception as e: # pylint:disable=broad-except 669 if hasattr(e, 'ag_error_metadata'): --> 670 raise e.ag_error_metadata.to_exception(e) 671 else: 672 raise

ValueError: in user code:

/home/nagasaka/Mask_RCNN/mrcnn/model.py:810 call  *
    detections_batch = utils.batch_slice(
/home/nagasaka/Mask_RCNN/mrcnn/utils.py:821 batch_slice  *
    output_slice = graph_fn(*inputs_slice)
/tmp/tmpi9t6nidi.py:17 <lambda>  **
    detections_batch = ag__.converted_call(ag__.ld(utils).batch_slice, ([ag__.ld(rois), ag__.ld(mrcnn_class), ag__.ld(mrcnn_bbox), ag__.ld(window)], ag__.autograph_artifact((lambda x, y, w, z: ag__.converted_call(ag__.ld(refine_detections_graph), (ag__.ld(x), ag__.ld(y), ag__.ld(w), ag__.ld(z), ag__.ld(self).config), None, fscope))), ag__.ld(self).config.IMAGES_PER_GPU), None, fscope)
/home/nagasaka/Mask_RCNN/mrcnn/model.py:702 refine_detections_graph  **
    indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/util/dispatch.py:201 wrapper
    return target(*args, **kwargs)
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/ops/math_ops.py:1856 range
    limit = ops.convert_to_tensor(limit, dtype=dtype, name="limit")
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/profiler/trace.py:163 wrapped
    return func(*args, **kwargs)
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/framework/ops.py:1540 convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py:339 _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py:264 constant
    return _constant_impl(value, dtype, shape, name, verify_shape=False,
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py:281 _constant_impl
    tensor_util.make_tensor_proto(
/home/nagasaka/.conda/envs/mask-rcnn/lib/python3.9/site-packages/tensorflow/python/framework/tensor_util.py:445 make_tensor_proto
    raise ValueError("None values not supported.")

ValueError: None values not supported.

Since I am new to mask r-cnn, could you please help me to solve the problem?

knagasaka commented 2 years ago

The error solved. Thank you.

patrykGawron commented 2 years ago

The error solved. Thank you.

Hey! I have a similar problem, how did you solve it?

patrykGawron commented 2 years ago

@knagasaka

knagasaka commented 2 years ago

@patrykGawron Hi, I do not remember very well, but I downgraded python to 3.6.13 and tensorflow to 1.5.0. I hope this helps you.