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

Fast pixelwise analysis throws ValueError for optimizer weight shape #9

Closed
EricHanLiu opened this issue May 8, 2018 · 5 comments
Closed

Comments

@EricHanLiu
Copy link
Contributor

EricHanLiu commented May 8, 2018

When running in Rodan with the provided model templates, we get

File "/code/rodan/rodan/jobs/Calvo-classifier/recognition_engine.py", line 47, in process_image_msae
    sae_models.append( load_model(model_paths[id_label]) )
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 291, in load_model
     model.optimizer.set_weights(optimizer_weight_values)
File "/usr/local/lib/python2.7/dist-packages/keras/optimizers.py", line 103, in set_weights
    'provided weight shape ' + str(w.shape))
ValueError: Optimizer weight shape (128,) not compatible with provided weight shape (5, 5, 3, 128)`

I've seen a solution that says to install HDFview and open the hdf5 file and delete the optimizer part of the file, which causes the model to load properly. Is this a safe thing to do within the context of this classifier? Will it break any code?

Others have discussed that this is a bug within Keras.

@calvozaragoza any advice?

@calvozaragoza
Copy link
Contributor

It should be safe within the context of classification (the optimizer is only used for training).

However, it seems a version inconsistency problem to me; the fast models were trained before migrating Rodan to docker. Check whether 'theano' is selected as backend in Keras, and also try the different options for the 'image_data_format' setting: https://keras.io/backend/

@EricHanLiu
Copy link
Contributor Author

Will do, thank you Jorge

@EricHanLiu
Copy link
Contributor Author

So we confirmed that Theano is the backend for Keras (the config file was the exact same as the instructions in this repository), and there was no image_data_format key so we added it ourselves in the dictionary. Doing so broke docker when we tried to reinstantiate everything, we got the error
Message: No module named tensorflow
and we had to rebuild the image since it crashed every time.
I guess this solution doesn't really work, so we'll try just removing the optimizer part of the models.

@EricHanLiu
Copy link
Contributor Author

Using this script to remove the optimizer weights for each file, testing now

import h5py
f = h5py.File('model_file.h5', 'r+')
del f['optimizer_weights']
f.close()

@EricHanLiu
Copy link
Contributor Author

Works with removing the optimizer weights! closing.

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

No branches or pull requests

3 participants