Export tensorflow weights to hdf5 file and model to keras model.json

柔情痞子 提交于 2019-12-25 09:03:12

问题


I recently found this Project which runs inference of keras model in a browser with GPU support using webgl. I have a few tensorflow project that I would like to run inference on a browser, is there a way to export tensorflow models into hdf5 file so it can be run using keras-js


回答1:


If you are using Keras, you can do something like this.

model.save_weights('my_model.hdf5')



回答2:


The only way I can see this working is if you use a Keras model as an interface to your TensorFlow workflow. If you do that, you can do this to save the model and its weights:

# save model
with open(model_save_filename, "w") as model_save_file:
    model_json = model.to_json()
    model_save_file.write(model_json)

# save model weights
model.save_weights(model_weights_save_filename)

More information on using Keras as an interface to Tensorflow workflows here: https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html#using-keras-models-with-tensorflow



来源:https://stackoverflow.com/questions/43402320/export-tensorflow-weights-to-hdf5-file-and-model-to-keras-model-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!