Superlee506 / Mask_RCNN_Humanpose

Mask R-CNN for Human Pose Estimation on Keras and TensorFlow.
Other
189 stars 36 forks source link

dimension mismatch #19

Closed liershui closed 5 years ago

liershui commented 6 years ago

Hi

Thanks for your effort,

I tested demo_human_pose.ipynb with your mask_rcnn_coco_humanpose.h5 file, it gives me the following error.

ValueError: Dimension 1 in both shapes must be equal, but are 324 and 8. Shapes are [1024,324] and [1024,8]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,324], [1024,8].

i tried to add exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"], it gives meaningless results. any solutions please?

Ahmer-444 commented 6 years ago

Hi! I am getting the same issue in demo_human_pose.ipynb, seems like a mismatch between the input tensors. I am also looking for the solution. Can anyone please help?

ValueError: Dimension 1 in both shapes must be equal, but are 8 and 324. Shapes are [1024,8] and [1024,324]. for 'Assign_1365' (op: 'Assign') with input shapes: [1024,8], [1024,324].

Superlee506 commented 6 years ago

@liershui @Ahmer-444 Can you give detailed information about this error? I can run this demo correctly.

Superlee506 commented 6 years ago

@liershui @Ahmer-444 Please Tell me the following information.

  1. What you did:
    • If you're using examples:
      • What's the command you run:
      • Have you made any changes to code? Paste them if any:
    • If not, tell us what you did that may be relevant. But we may not be able to resolve it if there is no reproducible code.
    • Better to paste what you did instead of describing them.
  2. What you observed, e.g. the entire log:
    • Better to paste what you observed instead of describing them.
  3. What you expected, if not obvious.
  4. Your environment
liershui commented 6 years ago

here is what i did, sorry for my annoying expression. i ran demo_human_pose.ipynb with jupyter, python3.5.2, keras2.1.5, tensorflow1.3.0, i have run Mask_RCNN (https://github.com/matterport/Mask_RCNN) in my environment so i think my environment is ok.

when i ran the 2nd cell in demo_human_pose.ipynb, i got this error:

2 Loading weights from /home/data/usrs/lib/code/Mask_RCNN_Humanpose/mask_rcnn_coco_humanpose.h5

InvalidArgumentError Traceback (most recent call last) /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 653 graph_def_version, node_def_str, input_shapes, input_tensors, --> 654 input_tensors_as_shapes, status) 655 except errors.InvalidArgumentError as err:

/usr/lib/python3.5/contextlib.py in exit(self, type, value, traceback) 65 try: ---> 66 next(self.gen) 67 except StopIteration:

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status() 465 compat.as_text(pywrap_tensorflow.TF_Message(status)), --> 466 pywrap_tensorflow.TF_GetCode(status)) 467 finally:

InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 8 and 324 for 'Assign_682' (op: 'Assign') with input shapes: [1024,8], [1024,324].

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in () 17 assert model_path != "", "Provide path to trained weights" 18 print("Loading weights from ", model_path) ---> 19 model.load_weights(model_path, by_name=True) ~/code/Mask_RCNN_Humanpose/model.py in load_weights(self, filepath, by_name, exclude) 2840 2841 if by_name: -> 2842 topology.load_weights_from_hdf5_group_by_name(f, layers) 2843 else: 2844 topology.load_weights_from_hdf5_group(f, layers) ~/pythonlib/lib/python3.5/site-packages/keras/engine/topology.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch, reshape) 3466 weight_values[i])) 3467 -> 3468 K.batch_set_value(weight_value_tuples) ~/pythonlib/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in batch_set_value(tuples) 2366 assign_placeholder = tf.placeholder(tf_dtype, 2367 shape=value.shape) -> 2368 assign_op = x.assign(assign_placeholder) 2369 x._assign_placeholder = assign_placeholder 2370 x._assign_op = assign_op /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variables.py in assign(self, value, use_locking) 525 the assignment has completed. 526 """ --> 527 return state_ops.assign(self._variable, value, use_locking=use_locking) 528 529 def assign_add(self, delta, use_locking=False): /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/state_ops.py in assign(ref, value, validate_shape, use_locking, name) 272 return gen_state_ops.assign( 273 ref, value, use_locking=use_locking, name=name, --> 274 validate_shape=validate_shape) 275 return ref.assign(value) /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_state_ops.py in assign(ref, value, validate_shape, use_locking, name) 41 result = _op_def_lib.apply_op("Assign", ref=ref, value=value, 42 validate_shape=validate_shape, ---> 43 use_locking=use_locking, name=name) 44 return result 45 /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords) 765 op = g.create_op(op_type_name, inputs, output_types, name=scope, 766 input_types=input_types, attrs=attr_protos, --> 767 op_def=op_def) 768 if output_structure: 769 outputs = op.outputs /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device) 2630 original_op=self._default_original_op, op_def=op_def) 2631 if compute_shapes: -> 2632 set_shapes_for_outputs(ret) 2633 self._add_op(ret) 2634 self._record_op_seen_by_control_dependencies(ret) /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in set_shapes_for_outputs(op) 1909 shape_func = _call_cpp_shape_fn_and_require_op 1910 -> 1911 shapes = shape_func(op) 1912 if shapes is None: 1913 raise RuntimeError( /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in call_with_requiring(op) 1859 1860 def call_with_requiring(op): -> 1861 return call_cpp_shape_fn(op, require_shape_fn=True) 1862 1863 _call_cpp_shape_fn_and_require_op = call_with_requiring /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in call_cpp_shape_fn(op, require_shape_fn) 593 res = _call_cpp_shape_fn_impl(op, input_tensors_needed, 594 input_tensors_as_shapes_needed, --> 595 require_shape_fn) 596 if not isinstance(res, dict): 597 # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op). /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 657 missing_shape_fn = True 658 else: --> 659 raise ValueError(err.message) 660 661 if missing_shape_fn: ValueError: Dimension 1 in both shapes must be equal, but are 8 and 324 for 'Assign_682' (op: 'Assign') with input shapes: [1024,8], [1024,324]. thank you very much.
liershui commented 6 years ago

also when i was trying to continue my training with an h5 file in /mylogs, i got the same error.

kei-bility commented 6 years ago

I also got error below. How can I fix it?

Loading weights from  /notebooks/Mask_RCNN_Humanpose/mask_rcnn_coco_humanpose.h5
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-38cd5c09f443> in <module>()
     11 assert model_path != "", "Provide path to trained weights"
     12 print("Loading weights from ", model_path)
---> 13 model.load_weights(model_path, by_name=True)
     14 #model.load_weights(model_path, by_name=True,exclude=["mrcnn_bbox_fc"])
     15 #model.load_weights(model_path, by_name=True,exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"])

/notebooks/Mask_RCNN_Humanpose/model.py in load_weights(self, filepath, by_name, exclude)
   2850 
   2851         if by_name:
-> 2852             saving.load_weights_from_hdf5_group_by_name(f, layers)
   2853         else:
   2854             saving.load_weights_from_hdf5_group(f, layers)

/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch, reshape)
   1016                                          ' has shape {}'.format(K.int_shape(symbolic_weights[i])) +
   1017                                          ', but the saved weight has shape ' +
-> 1018                                          str(weight_values[i].shape) + '.')
   1019                 else:
   1020                     weight_value_tuples.append((symbolic_weights[i],

ValueError: Layer #389 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc_6/kernel:0' shape=(1024, 8) dtype=float32_ref> has shape (1024, 8), but the saved weight has shape (1024, 324).
Yuansonghe6 commented 6 years ago

Hello, I have this question, so can you tell me how do you deal with this problem? Thank you. ValueError Traceback (most recent call last)

in () 4 # model.load_weights(COCO_MODEL_PATH, by_name=True) 5 # Load weights trained on MS-COCO ----> 6 model.load_weights(COCO_MODEL_PATH, by_name=True) 7 8 #model_path = model.find_last()[1] ~/source/Mask_RCNN/mrcnn/model.py in load_weights(self, filepath, by_name, exclude) 2136 2137 if by_name: -> 2138 saving.load_weights_from_hdf5_group_by_name(f, layers) 2139 else: 2140 saving.load_weights_from_hdf5_group(f, layers) ~/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch, reshape) 1015 ' has shape {}'.format(K.int_shape(symbolic_weights[i])) + 1016 ', but the saved weight has shape ' + -> 1017 str(weight_values[i].shape) + '.') 1018 else: 1019 weight_value_tuples.append((symbolic_weights[i], ValueError: Layer #389 (named "mrcnn_bbox_fc"), weight has shape (1024, 16), but the saved weight has shape (1024, 324).
russoale commented 5 years ago

You need to download the pre-trained weights from this repository: https://github.com/Superlee506/Mask_RCNN_Humanpose/releases/download/v0.9-alpha/mask_rcnn_coco_humanpose.h5

within the demo_human_pose.ipynb you reference to mask_rcnn_coco_humanpose.h5 file but actually then downloading matterports pre-trained weights via utils.download_trained_weights() function!

myagmur01 commented 5 years ago

-- ValueError: Layer matterport#389 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc_6/kernel:0' shape=(1024, 16) dtype=float32_ref> has shape (1024, 16), but the saved weight has shape (1024, 324). which means your number of classes are making (1+3) x 4 = 16 vectors at top, but probably your are calling coco model weights which has a shape of (1+80) x 4 = 324 vector in size and you are getting this error. Please be sure whether your script is calling coco model weights or your own trained model weigths.