-
Notifications
You must be signed in to change notification settings - Fork 45
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
problem with "keras_model" #19
Comments
That looks really odd. According to a quick search this might be related to a broken installation of the keras package (see e.g. https://stackoverflow.com/questions/30861493/how-to-fix-python-valueerrorbad-marshal-data). Please verify if your installation is correct. If that's the case please let me know what version of keras you are using. |
After creating new virtual environment and installing keras (version: 2.2.4) and tensorflow (version:1.14.0) for python (version: 2.7) I get the same error! Thanks a lot for providing the link. Another issue that I see is the "keras.py" file in "bagnets" folder which probably needs to be renamed. |
I investigated this in a bit more depth. With the latest tensorflow and keras in Python 3 everything works fine, but I can replicate the marshal error in Python 2.7. The issue seems to be related in the serialization of the internal model objects included in the h5 file, as marshal (which is a serialisation package) features different internal representations in the two Python versions (see keras-team/keras#7440 for an in-depth discussion). The right and only solution to this problem is to actually construct the model in the standard keras-way and to then load the weights into that model. In principle that shouldn't be too hard but it requires a bit of debugging. Alternatively, you can simply switch to Python 3. |
Thanks a lot for the help. |
@AmirhosseinKardoost Sounds great! Would you mind contributing your code to this repo or to share it with me once you are done? That would be great! |
Sure, I would be happy to contribute. I would write about it as soon as I'm done. |
@wielandbrendel I need the features extracted from patches using your approach in my project. I could do this using PyTorch. If the performance of my method increase using these features I have to bring the model to Keras and load the corresponding weights. Therefore, It could probably take some time until I work on it (if the features improve the performance of my project). |
@Amirhk-dev Thanks for letting me know! I might do it myself at some point but I am pretty busy at the moment. You can just let me know here once you actually start working on it. Thanks again! |
@wielandbrendel Sure, I will inform you whenever I start working on it. Thanks for this cool project. |
Thanks for providing the code!
I don't have any issue loading the models in pytorch (the code below),
import bagnets.pytorch
pytorch_model = bagnets.pytorch.bagnet17(pretrained=True)
But in keras the code below throws an error!
import bagnets.keras
keras_model = bagnets.keras.bagnet17()
Probably I'm doing something wrong.
I would appreciate your help.
The error is in the below:
keras_model = bagnets.keras.bagnet17()
Traceback (most recent call last):
File "", line 1, in
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-ackages/keras/engine/saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-ackages/keras/engine/saving.py", line 225, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-ackages/keras/engine/saving.py", line 458, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/layers/init.py", line 55, in deserialize
printable_module_name='layer')
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/engine/network.py", line 1022, in from_config
process_layer(layer_data)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/engine/network.py", line 1008, in process_layer
custom_objects=custom_objects)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/layers/init.py", line 55, in deserialize
printable_module_name='layer')
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/layers/core.py", line 735, in from_config
function = func_load(config['function'], globs=globs)
File "/home/kd/anaconda2/bin/py27_1/local/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 235, in func_load
code = marshal.loads(raw_code)
ValueError: bad marshal data (unknown type code)
The text was updated successfully, but these errors were encountered: