question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible

See original GitHub issue
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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
Ivan-basiscommented, Sep 23, 2020

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.

2reactions
mayurmahurkarcommented, Sep 10, 2020

Facing this issue in test.py

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Shapes (None, 1) and (None, 50) are incompatible
I was training a CNN model (transfer learning). While compiling, I got the following error. ValueError: Shapes (None, 1) and (None, 50) are...
Read more >
ValueError: Shapes (None, 1) and (None, 3) are incompatible
The first problem is with the LSTM input_shape. input_shape = (20,85,1) . From the doc: https://keras.io/layers/recurrent/.
Read more >
Tensorflow - I don't get the right shapes - `ValueError
The error occurs because of the x_test shape. In your code, you set it actually to x_train. [x_test = x_train / 255.0] Furthermore,...
Read more >
ValueError: Shapes (1, 1, 512, 12) and (75, 512 ... - CSDN博客
ValueError : Shapes (1, 1, 512, 12) and (75, 512, 1, 1) are incompatible ... 出现上述错误可能是1、train.py(训练的py文件)里面的num_classes没改。 2 ...
Read more >
Could you help me solve this error - TensorFlow Forum
ValueError : Shapes (None, 1) and (None, 10) are incompatible I use anaconda / spyder to test the tensorflow learning categorise the image ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found