keras-yolo4
keras-yolo4 copied to clipboard
ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible
Traceback (most recent call last):
File "test.py", line 58, in <module>
yolo4_model.load_weights(model_path)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/network.py", line 1230, in load_weights
f, self.layers, reshape=reshape)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 1237, in load_weights_from_hdf5_group
K.batch_set_value(weight_value_tuples)
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 2960, in batch_set_value
tf_keras_backend.batch_set_value(tuples)
File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 3323, in batch_set_value
x.assign(np.asarray(value, dtype=dtype(x)))
File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 819, in assign
self._shape.assert_is_compatible_with(value_tensor.shape)
File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 1110, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible
Facing this issue in test.py
how did you solve?
that means that some model's layers have different shape then the weights you load. This is surely because you created the model with another number of classes (not 80), so the conv_110 layer has (1, 1, 1024, 75) weights' shape instead of (1, 1, 1024, 255) that the model with weights you load was.
So, you need to use yolo4_model.load_weights(model_path, by_name=True, skip_mismatch=True)
to load only coinciding layer's weights without errors. In particular, in this case all except the last 3 layers will get the weights from the checkpoint and the last 3 layers will be randomly initialized and must be trained for your task.
@Ivan-basis is right, use coco_classes.txt instead of voc_classes.txt
@Ivan-basis is there any way to fix it before we convert the weight?
I am using the converted model for another app and getting the same prob? could you help, please?