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
I try to load my weights as follow :
But this give me the following error :
Layer #1 (named "conv2d_1"), weight <tf.Variable 'conv2d_1/kernel:0' shape=(3, 3, 32, 64) dtype=float32> 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 ?