Closed lucataglia closed 6 years ago
@lucaRadicalbit You can use tf.saver(...)
which takes exactly the same arguments as the constructor of the Saver
class. :)
Maybe I am missing something really easy but I already try tf.saver and I got: The compile error told about a Saveable. I really can not figured out what I'm doing wrong.
@lucaRadicalbit That's because the saver constructor does not take a session argument. This is the signature:
def saver(
saveables: Set[Saveable] = null, reshape: Boolean = false, sharded: Boolean = false, maxToKeep: Int = 5,
keepCheckpointEveryNHours: Float = 10000.0f, restoreSequentially: Boolean = false, filename: String = "model",
builder: SaverDefBuilder = DefaultSaverDefBuilder, allowEmpty: Boolean = false,
writerVersion: WriterVersion = V2, saveRelativePaths: Boolean = false, padGlobalStep: Boolean = false,
name: String = "Saver"): Saver
So, if you want it to save all trainable variables (the default), all you need to do is:
val savePath = Paths.get("./my-model")
val saver = tf.saver()
// After having created the saver you can save using:
saver.save(session, savePath)
And you can reuse that saver
object across different sessions too. :)
@eaplatanios Thank you very much, it works !!
@lucaRadicalbit That's great to hear! :)
@sujitbiswas If you use the Estimator
, then you can add a CheckpointSaverHook
and that will handle saving and restoring state while training for you automatically. :)
On Oct 24, 2017, 10:26 AM -0400, sujitbiswas notifications@github.com, wrote:
@eaplatanios related question, how to use saver with Estimator? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I'm looking for a way to save a TF model and than restore for training just like the Python API allow me to do. Looking at the way for save the model:
I need to do something similar in Scala. Reading the Saver class documentation of the Scala API read that I can do:
But I can not understand how create the
saver
object on which thesaver
method is called. I try to use the constructor of the Saver class but it's private. Looking at the code on GitHub I saw that there is a companion object that expose some method but I did't find a way to do what I need.