Keras load pre-trained weights. Shape mismatch I have some trouble loading pre-trained weights with Keras.
Let's say I have a keras model model and that my weights are stored at my_weights.h5.

I try to load my weights as follow : 

model.load_weights("my_weights.h5", by_name=True)


But this give me the following error : 

Layer #1 (named "conv2d_1"), weight &lt;tf.Variable 'conv2d_1/kernel:0' shape=(3, 3, 32, 64) dtype=float32&gt; has shape (3, 3, 32, 64), but the saved weight has shape (32, 3, 3, 3).


So I tried to see what was the shape of my weights and my model structure : 

for layer in model_body.layers :
    print(layer.name+" : input ("+str(layer.input_shape)+") output ("+str(layer.output_shape)+")")

print("__")
with h5py.File(weights_filepath, 'r') as f:
    for k in f.keys():
        for l in f[k].keys():
            for m in f[k][l].keys():
                print(k+ " : " + m + " : " + str(f[k][l][m].shape))


conv2d_1 : input ((None, None, None, 32)) output ((None, None, None, 64))
__
conv2d_1 : kernel:0 : (3, 3, 3, 32)


(I kept only the layer that appear in the error)

By seeing this, I don't understand why the shapes mismatch, and where the shape (3, 3, 32, 64) in the error come from). Am I missing something ?
I have solved the kind of issue as follows. Hope the solution would be helpful.
1. Delete &quot;by_name=True&quot;
# -model.load_weights(weights_path, by_name=True)
model.load_weights(weights_path)

2. Change the number of class
While it throws another throwing &quot;ValueError: Shapes (1536, 1000) and (1536, 1001) are incompatible&quot;, I change num_classes from 1000 to 1001. And then it shows the correct model summary.
# -num_classes = 1000
num_classes = 1001