【问题标题】:Export tensorflow weights to hdf5 file and model to keras model.json将张量流权重导出到 hdf5 文件和模型到 keras model.json
【发布时间】:2017-09-10 04:04:00
【问题描述】:

我最近发现了这个Project,它使用 webgl 在支持 GPU 的浏览器中运行 keras 模型的推理。我有一些我想在浏览器上运行推理的 tensorflow 项目,有没有办法将 tensorflow 模型导出到 hdf5 文件中,以便可以使用 keras-js 运行它

【问题讨论】:

标签: python tensorflow keras hdf5


【解决方案1】:

如果你使用的是 Keras,你可以这样做。

model.save_weights('my_model.hdf5')

【讨论】:

  • 不,我正在使用 tensorflow
【解决方案2】:

我能看到这个工作的唯一方法是如果你使用Keras 模型作为你的TensorFlow 工作流的接口。如果你这样做,你可以这样做来保存模型及其权重:

# 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)

更多关于使用Keras 作为Tensorflow 工作流接口的信息:https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html#using-keras-models-with-tensorflow

【讨论】:

    猜你喜欢
    • 2020-01-18
    • 1970-01-01
    • 2018-10-11
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    相关资源
    最近更新 更多