awslabs / keras-apache-mxnet

[DEPRECATED] Amazon Deep Learning's Keras with Apache MXNet support
https://github.com/awslabs/keras-apache-mxnet/wiki
Other
289 stars 65 forks source link

Unable to export to mxnet (unless immediately after training) #227

Closed 4sfaloth closed 5 years ago

4sfaloth commented 5 years ago

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or on the Keras Slack channel instead of opening a GitHub issue.

Thank you!

As the title says, I am only able to export the model to mxnet format (via keras.models.save_mxnet_model) immediately after training. That is, if I run the save_mxnet_model at the end of my training script, I get the mxnet files alright. But if I tried to load the keras .h5 file from disk and then run the save_mxnet_model I get this weird error

_...lib\site-packages\keras\engine\saving.py", line 82, in save_mxnet_model pred_module = module.buckets['pred'] KeyError: 'pred'

Any ideas on what may be causing this?

I am using keras-mxnet 2.2.4.1 and mxnet 1.4.0

roywei commented 5 years ago

Hi @4sfaloth, it's due to mxnet backend, we are using different buckets (train, pred, test) to do training and prediction. when a model is loaded from 'h5' these buckets have not been initialized. A solution now is to run prediction on any data. then save to mxnet

model = load_model('keras_model.h5')
model.predict(x_test)
save_mxnet_model(model, 'mxnet_model')

BTW, we only support h5 files trained with mxnet backend for now.

4sfaloth commented 5 years ago

@roywei thanks for the fast response. Indeed we had found and started to use that workaround in the meantime, but I was hoping there would be a cleaner way to achieve it. Thanks for the help!