Tensorflow: how to save/restore a model?

前端 未结 26 2539
迷失自我
迷失自我 2020-11-21 11:37

After you train a model in Tensorflow:

  1. How do you save the trained model?
  2. How do you later restore this saved model?
26条回答
  •  伪装坚强ぢ
    2020-11-21 12:11

    You can save the variables in the network using

    saver = tf.train.Saver() 
    saver.save(sess, 'path of save/fileName.ckpt')
    

    To restore the network for reuse later or in another script, use:

    saver = tf.train.Saver()
    saver.restore(sess, tf.train.latest_checkpoint('path of save/')
    sess.run(....) 
    

    Important points:

    1. sess must be same between first and later runs (coherent structure).
    2. saver.restore needs the path of the folder of the saved files, not an individual file path.

提交回复
热议问题