Human-Action-Recognition-with-Keras icon indicating copy to clipboard operation
Human-Action-Recognition-with-Keras copied to clipboard

ValueError: Layer weight shape (3, 3, 224, 64) not compatible with provided weight shape (64, 3, 3, 3)

Open hqzxbb opened this issue 7 years ago • 10 comments

Using Theano backend. (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) (Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0) Traceback (most recent call last): File "HumanActionRecognition.py", line 110, in model.layers[k].set_weights(weights) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/keras/engine/topology.py", line 985, in set_weights 'provided weight shape ' + str(w.shape)) ValueError: Layer weight shape (3, 3, 224, 64) not compatible with provided weight shape (64, 3, 3, 3)

hqzxbb avatar Mar 10 '17 06:03 hqzxbb

I have the same problem!!! ValueError: Layer weight shape (3, 3, 224, 64) not compatible with provided weight shape (64, 3, 3, 3)

Have you solved the problem? I had set Theano backend.

shonehang avatar Apr 18 '17 08:04 shonehang

Check whether "image_dim_ordering" in "~/.keras/keras.json" is "th". I had the same problem when this value was "tf".

J-Holliday avatar May 18 '17 03:05 J-Holliday

Have you solved the problem? I am also facing same problem.. ValueError: Layer weight shape (3, 3, 223, 64) not compatible with provided weight shape (64, 3, 3, 3)

pradeepbatchu avatar Jan 13 '18 08:01 pradeepbatchu

I have the same problem, trying to load 2 saved trained models I get: ValueError: Optimizer weight shape (32, 32, 128) not compatible with provided weight shape (128, 128, 32) Any solution?

amessica avatar Feb 17 '18 12:02 amessica

I have the same problem, have you solved it?

ecemseymen avatar Mar 01 '19 08:03 ecemseymen

@ecemseymen, yes I did. Tensorflow's default is a single model when loading. If you want to load several models you have to rename them. For example:

model0 = load_model('D:\Python\models/model0.hdf5') # load compiled model model0.name = 'model0' # Rename model to avoid "model_0" conflict 3 times . names should be unique for layer in model0.layers: # this line is necessary if you don't want to re-train the model layer.trainable=False model1 = load_model('D:\Python\models/model1.hdf5')
model1.name = 'model1' for layer in model1.layers: # freeze model weigths layer.trainable=False model3 = load_model('D:\Python\models/model3.hdf5')
model3.name = 'model3' for layer in model3.layers: layer.trainable=False

then the rest of your code........ I hope it helps.

amessica avatar Mar 01 '19 13:03 amessica

i have same error. I am using keras 2.2.4. Have you solved the problem?

ghost avatar Jun 19 '19 07:06 ghost

[Solved] I changed some think like:

for k in range(f.attrs['nb_layers']):
    if k >= len(model.layers):
        # we don't look at the last (fully-connected) layers in the savefile
        break
    g = f['layer_{}'.format(k)]
    weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
    layer = model.layers[k]
    #model.layers[k].set_weights(weights)
    if layer.__class__.__name__ in ['Conv1D', 'Conv2D', 'Conv3D', 'AtrousConvolution2D']:
        weights[0] = np.transpose(weights[0], (2, 3, 1, 0))
    layer.set_weights(weights)
f.close()

ghost avatar Jun 19 '19 09:06 ghost

Hi, I noticed that in row 36 the pre-trained model whole_model.h5 is used. I can't find it in your depository. Anyone ones where to find it? Thanks.

txing001 avatar Sep 21 '20 10:09 txing001

I have the same problem, have you solved it?

Make sure you have set image_data_format to channels_first

vijethasachin avatar Sep 05 '21 02:09 vijethasachin