Can't load_model with error “Optimizer weight shape (256, 32) not compatible with provided weight shape (4,)”
See original GitHub issueI have 3 trained model file.
- left_branch.h5
- right_branch.h5
- concat.h5
The model concat.h5
is fine-tuned by concatenating from the two pre-trained model as the initial model(left_branch.h5
, right_branch.h5
).
While left_branch.h5
and right_branch.h5
model file can be load by function keras.models.load_model(),
but I load the trained concat.h5
formatted model file, I get the error blew.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 167, in load_model
model.optimizer.set_weights(optimizer_weight_values)
File "/usr/local/lib/python2.7/dist-packages/keras/optimizers.py", line 97, in set_weights
'provided weight shape ' + str(w.shape))
Exception: Optimizer weight shape (256, 32) not compatible with provided weight shape (4,)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:28 (9 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am using Keras 1.1.1 and am having the same problem. Deleting the optimizer weights as a workaround works for me.
Just in case someone needs to do the same, here’s the code:
I had the same problem and what it seemed to work for me was to set the
compile
flag toFalse
in theload_model
function. Afterwards one can compile the model with the previously used optimizer.