Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable shape and weights shape are not matching #140

Open
christer1114 opened this issue Apr 12, 2021 · 5 comments
Open

Variable shape and weights shape are not matching #140

christer1114 opened this issue Apr 12, 2021 · 5 comments

Comments

@christer1114
Copy link

christer1114 commented Apr 12, 2021

Hi,

I am trying to run the codes for Age detection using jupyter notebook but I an getting errors when I try to load the weights.
When the code below is used,

base_model = ResNet50(include_top=False, weights='imagenet', input_shape=(224, 224, 3), pooling="avg")
prediction = Dense(units=101, kernel_initializer="he_normal", use_bias=False, activation="softmax",
name="pred_age")(base_model.output)
model = Model(inputs=base_model.input, outputs=prediction)

it yields,

ValueError: Cannot assign to variable conv3_block1_0_conv/kernel:0 due to variable shape (1, 1, 256, 512) and value shape (512, 128, 1, 1) are incompatible

Please help.

@gadididi
Copy link

Hi,

I am trying to run the codes for Age detection using jupyter notebook but I an getting errors when I try to load the weights.
When the code below is used,

base_model = ResNet50(include_top=False, weights='imagenet', input_shape=(224, 224, 3), pooling="avg")
prediction = Dense(units=101, kernel_initializer="he_normal", use_bias=False, activation="softmax",
name="pred_age")(base_model.output)
model = Model(inputs=base_model.input, outputs=prediction)

it yields,

ValueError: Cannot assign to variable conv3_block1_0_conv/kernel:0 due to variable shape (1, 1, 256, 512) and value shape (512, 128, 1, 1) are incompatible

Please help.

HI @christer1114
did you found solution for this problem?

@oballinger
Copy link

is it crucial you run it from jupyter/IDE? demo.py works fine from the command line

@sushidelivery
Copy link

same problem

@RTnhN
Copy link

RTnhN commented Jun 18, 2021

This is pretty old, but maybe it will help others.

I had this problem too. I found this stack overflow answer that helped me. You just need to add by_name=True in the model.load_weights(weight_file) method call. It should be model.load_weights(weight_file,by_name=True). It worked for me, so it might work for you too.

@sushidelivery
Copy link

This is pretty old, but maybe it will help others.

I had this problem too. I found this stack overflow answer that helped me. You just need to add by_name=True in the model.load_weights(weight_file) method call. It should be model.load_weights(weight_file,by_name=True). It worked for me, so it might work for you too.

thank you! I will try & check it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants