Initializer that sets the value of the variable to the provided value
.
Initializer that sets the value of the variable to the provided value
.
Glorot Normal initializer, also called the Xavier Normal initializer..
Glorot Normal initializer, also called the Xavier Normal initializer..
This initializer draws samples from a Normal distribution centered on zero and with standard deviation equal to
sqrt(2 / (fanIn + fanOut))
, where fanIn
is the number of input units in the weight tensor and fanOut
is the
number of output units in the weight tensor.
Reference: [Understanding the difficulty of training deep feed-forward neural networks](http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf)
Optional random seed, used to generate a random seed pair for the random number generator, when combined with the graph-level seed.
Glorot uniform initializer, also called the Xavier uniform initializer..
Glorot uniform initializer, also called the Xavier uniform initializer..
This initializer draws samples from a uniform distribution within [-limit, limit]
, where limit
is equal to
sqrt(6 / (fanIn + fanOut))
, where fanIn
is the number of input units in the weight tensor and fanOut
is the
number of output units in the weight tensor.
Reference: [Understanding the difficulty of training deep feed-forward neural networks](http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf)
Optional random seed, used to generate a random seed pair for the random number generator, when combined with the graph-level seed.
Base trait for all variable initializers.
Partitioned variable wrapper.
Partitioned variable wrapper.
Variables passed via wrappedVariables
must contain a non-null save slice information field. Concatenation and
iteration is in lexicographic order according to the variableOffset
property of the save slice information.
Accessing this object as an Output returns the variable parts concatenated along the partition axis.
This wrapper also acts as an iterator that allows accessing the underlying variables. This iterator is necessary to control the order of access when variables are not partitioned in a standard way along a single axis.
IllegalArgumentException
If the provided variables sequence is empty, or if their shapes do not match with
shape
, or if their data types do not match dataType
., or if they have
null
-valued save slice information
A variable partitioner is simply a function that accepts the DataType
and the fully defined Shape
of the
variable to be created, and returns an array of integers corresponding to the number of partitions for each axis
(currently only one axis can be partitioned).
Initializer that sets the value of the variable to a value
drawn from a Normal distribution.
Initializer that sets the value of the variable to a value
drawn from a truncated Normal distribution.
Initializer that sets the value of the variable to a value
drawn from a uniform distribution.
A variable regularizer is simply a function that takes an Op.Output
representing the variable value as input, and
returns another Output representing the regularizer value as output.
Enumeration of possible variable reuse options, used by variable scopes and variable stores.
Enumeration of possible variable reuse options, used by variable scopes and variable stores.
The supported options are:
Trait marking the variable reuse modes that allow reusing existing variables.
Class used to describe tensor slices that need to be saved.
Base class for defining objects that be saved and restored.
A saver can save and restore variables and other saveable objects.
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:
maxToKeep
: The maximum number of recent checkpoint files to keep. As new files are created, older files are
deleted. If 0
, no checkpoints are deleted from the filesystem but only the last one is kept in the
checkpoint
file. Defaults to 5
(i.e., only the 5 most recent checkpoint files are kept).keepCheckpointEveryNHours
: In addition to keeping the most recent maxToKeep
checkpoint files, you might want
to keep one checkpoint file for every N
hours of training. This can be useful if you want to later analyze how
a model progressed during a long training session. For example, passing keepCheckpointEveryNHours = 2
ensures
that you keep one checkpoint file for every 2 hours of training. The default value of 10000
hours effectively
disables the feature.
Note that you still have to call the save
method every time you want to save the model. Passing these arguments to
the constructor will not save variables automatically for you.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).
A saver builder is used to build SaverDef objects.
A saver builder is used to build SaverDef objects.
Most users shall never have to worry about dealing with saver builders. The Saver constructor uses DefaultSaverDefBuilder by default, which should be fine for most applications.
Variable based on resource handles.
Variable based on resource handles.
See the Variables Guide for a high-level overview.
A variable allows you to maintain state across subsequent calls to Session.run()
. The variable constructors
require an initial value for the variable, which can be a tensor of any type and shape. The initial value defines
the type and shape of the variable. After construction, the type and shape of the variable are fixed. The value can
be changed using one of the assignment methods.
Just like any tensor, variables can be used as inputs for other ops in the graph. Additionally, all the operators overloaded for tensors are carried over to variables, so you can also add nodes to the graph by just doing arithmetic on variables.
Unlike the Python API, the Scala API uses resource variables that have well-defined semantics. Each usage of a
resource variable in a TensorFlow graph adds a read
operation to the graph. The tensors returned by a read
operation are guaranteed to see all modifications to the value of the variable which happen in any operation on
which the read
depends on (either directly, indirectly, or via a control dependency) and guaranteed to not see
any modification to the value of the variable from operations that depend on the read
operation. Updates from
operations that have no dependency relationship to the read
operation might or might not be visible to read
. For
example, if there is more than one assignment to a resource variable in a single Session.run()
call there is a
well-defined value for each operation which uses the variable's value if the assignments and the read
are
connected by edges in the graph.
Represents objects that can be used as variables (e.g., variables and partitioned variables).
Variable scope that carries default settings to provide to getVariable
.
Variable scope that carries default settings to provide to getVariable
.
A variable scope allows to create new variables and to share already created ones while providing checks to not create or share by accident.
Many of the arguments we need for getVariable
in a variable store are most easily handled with a context.
VariableScope objects are used for the defaults.
A thread-local score for the current variable scope and scope counts.
Variable store that carries a number of named variables.
Initializer capable of adapting its scale to the shape of weights tensors.
Initializer capable of adapting its scale to the shape of weights tensors.
With the Normal distribution option, samples are drawn from a truncated Normal distribution centered on zero, and
with standard deviation equal to sqrt(initialScale / n)
, where n
is:
mode == FanInScalingMode
,mode == FanOutScalingMode
, ormode == FanAverageScalingMode
With uniform distribution option, samples are drawn from a uniform distribution within [-limit, limit]
, where
limit = sqrt(3 * initialScale / n)
.
Create new variables only and throw an exception if a variable with the same name exists.
Initializer that sets all elements of the variable tensor to ones.
Reuse existing variables only and throw an exception if no appropriate variable exists.
Reuse existing variables or create new ones, if no variable with the provided name exists.
Contains helper functions for managing savers.
Contains helper functions for saver builders.
Initializer that sets all elements of the variable tensor to zeros.
This function defines the main logic of 'getVariable'.
This function defines the main logic of 'getVariable'. However, 'underlyingGetter' may override this logic. That is why we pass it as an argument to the 'underlyingGetter'.
Returns a default variable initializer.
Returns a default variable initializer.
Variable name.
Variable data type.
Default initializer.
IllegalArgumentException
If no default initializer is defined for the specified data type.