Class/Object

org.platanios.tensorflow.api.ops.variables

Saver

Related Docs: object Saver | package variables

Permalink

class Saver extends Serializable

A saver can save and restore variables and other saveable objects.

This class adds ops to save and restore variables to and from *checkpoints*. It also provides convenience methods to run these ops. Checkpoints are binary files in a proprietary format which map variable names to tensor values. The best way to examine the contents of a checkpoint is to load it using a Saver.

Savers can automatically number checkpoint filenames. This lets you keep multiple checkpoints at different steps while training a model. For example, you can number the checkpoint filenames with the training step number. To avoid filling up disks, savers manage checkpoint files automatically. For example, they can make sure to keep only the N most recent files, or one checkpoint for every N hours of training.

You may number checkpoint filenames by passing a value to the optional globalStep argument of the save method. For example:

// Using a slight abuse of notation for paths:
saver.save(session, "my-model", globalStep = 0) ==> filename: "my-model-0"
saver.save(session, "my-model", globalStep = 1000) ==> filename: "my-model-1000"

Also, optional arguments to the Saver constructor let you control the proliferation of checkpoint files on disk:

An example training program that saves regularly looks like this:

// Using a slight abuse of notation.
// Create a saver.
val saver = tf.Saver(variables)
// Launch the graph and train, saving the model every 1,000 steps.
for (step <- 0 to 1000000) {
  session.run(trainOp)
  if (step % 1000 == 0) {
    // Append the step number to the checkpoint name.
    saver.save(session, "my-model", globalStep = step)
  }
}

In addition to checkpoint files, savers keep a protocol buffer on disk with the list of recent checkpoints. This is used to manage numbered checkpoint files. The latestCheckpoint method makes it easy to discover the path to the most recent checkpoint. That protocol buffer is stored in a file next to the checkpoint files, with default name "checkpoint" (can be provided using the checkpointStateFilename argument of the save method).

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Saver
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. def latestCheckpoints: Seq[Path]

    Permalink

    Returns the sequence of the latest and not-yet-deleted checkpoint filenames, sorted from oldest to newest.

    Returns the sequence of the latest and not-yet-deleted checkpoint filenames, sorted from oldest to newest. You can pass any of the returned values to restore.

  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def recoverLastCheckpoints(checkpoints: Seq[Path]): Unit

    Permalink

    Recovers the internal saver state (holding the last checkpoints) after a crash.

    Recovers the internal saver state (holding the last checkpoints) after a crash.

    This method searches for the checkpoints pointed to by checkpoints (which can also be glob patterns). If the files exist, the method uses their last modification time as the checkpoint stamp.

    checkpoints

    Sequence of checkpoint filenames (can also be glob patterns).

  17. def restore(session: core.client.Session, savePath: Path): Unit

    Permalink

    Restores previously saved saveables.

    Restores previously saved saveables.

    This method runs the ops responding for restoring variables. It requires a session in which the saver's graph was launched. The variables to restore do not have to have been initialized, as restoring is itself a way to initialize variables.

    The savePath argument is typically a value previously returned from a save call, or a call to Saver.latestCheckpoint.

    session

    Session to use for restoring the variables.

    savePath

    Path to the checkpoint filename. If the saver is sharded, this is the prefix of the sharded checkpoint filenames.

  18. def save(session: core.client.Session, savePath: Path, globalStep: Option[Int] = None, checkpointStateFilename: String = "checkpoint", metaGraphSuffix: String = "meta", writeMetaGraph: Boolean = true, writeCheckpointState: Boolean = true): Option[Path]

    Permalink

    Saves the current value of the saveables this saver is responsible for.

    Saves the current value of the saveables this saver is responsible for.

    This method runs the ops responsible for saving variables. It requires a session in which the saver's graph was launched. The variables being saved must also have been initialized.

    The method returns the path of the newly created checkpoint file. This path can be passed directly to restore.

    session

    Session to use for saving the variables.

    savePath

    Path to the checkpoint filename. If the saver is sharded, this is the prefix of the sharded checkpoint filenames

    globalStep

    If provided, the global step number is appended to savePath to create the checkpoint filename.

    checkpointStateFilename

    Optional name for the protocol buffer file that will contain / contains the list of the most recent checkpoint filenames. That file, kept in the same directory as the checkpoint files, and it is automatically managed by the saver to keep track of recent checkpoints.

    metaGraphSuffix

    Meta graph filename suffix.

    writeMetaGraph

    Boolean value indicating whether or not to write the graph meta information file.

    writeCheckpointState

    Boolean value indicating whether or not to write the checkpoint state file.

    returns

    Path of the newly created checkpoint file, if the save operation was successful; None, otherwise. If the saver is sharded, the filename ends with "-?????-of-nnnnn" where "nnnnn" is the number of shards created.

  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def toProto(exportScope: String = null): SaverDef

    Permalink

    Alias for toSaverDef.

  21. def toProto: SaverDef

    Permalink

    Converts this object to its corresponding ProtoBuf object.

    Converts this object to its corresponding ProtoBuf object.

    returns

    ProtoBuf object corresponding to this object.

    Definition Classes
    SaverSerializable
  22. def toSaverDef(exportScope: String = null): SaverDef

    Permalink

    Constructs and returns a SaverDef object that represents this saver.

    Constructs and returns a SaverDef object that represents this saver.

    exportScope

    Optional string specifying the name scope to remove. Only the ops within this name scope will be included in the resulting ProtoBuf object and the export scope will be stripped from their names to allow for easy import into new name scopes.

    returns

    Constructed SaverDef.

  23. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. val writerVersion: WriterVersion

    Permalink

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped