Or *_*ets 6 python machine-learning tensorflow
我想使用我的神经网络而不再训练网络.我读到了
save_path = saver.save(sess, "model.ckpt")
print("Model saved in file: %s" % save_path)
Run Code Online (Sandbox Code Playgroud)
现在我把文件夹中的3个文件:checkpoint,model.ckpt,和model.ckpt.meta
我希望,在python的另一个类中恢复数据,获得我的神经网络的权重并进行单一预测.
我怎样才能做到这一点?
要保存模型,您可以这样做:
model_checkpoint = 'model.chkpt'
# Create the model
...
...
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
# Create a saver so we can save and load the model as we train it
tf_saver = tf.train.Saver(tf.all_variables())
# (Optionally) do some training of the model
...
...
tf_saver.save(sess, model_checkpoint)
Run Code Online (Sandbox Code Playgroud)
我假设您已经完成了此操作,因为您已经获得了三个文件。当你想在另一个类中加载模型时,你可以这样做:
# The same file as we saved earlier
model_checkpoint = 'model.chkpt'
# Create the SAME model as before
...
...
with tf.Session() as sess:
# Restore the model
tf_saver = tf.train.Saver()
tf_saver.restore(sess, model_checkpoint)
# Now your model is loaded with the same values as when you saved,
# and you can do prediction or continue training
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6135 次 |
| 最近记录: |