使用Mask-RCNN测试细胞数据集的时候,出现了以下错误:
Loading weights ../../path/to/weights.h5
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 654, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/contextlib.py", line 88, in __exit__
next(self.gen)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 8 and 324 for 'Assign_376' (op: 'Assign') with input shapes: [1024,8], [1024,324].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/Pycharm_Projection/Mask_RCNN-master/samples/nucleus/nucleus.py", line 484, in
model.load_weights(weights_path, by_name=True)
File "/home/ubuntu/Pycharm_Projection/Mask_RCNN-master/mrcnn/model.py", line 2130, in load_weights
saving.load_weights_from_hdf5_group_by_name(f, layers)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/keras/engine/topology.py", line 3158, in load_weights_from_hdf5_group_by_name
K.batch_set_value(weight_value_tuples)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2188, in batch_set_value
assign_op = x.assign(assign_placeholder)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 527, in assign
return state_ops.assign(self._variable, value, use_locking=use_locking)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 274, in assign
validate_shape=validate_shape)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 43, in assign
use_locking=use_locking, name=name)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1861, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "/home/ubuntu/anaconda3/envs/tensorflow1.3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Dimension 1 in both shapes must be equal, but are 8 and 324 for 'Assign_376' (op: 'Assign') with input shapes: [1024,8], [1024,324].
Process finished with exit code 1
由于使用的h5权重文件是官方的文件,官方的h5总共是80类,因此需要将
NUM_CLASSES = 1 + 1
改为:
NUM_CLASSES = 1 + 80,
最后正常运行!
参考链接:https://blog.csdn.net/qq_15969343/article/details/80559154