Base class for different Reader types, that produce a record every step.
Conceptually, Readers convert string 'work units' into records (key, value pairs). Typically the 'work units' are filenames and the records are extracted from the contents of those files. We want a single record produced per step, but a work unit can correspond to many records.
Therefore we introduce some decoupling using a queue. The queue contains the work units and the Reader dequeues from the queue when it is asked to produce a record (via Read()) but it has finished the last work unit.
Readers are not compatible with eager execution. Instead, please use tf.data to get data into your model.
View source
Returns the number of records this reader has produced.
This is the same as the number of Read executions that have succeeded.
View source
Returns the number of work units this reader has finished processing.
View source
Returns the next record (key, value) pair produced by a reader.
Will dequeue a work unit from queue if necessary (e.g. when the Reader needs to start reading from a new file since it has finished with the previous file).
View source
Returns up to num_records (key, value) pairs produced by a reader.
Will dequeue a work unit from queue if necessary (e.g., when the Reader needs to start reading from a new file since it has finished with the previous file). It may return less than num_records even before the last batch.
View source
Restore a reader to its initial clean state.
View source
Restore a reader to a previously saved state.
Not all Readers support being restored, so this can produce an Unimplemented error.
View source
Produce a string tensor that encodes the state of a reader.
Not all Readers support being serialized, so this can produce an Unimplemented error.


Computes the "logical and" of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_all
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.all


Computes the "logical or" of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_any
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.any


Joins all strings into a single string, or joins along an axis.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.reduce_join


Computes log(sum(exp(elements across dimensions of a tensor))). (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_logsumexp
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
This function is more numerically stable than log(sum(exp(input))). It avoids overflows caused by taking the exp of large inputs and underflows caused by taking the log of small inputs.


Computes the maximum of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_max
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.max


Computes the mean of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_mean
Reduces input_tensor along the dimensions given in axis by computing the mean of elements across the dimensions in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.mean
Please note that np.mean has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.reduce_mean has an aggressive type inference from input_tensor, for example:


Computes the minimum of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_min
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.min


Computes the product of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_prod
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.prod


Computes the sum of elements across dimensions of a tensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_sum
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.sum apart the fact that numpy upcast uint8 and int32 to int64 while tensorflow returns the same dtype as the input.


Adds ops to list the names of uninitialized variables.
When run, it returns a 1-D tensor containing the names of uninitialized variables if there are any, or an empty array if there are none.


Clears the default graph stack and resets the global default graph.


Resource management library.
get_data_files_path(...): Get a direct path to the data files colocated with the script.
get_path_to_datafile(...): Get the path to the specified file in the data dependencies.
get_root_dir_with_all_resources(...): Get a root directory containing all the data attributes in the build rule.
load_resource(...): Load the resource at given path, where path is relative to tensorflow/.
readahead_file_path(...): Readahead files not implemented; simply returns given path.


Get a direct path to the data files colocated with the script.


Get the path to the specified file in the data dependencies.
The path is relative to tensorflow/


Get a root directory containing all the data attributes in the build rule.


Load the resource at given path, where path is relative to tensorflow/.


Readahead files not implemented; simply returns given path.


Returns True if resource variables are enabled.
Resource variables are improved versions of TensorFlow variables with a well-defined memory model. Accessing a resource variable reads its value, and all ops which access a specific read value of the variable are guaranteed to see the same value for that tensor. Writes which happen after a read (by having a control or data dependency on the read) are guaranteed not to affect the value of the read tensor, and similarly writes which happen before a read are guaranteed to affect the value. No guarantees are made about unordered read/write pairs.
Calling tf.enable_resource_variables() lets you opt-in to this TensorFlow 2.0 feature.


Reverses variable length slices. (deprecated arguments) (deprecated arguments)
This op first slices input along the dimension batch_axis, and for each slice i, reverses the first seq_lengths[i] elements along the dimension seq_axis.
The elements of seq_lengths must obey seq_lengths[i] <= input.dims[seq_axis], and seq_lengths must be a vector of length input.dims[batch_axis].
The output slice i along dimension batch_axis is then given by input slice i, with the first seq_lengths[i] slices along dimension seq_axis reversed.


A ProtocolMessage
class RunHandlerPoolOptions


Public API for tf.saved_model namespace.
builder module: SavedModel builder.
constants module: Constants for SavedModel save and restore operations.
experimental module: Public API for tf.saved_model.experimental namespace.
loader module: Loader functionality for SavedModel with hermetic, language-neutral exports.
main_op module: SavedModel main op.
signature_constants module: Signature constants for SavedModel save and restore operations.
signature_def_utils module: SignatureDef utility functions.
tag_constants module: Common tags used for graphs in SavedModel.
utils module: SavedModel utility functions.
class Asset: Represents a file asset to hermetically include in a SavedModel.
class Builder: Builds the SavedModel protocol buffer and saves variables and assets.
class SaveOptions: Options for saving to SavedModel.
build_signature_def(...): Utility function to build a SignatureDef protocol buffer.
build_tensor_info(...): Utility function to build TensorInfo proto from a Tensor. (deprecated)
classification_signature_def(...): Creates classification signature from given examples and predictions.
contains_saved_model(...): Checks whether the provided export directory could contain a SavedModel.
get_tensor_from_tensor_info(...): Returns the Tensor or CompositeTensor described by a TensorInfo proto. (deprecated)
is_valid_signature(...): Determine whether a SignatureDef can be served by TensorFlow Serving.
load(...): Loads the model from a SavedModel as specified by tags. (deprecated)
load_v2(...): Load a SavedModel from export_dir.
main_op_with_restore(...): Returns a main op to init variables, tables and restore the graph. (deprecated)
maybe_saved_model_directory(...): Checks whether the provided export directory could contain a SavedModel.
predict_signature_def(...): Creates prediction signature from given inputs and outputs.
regression_signature_def(...): Creates regression signature from given examples and predictions.
save(...): Exports the Trackable object obj to SavedModel format.
simple_save(...): Convenience function to build a SavedModel suitable for serving. (deprecated)


SavedModel builder.
Builds a SavedModel that can be saved to storage, is language neutral, and enables systems to produce, consume, or transform TensorFlow Models.
class SavedModelBuilder: Builds the SavedModel protocol buffer and saves variables and assets.


Utility function to build a SignatureDef protocol buffer.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.signature_def_utils.build_signature_def


Utility function to build TensorInfo proto from a Tensor. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.utils.build_tensor_info


Creates classification signature from given examples and predictions.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.signature_def_utils.classification_signature_def
This function produces signatures intended for use with the TensorFlow Serving Classify API (tensorflow_serving/apis/prediction_service.proto), and so constrains the input and output types to those allowed by TensorFlow Serving.


Constants for SavedModel save and restore operations.


Checks whether the provided export directory could contain a SavedModel.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.loader.maybe_saved_model_directory, tf.compat.v1.saved_model.maybe_saved_model_directory
Note that the method does not load any data by itself. If the method returns false, the export directory definitely does not contain a SavedModel. If the method returns true, the export directory may contain a SavedModel but provides no guarantee that it can be loaded.


Public API for tf.saved_model.experimental namespace.
class VariablePolicy: Enum defining options for variable handling when saving.
save(...): Exports the Trackable object obj to SavedModel format.


Returns the Tensor or CompositeTensor described by a TensorInfo proto. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.utils.get_tensor_from_tensor_info


Determine whether a SignatureDef can be served by TensorFlow Serving.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.signature_def_utils.is_valid_signature


Loads the model from a SavedModel as specified by tags. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.loader.load


Loader functionality for SavedModel with hermetic, language-neutral exports.
Load and restore capability for a SavedModel, which may include multiple meta graph defs. Each SavedModel is associated with a single checkpoint. Each meta graph def is saved with one or more tags, which are used to identify the exact meta graph def to load.
The load operation requires the session in which to restore the graph definition and variables, the tags used to identify the meta graph def to load and the location of the SavedModel.
Upon a load, the subset of variables and assets supplied as part of the specific meta graph def, will be restored into the supplied session. The values of the variables though will correspond to the saved values from the first meta graph added to the SavedModel using add_meta_graph_and_variables(...) in builder.py.
load(...): Loads the model from a SavedModel as specified by tags. (deprecated)
maybe_saved_model_directory(...): Checks whether the provided export directory could contain a SavedModel.


SavedModel main op.
Builds a main op that defines the sequence of ops to be run as part of the SavedModel load/restore operations.
main_op(...): Returns a main op to init variables and tables. (deprecated)
main_op_with_restore(...): Returns a main op to init variables, tables and restore the graph. (deprecated)


Returns a main op to init variables and tables. (deprecated)
Returns the main op including the group of ops that initializes all variables, initializes local variables and initialize all tables.


Returns a main op to init variables, tables and restore the graph. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.main_op.main_op_with_restore
Returns the main op including the group of ops that initializes all variables, initialize local variables, initialize all tables and the restore op name.


Creates prediction signature from given inputs and outputs.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.signature_def_utils.predict_signature_def
This function produces signatures intended for use with the TensorFlow Serving Predict API (tensorflow_serving/apis/prediction_service.proto). This API imposes no constraints on the input and output types.


Creates regression signature from given examples and predictions.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.saved_model.signature_def_utils.regression_signature_def
This function produces signatures intended for use with the TensorFlow Serving Regress API (tensorflow_serving/apis/prediction_service.proto), and so constrains the input and output types to those allowed by TensorFlow Serving.


Signature constants for SavedModel save and restore operations.


SignatureDef utility functions.
Utility functions for building and inspecting SignatureDef protos.
class MethodNameUpdater: Updates the method name(s) of the SavedModel stored in the given path.
build_signature_def(...): Utility function to build a SignatureDef protocol buffer.
classification_signature_def(...): Creates classification signature from given examples and predictions.
is_valid_signature(...): Determine whether a SignatureDef can be served by TensorFlow Serving.
predict_signature_def(...): Creates prediction signature from given inputs and outputs.
regression_signature_def(...): Creates regression signature from given examples and predictions.


Updates the method name(s) of the SavedModel stored in the given path.
The MethodNameUpdater class provides the functionality to update the method name field in the signature_defs of the given SavedModel. For example, it can be used to replace the predict method_name to regress.
Typical usages of the MethodNameUpdater
View source
Replaces the method_name in the specified signature_def.
This will match and replace multiple sig defs iff tags is None (i.e when multiple MetaGraphs have a signature_def with the same key). If tags is not None, this will only replace a single signature_def in the MetaGraph with matching tags.
View source
Saves the updated SavedModel.


Convenience function to build a SavedModel suitable for serving. (deprecated)
In many common cases, saving models for serving will be as simple as:
Although in many cases it's not necessary to understand all of the many ways to configure a SavedModel, this method has a few practical implications:
More information about SavedModel and signatures can be found here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md


Common tags used for graphs in SavedModel.


SavedModel utility functions.
Utility functions to assist with setup and construction of the SavedModel proto.
build_tensor_info(...): Utility function to build TensorInfo proto from a Tensor. (deprecated)
get_tensor_from_tensor_info(...): Returns the Tensor or CompositeTensor described by a TensorInfo proto. (deprecated)


Multiplies a scalar times a Tensor or IndexedSlices object.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.scalar_mul
Intended for use in gradient code which might deal with IndexedSlices objects, which are easy to multiply by a scalar but more expensive to multiply with arbitrary tensors.


scan on the list of tensors unpacked from elems on dimension 0.
See also tf.map_fn.
The simplest version of scan repeatedly applies the callable fn to a sequence of elements from first to last. The elements are made of the tensors unpacked from elems on dimension 0. The callable fn takes two tensors as arguments. The first argument is the accumulated value computed from the preceding invocation of fn, and the second is the value at the current position of elems. If initializer is None, elems must contain at least one element, and its first element is used as the initializer.
Suppose that elems is unpacked into values, a list of tensors. The shape of the result tensor is [len(values)] + fn(initializer, values[0]).shape. If reverse=True, it's fn(initializer, values[-1]).shape.
This method also allows multi-arity elems and accumulator. If elems is a (possibly nested) list or tuple of tensors, then each of these tensors must have a matching first (unpack) dimension. The second argument of fn must match the structure of elems.
If no initializer is provided, the output structure and dtypes of fn are assumed to be the same as its input; and in this case, the first argument of fn must match the structure of elems.
If an initializer is provided, then the output of fn must have the same structure as initializer; and the first argument of fn must match this structure.
For example, if elems is (t1, [t2, t3]) and initializer is [i1, i2] then an appropriate signature for fn in python2 is: fn = lambda (acc_p1, acc_p2), (t1, [t2, t3]): and fn must return a list, [acc_n1, acc_n2]. An alternative correct signature for fn, and the one that works in python3, is: fn = lambda a, t:, where a and t correspond to the input tuples.


Adds sparse updates to the variable referenced by resource.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the updated value. Duplicate entries are handled correctly: if multiple indices reference the same location, their contributions add.
Requires updates.shape = indices.shape + ref.shape[1:].


Divides a variable reference by sparse updates.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
Duplicate entries are handled correctly: if multiple indices reference the same location, their contributions divide.
Requires updates.shape = indices.shape + ref.shape[1:] or updates.shape = [].


Reduces sparse updates into a variable reference using the max operation.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
Duplicate entries are handled correctly: if multiple indices reference the same location, their contributions combine.
Requires updates.shape = indices.shape + ref.shape[1:] or updates.shape = [].


Reduces sparse updates into a variable reference using the min operation.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
Duplicate entries are handled correctly: if multiple indices reference the same location, their contributions combine.
Requires updates.shape = indices.shape + ref.shape[1:] or updates.shape = [].


Multiplies sparse updates into a variable reference.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
Duplicate entries are handled correctly: if multiple indices reference the same location, their contributions multiply.
Requires updates.shape = indices.shape + ref.shape[1:] or updates.shape = [].


Applies sparse addition to individual values or slices in a Variable.
ref is a Tensor with rank P and indices is a Tensor of rank Q.
indices must be integer tensor, containing indices into ref. It must be shape [d_0, ..., d_{Q-2}, K] where 0 < K <= P.
The innermost dimension of indices (with length K) corresponds to indices into elements (if K = P) or slices (if K < P) along the Kth dimension of ref.
updates is Tensor of rank Q-1+P-K with shape:
For example, say we want to add 4 scattered elements to a rank-1 tensor to 8 elements. In Python, that addition would look like this:
The resulting update to ref would look like this:
See tf.scatter_nd for more details about how to make updates to slices.


Applies sparse subtraction to individual values or slices in a Variable.
ref is a Tensor with rank P and indices is a Tensor of rank Q.
indices must be integer tensor, containing indices into ref. It must be shape [d_0, ..., d_{Q-2}, K] where 0 < K <= P.
The innermost dimension of indices (with length K) corresponds to indices into elements (if K = P) or slices (if K < P) along the Kth dimension of ref.
updates is Tensor of rank Q-1+P-K with shape:
For example, say we want to subtract 4 scattered elements from a rank-1 tensor with 8 elements. In Python, that update would look like this:
The resulting update to ref would look like this:
See tf.scatter_nd for more details about how to make updates to slices.


Applies sparse updates to individual values or slices in a Variable.
ref is a Tensor with rank P and indices is a Tensor of rank Q.
indices must be integer tensor, containing indices into ref. It must be shape [d_0, ..., d_{Q-2}, K] where 0 < K <= P.
The innermost dimension of indices (with length K) corresponds to indices into elements (if K = P) or slices (if K < P) along the Kth dimension of ref.
updates is Tensor of rank Q-1+P-K with shape:
For example, say we want to update 4 scattered elements to a rank-1 tensor to 8 elements. In Python, that update would look like this:
The resulting update to ref would look like this:
See tf.scatter_nd for more details about how to make updates to slices.


Subtracts sparse updates to a variable reference.
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
Duplicate entries are handled correctly: if multiple indices reference the same location, their (negated) contributions add.
Requires updates.shape = indices.shape + ref.shape[1:] or updates.shape = [].


Applies sparse updates to a variable reference.
This operation computes
This operation outputs ref after the update is done. This makes it easier to chain operations that need to use the reset value.
If values in ref is to be updated more than once, because there are duplicate entries in indices, the order at which the updates happen for each value is undefined.
Requires updates.shape = indices.shape + ref.shape[1:].


Serialize N-minibatch SparseTensor into an [N, 3] Tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.serialize_many_sparse
The SparseTensor must have rank R greater than 1, and the first dimension is treated as the minibatch dimension. Elements of the SparseTensor must be sorted in increasing order of this first dimension. The serialized SparseTensor objects going into each row of the output Tensor will have rank R-1.
The minibatch size N is extracted from sparse_shape[0].


Serialize a SparseTensor into a 3-vector (1-D Tensor) object.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.serialize_sparse


A class for running TensorFlow operations.
A Session object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated. For example:
A session may own resources, such as tf.Variable, tf.queue.QueueBase, and tf.compat.v1.ReaderBase. It is important to release these resources when they are no longer required. To do this, either invoke the tf.Session.close method on the session, or use the session as a context manager. The following two examples are equivalent:
The ConfigProto protocol buffer exposes various configuration options for a session. For example, to create a session that uses soft constraints for device placement, and log the resulting placement decisions, create a session as follows:
View source
Returns a context manager that makes this object the default session.
Use with the with keyword to specify that calls to tf.Operation.run or tf.Tensor.eval should be executed in this session.
To get the current default session, use tf.compat.v1.get_default_session.
Alternatively, you can use with tf.compat.v1.Session(): to create a session that is automatically closed on exiting the context, including when an uncaught exception is raised.
View source
Closes this session.
Calling this method frees all resources associated with the session.
View source
Lists available devices in this session.
Each element in the list has the following properties
View source
Returns a Python callable that runs a particular step.
The returned callable will take len(feed_list) arguments whose types must be compatible feed values for the respective elements of feed_list. For example, if element i of feed_list is a tf.Tensor, the ith argument to the returned callable must be a numpy ndarray (or something convertible to an ndarray) with matching element type and shape. See tf.Session.run for details of the allowable feed key and value types.
The returned callable will have the same return type as tf.Session.run(fetches, ...). For example, if fetches is a tf.Tensor, the callable will return a numpy ndarray; if fetches is a tf.Operation, it will return None.
View source
Continues the execution with more feeds and fetches.
This is EXPERIMENTAL and subject to change.
To use partial execution, a user first calls partial_run_setup() and then a sequence of partial_run(). partial_run_setup specifies the list of feeds and fetches that will be used in the subsequent partial_run calls.
The optional feed_dict argument allows the caller to override the value of tensors in the graph. See run() for more information.
Below is a simple example:
View source
Sets up a graph with feeds and fetches for partial run.
This is EXPERIMENTAL and subject to change.
Note that contrary to run, feeds only specifies the graph elements. The tensors will be supplied by the subsequent partial_run calls.
View source
Resets resource containers on target, and close all connected sessions.
A resource container is distributed across all workers in the same cluster as target. When a resource container on target is reset, resources associated with that container will be cleared. In particular, all Variables in the container will become undefined: they lose their values and shapes.
(i) reset() is currently only implemented for distributed sessions. (ii) Any sessions on the master named by target will be closed.
If no resource containers are provided, all containers are reset.
View source
Runs operations and evaluates tensors in fetches.
This method runs one "step" of TensorFlow computation, by running the necessary graph fragment to execute every Operation and evaluate every Tensor in fetches, substituting the values in feed_dict for the corresponding input values.
The fetches argument may be a single graph element, or an arbitrarily nested list, tuple, namedtuple, dict, or OrderedDict containing graph elements at its leaves. A graph element can be one of the following types:
The value returned by run() has the same shape as the fetches argument, where the leaves are replaced by the corresponding values returned by TensorFlow.
The optional feed_dict argument allows the caller to override the value of tensors in the graph. Each key in feed_dict can be one of the following types:
Each value in feed_dict must be convertible to a numpy array of the dtype of the corresponding key.
The optional options argument expects a [RunOptions] proto. The options allow controlling the behavior of this particular step (e.g. turning tracing on).
The optional run_metadata argument expects a [RunMetadata] proto. When appropriate, the non-Tensor output of this step will be collected there. For example, when users turn on tracing in options, the profiled info will be collected into this argument and passed back.
View source
View source


A ProtocolMessage
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.summary.SessionLog


Computes the difference between two lists of numbers or strings.
Given a list x and a list y, this operation returns a list out that represents all values that are in x but not in y. The returned list out is sorted in the same order that the numbers appear in x (duplicates are preserved). This operation also returns a list idx that represents the position of each out element in x. In other words:
out[i] = x[idx[i]] for i in [0, 1, ..., len(out) - 1]
For example, given this input:
This operation would return:


Tensorflow set operations.
difference(...): Compute set difference of elements in last dimension of a and b.
intersection(...): Compute set intersection of elements in last dimension of a and b.
set_difference(...): Compute set difference of elements in last dimension of a and b.
set_intersection(...): Compute set intersection of elements in last dimension of a and b.
set_size(...): Compute number of unique elements along last dimension of a.
set_union(...): Compute set union of elements in last dimension of a and b.
size(...): Compute number of unique elements along last dimension of a.
union(...): Compute set union of elements in last dimension of a and b.


Sets the graph-level random seed for the default graph.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.set_random_seed
Operations that rely on a random seed actually derive it from two seeds: the graph-level and operation-level seeds. This sets the graph-level seed.
Its interactions with operation-level seeds is as follows:
To illustrate the user-visible effects, consider these examples:
To generate different sequences across sessions, set neither graph-level nor op-level seeds:
To generate the same repeatable sequence for an op across sessions, set the seed for the op:
To make the random sequences generated by all ops be repeatable across sessions, set a graph-level seed:


Returns the shape of a tensor.
This operation returns a 1-D integer tensor representing the shape of input.


Signal processing operations.
See the tf.signal guide.
dct(...): Computes the 1D [Discrete Cosine Transform (DCT)][dct] of input.
fft(...): Fast Fourier transform.
fft2d(...): 2D fast Fourier transform.
fft3d(...): 3D fast Fourier transform.
fftshift(...): Shift the zero-frequency component to the center of the spectrum.
frame(...): Expands signal's axis dimension into frames of frame_length.
hamming_window(...): Generate a Hamming window.
hann_window(...): Generate a Hann window.
idct(...): Computes the 1D [Inverse Discrete Cosine Transform (DCT)][idct] of input.
ifft(...): Inverse fast Fourier transform.
ifft2d(...): Inverse 2D fast Fourier transform.
ifft3d(...): Inverse 3D fast Fourier transform.
ifftshift(...): The inverse of fftshift.
inverse_mdct(...): Computes the inverse modified DCT of mdcts.
inverse_stft(...): Computes the inverse Short-time Fourier Transform of stfts.
inverse_stft_window_fn(...): Generates a window function that can be used in inverse_stft.
irfft(...): Inverse real-valued fast Fourier transform.
irfft2d(...): Inverse 2D real-valued fast Fourier transform.
irfft3d(...): Inverse 3D real-valued fast Fourier transform.
kaiser_bessel_derived_window(...): Generate a [Kaiser Bessel derived window][kbd].
kaiser_window(...): Generate a [Kaiser window][kaiser].
linear_to_mel_weight_matrix(...): Returns a matrix to warp linear scale spectrograms to the mel scale.
mdct(...): Computes the [Modified Discrete Cosine Transform][mdct] of signals.
mfccs_from_log_mel_spectrograms(...): Computes MFCCs of log_mel_spectrograms.
overlap_and_add(...): Reconstructs a signal from a framed representation.
rfft(...): Real-valued fast Fourier transform.
rfft2d(...): 2D real-valued fast Fourier transform.
rfft3d(...): 3D real-valued fast Fourier transform.
stft(...): Computes the Short-time Fourier Transform of signals.
vorbis_window(...): Generate a [Vorbis power complementary window][vorbis].


Returns the size of a tensor.
Returns a 0-D Tensor representing the number of elements in input of type out_type. Defaults to tf.int32.
Equivalent to np.size()


SpaceToBatch for 4-D tensors of type T.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.space_to_batch
This is a legacy version of the more general SpaceToBatchND.
Zero-pads and then rearranges (permutes) blocks of spatial data into batch. More specifically, this op outputs a copy of the input tensor where values from the height and width dimensions are moved to the batch dimension. After the zero-padding, both height and width of the input must be divisible by the block size.
paddings = [[pad_top, pad_bottom], [pad_left, pad_right]]
The effective spatial dimensions of the zero-padded input tensor will be:
height_pad = pad_top + height + pad_bottom width_pad = pad_left + width + pad_right
The attr block_size must be greater than one. It indicates the block size.
The shape of the output will be:
[batchblock_sizeblock_size, height_pad/block_size, width_pad/block_size, depth]
Some examples:
(1) For the following input of shape [1, 2, 2, 1] and block_size of 2:
The output tensor has shape [4, 1, 1, 1] and value:
(2) For the following input of shape [1, 2, 2, 3] and block_size of 2:
The output tensor has shape [4, 1, 1, 3] and value:
(3) For the following input of shape [1, 4, 4, 1] and block_size of 2:
The output tensor has shape [4, 2, 2, 1] and value:
(4) For the following input of shape [2, 2, 4, 1] and block_size of 2:
The output tensor has shape [8, 1, 2, 1] and value:
Among others, this operation is useful for reducing atrous convolution into regular convolution.


SpaceToDepth for tensors of type T.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.space_to_depth
Rearranges blocks of spatial data, into depth. More specifically, this op outputs a copy of the input tensor where values from the height and width dimensions are moved to the depth dimension. The attr block_size indicates the input block size.
The data_format attr specifies the layout of the input and output tensors with the following options: "NHWC": [ batch, height, width, channels ] "NCHW": [ batch, channels, height, width ] "NCHW_VECT_C": qint8 [ batch, channels / 4, height, width, 4 ]
It is useful to consider the operation as transforming a 6-D Tensor. e.g. for data_format = NHWC, Each element in the input tensor can be specified via 6 coordinates, ordered by decreasing memory layout significance as: n,oY,bY,oX,bX,iC (where n=batch index, oX, oY means X or Y coordinates within the output image, bX, bY means coordinates within the input block, iC means input channels). The output would be a transpose to the following layout: n,oY,oX,bY,bX,iC
This operation is useful for resizing the activations between convolutions (but keeping all data), e.g. instead of pooling. It is also useful for training purely convolutional models.
For example, given an input of shape [1, 2, 2, 1], data_format = "NHWC" and block_size = 2:
This operation will output a tensor of shape [1, 1, 1, 4]:
Here, the input has a batch of 1 and each batch element has shape [2, 2, 1], the corresponding output will have a single element (i.e. width and height are both 1) and will have a depth of 4 channels (1 * block_size * block_size). The output element shape is [1, 1, 4].
For an input tensor with larger depth, here of shape [1, 2, 2, 3], e.g.
This operation, for block_size of 2, will return the following tensor of shape [1, 1, 1, 12]
Similarly, for the following input of shape [1 4 4 1], and a block size of 2:
the operator will return the following tensor of shape [1 2 2 4]:


Sparse Tensor Representation.
See also tf.sparse.SparseTensor.
class SparseConditionalAccumulator: A conditional accumulator for aggregating sparse gradients.
class SparseTensor: Represents a sparse tensor.
add(...): Adds two tensors, at least one of each is a SparseTensor. (deprecated arguments)
bincount(...): Count the number of times an integer value appears in a tensor.
concat(...): Concatenates a list of SparseTensor along the specified dimension. (deprecated arguments)
cross(...): Generates sparse cross from a list of sparse and dense tensors.
cross_hashed(...): Generates hashed sparse cross from a list of sparse and dense tensors.
expand_dims(...): Returns a tensor with an length 1 axis inserted at index axis.
eye(...): Creates a two-dimensional sparse tensor with ones along the diagonal.
fill_empty_rows(...): Fills empty rows in the input 2-D SparseTensor with a default value.
from_dense(...): Converts a dense tensor into a sparse tensor.
mask(...): Masks elements of IndexedSlices.
matmul(...): Multiply SparseTensor (or dense Matrix) (of rank 2) "A" by dense matrix
maximum(...): Returns the element-wise max of two SparseTensors.
merge(...): Combines a batch of feature ids and values into a single SparseTensor. (deprecated)
minimum(...): Returns the element-wise min of two SparseTensors.
placeholder(...): Inserts a placeholder for a sparse tensor that will be always fed.
reduce_max(...): Computes the max of elements across dimensions of a SparseTensor. (deprecated arguments) (deprecated arguments)
reduce_max_sparse(...): Computes the max of elements across dimensions of a SparseTensor. (deprecated arguments)
reduce_sum(...): Computes the sum of elements across dimensions of a SparseTensor. (deprecated arguments) (deprecated arguments)
reduce_sum_sparse(...): Computes the sum of elements across dimensions of a SparseTensor. (deprecated arguments)
reorder(...): Reorders a SparseTensor into the canonical, row-major ordering.
reset_shape(...): Resets the shape of a SparseTensor with indices and values unchanged.
reshape(...): Reshapes a SparseTensor to represent values in a new dense shape.
retain(...): Retains specified non-empty values within a SparseTensor.
segment_mean(...): Computes the mean along sparse segments of a tensor.
segment_sqrt_n(...): Computes the sum along sparse segments of a tensor divided by the sqrt(N).
segment_sum(...): Computes the sum along sparse segments of a tensor.
slice(...): Slice a SparseTensor based on the start and `size.
softmax(...): Applies softmax to a batched N-D SparseTensor.
sparse_dense_matmul(...): Multiply SparseTensor (or dense Matrix) (of rank 2) "A" by dense matrix
split(...): Split a SparseTensor into num_split tensors along axis. (deprecated arguments)
to_dense(...): Converts a SparseTensor into a dense tensor.
to_indicator(...): Converts a SparseTensor of ids into a dense bool indicator tensor.
transpose(...): Transposes a SparseTensor


A conditional accumulator for aggregating sparse gradients.
Inherits From: ConditionalAccumulatorBase
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.SparseConditionalAccumulator
Sparse gradients are represented by IndexedSlices.
Up-to-date gradients (i.e., time step at which gradient was computed is equal to the accumulator's time step) are added to the accumulator.
Extraction of the average gradient is blocked until the required number of gradients has been accumulated.
View source
Attempts to apply a sparse gradient to the accumulator.
The attempt is silently dropped if the gradient is stale, i.e., local_step is less than the accumulator's global time step.
A sparse gradient is represented by its indices, values and possibly empty or None shape. Indices must be a vector representing the locations of non-zero entries in the tensor. Values are the non-zero slices of the gradient, and must have the same first dimension as indices, i.e., the nnz represented by indices and values must be consistent. Shape, if not empty or None, must be consistent with the accumulator's shape (if also provided).
A tensor [[0, 0], [0, 1], [2, 3]] can be represented indices: [1,2] values: [[0,1],[2,3]] shape: [3, 2]
View source
Attempts to apply a gradient to the accumulator.
The attempt is silently dropped if the gradient is stale, i.e., local_step is less than the accumulator's global time step.
View source
Number of gradients that have currently been aggregated in accumulator.
View source
Sets the global time step of the accumulator.
The operation logs a warning if we attempt to set to a time step that is lower than the accumulator's own time step.
View source
Attempts to extract the average gradient from the accumulator.
The operation blocks until sufficient number of gradients have been successfully applied to the accumulator.
Once successful, the following actions are also triggered:
View source
Attempts to extract the average gradient from the accumulator.
The operation blocks until sufficient number of gradients have been successfully applied to the accumulator.
Once successful, the following actions are also triggered:


Adds two tensors, at least one of each is a SparseTensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.add
If one SparseTensor and one Tensor are passed in, returns a Tensor. If both arguments are SparseTensors, this returns a SparseTensor. The order of arguments does not matter. Use vanilla tf.add() for adding two dense Tensors.
The shapes of the two operands must match: broadcasting is not supported.
The indices of any input SparseTensor are assumed ordered in standard lexicographic order. If this is not the case, before this step run SparseReorder to restore index ordering.
If both arguments are sparse, we perform "clipping" as follows. By default, if two values sum to zero at some index, the output SparseTensor would still include that particular location in its index, storing a zero in the corresponding value slot. To override this, callers can specify thresh, indicating that if the sum has a magnitude strictly smaller than thresh, its corresponding value and index would then not be included. In particular, thresh == 0.0 (default) means everything is kept and actual thresholding happens only for a positive value.
For example, suppose the logical sum of two sparse operands is (densified):
Then,


Concatenates a list of SparseTensor along the specified dimension. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.concat
Concatenation is with respect to the dense versions of each sparse input. It is assumed that each inputs is a SparseTensor whose elements are ordered along increasing dimension number.
If expand_nonconcat_dim is False, all inputs' shapes must match, except for the concat dimension. If expand_nonconcat_dim is True, then inputs' shapes are allowed to vary among all inputs.
The indices, values, and shapes lists must have the same length.
If expand_nonconcat_dim is False, then the output shape is identical to the inputs', except along the concat dimension, where it is the sum of the inputs' sizes along that dimension.
If expand_nonconcat_dim is True, then the output shape along the non-concat dimensions will be expand to be the largest among all inputs, and it is the sum of the inputs sizes along the concat dimension.
The output elements will be resorted to preserve the sort order along increasing dimension number.
This op runs in O(M log M) time, where M is the total number of non-empty values across all inputs. This is due to the need for an internal sort in order to concatenate efficiently across an arbitrary dimension.
For example, if axis = 1 and the inputs are
then the output will be
Graphically this is equivalent to doing
Another example, if 'axis = 1' and the inputs are
if expand_nonconcat_dim = False, this will result in an error. But if expand_nonconcat_dim = True, this will result in:
Graphically this is equivalent to doing


Multiply matrix "a" by matrix "b".
The inputs must be two-dimensional matrices and the inner dimension of "a" must match the outer dimension of "b". Both "a" and "b" must be Tensors not SparseTensors. This op is optimized for the case where at least one of "a" or "b" is sparse, in the sense that they have a large proportion of zero values. The breakeven for using this versus a dense matrix multiply on one platform was 30% zero values in the sparse matrix.
The gradient computation of this operation will only take advantage of sparsity in the input gradient when that gradient comes from a Relu.


Combines a batch of feature ids and values into a single SparseTensor. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.merge
The most common use case for this function occurs when feature ids and their corresponding values are stored in Example protos on disk. parse_example will return a batch of ids and a batch of values, and this function joins them into a single logical SparseTensor for use in functions such as sparse_tensor_dense_matmul, sparse_to_dense, etc.
The SparseTensor returned by this function has the following properties:
For example, consider the following feature vectors:
These might be stored sparsely in the following Example protos by storing only the feature ids (column number if the vectors are treated as a matrix) of the non-zero elements and the corresponding values:
The result of calling parse_example on these examples will produce a dictionary with entries for "ids" and "values". Passing those two objects to this function along with vocab_size=6, will produce a SparseTensor that sparsely represents all three instances. Namely, the indices property will contain the coordinates of the non-zero entries in the feature matrix (the first dimension is the row number in the matrix, i.e., the index within the batch, and the second dimension is the column number, i.e., the feature id); values will contain the actual values. shape will be the shape of the original matrix, i.e., (3, 6). For our example above, the output will be equal to:
This method generalizes to higher-dimensions by simply providing a list for both the sp_ids as well as the vocab_size. In this case the resulting SparseTensor has the following properties:


Inserts a placeholder for a sparse tensor that will be always fed.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.placeholder
@compatibility{eager} Placeholders are not compatible with eager execution.


Computes the max of elements across dimensions of a SparseTensor. (deprecated arguments) (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.reduce_max
This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_max(). In particular, this Op also returns a dense Tensor instead of a sparse one.
Reduces sp_input along the dimensions given in reduction_axes. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keepdims is true, the reduced dimensions are retained with length 1.
If reduction_axes has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, similar to the indexing rules in Python.
The values not defined in sp_input don't participate in the reduce max, as opposed to be implicitly assumed 0 -- hence it can return negative values for sparse reduction_axes. But, in case there are no values in reduction_axes, it will reduce to 0. See second example below.


Computes the max of elements across dimensions of a SparseTensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.reduce_max_sparse
This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_max(). In contrast to SparseReduceSum, this Op returns a SparseTensor.
Reduces sp_input along the dimensions given in reduction_axes. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keepdims is true, the reduced dimensions are retained with length 1.
If reduction_axes has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, which are interpreted according to the indexing rules in Python.


Computes the sum of elements across dimensions of a SparseTensor. (deprecated arguments) (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.reduce_sum
This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_sum(). In particular, this Op also returns a dense Tensor instead of a sparse one.
Reduces sp_input along the dimensions given in reduction_axes. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keepdims is true, the reduced dimensions are retained with length 1.
If reduction_axes has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, similar to the indexing rules in Python.


Computes the sum of elements across dimensions of a SparseTensor. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.reduce_sum_sparse
This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_sum(). In contrast to SparseReduceSum, this Op returns a SparseTensor.
Reduces sp_input along the dimensions given in reduction_axes. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keepdims is true, the reduced dimensions are retained with length 1.
If reduction_axes has no entries, all dimensions are reduced, and a tensor with a single element is returned. Additionally, the axes can be negative, which are interpreted according to the indexing rules in Python.


Computes the mean along sparse segments of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.segment_mean
Read the section on segmentation for an explanation of segments.
Like tf.math.segment_mean, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. segment_ids is allowed to have missing ids, in which case the output will be zeros at those indices. In those cases num_segments is used to determine the size of the output.


Computes the sum along sparse segments of a tensor divided by the sqrt(N).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.segment_sqrt_n
N is the size of the segment being reduced.


Computes the sum along sparse segments of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.segment_sum
Read the section on segmentation for an explanation of segments.
Like tf.math.segment_sum, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. segment_ids is allowed to have missing ids, in which case the output will be zeros at those indices. In those cases num_segments is used to determine the size of the output.


Split a SparseTensor into num_split tensors along axis. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sparse.split
If the sp_input.dense_shape[axis] is not an integer multiple of num_split each slice starting from 0:shape[axis] % num_split gets extra one dimension. For example, if axis = 1 and num_split = 2 and the input is:
Graphically the output tensors are:


Converts a sparse representation into a dense tensor. (deprecated)
Builds an array dense with shape output_shape such that
All other values in dense are set to default_value. If sparse_values is a scalar, all sparse indices are set to this single value.
Indices should be sorted in lexicographic order, and indices must not contain any repeats. If validate_indices is True, these properties are checked during execution.


Public API for tf.spectral namespace.
dct(...): Computes the 1D [Discrete Cosine Transform (DCT)][dct] of input.
fft(...): Fast Fourier transform.
fft2d(...): 2D fast Fourier transform.
fft3d(...): 3D fast Fourier transform.
idct(...): Computes the 1D [Inverse Discrete Cosine Transform (DCT)][idct] of input.
ifft(...): Inverse fast Fourier transform.
ifft2d(...): Inverse 2D fast Fourier transform.
ifft3d(...): Inverse 3D fast Fourier transform.
irfft(...): Inverse real-valued fast Fourier transform.
irfft2d(...): Inverse 2D real-valued fast Fourier transform.
irfft3d(...): Inverse 3D real-valued fast Fourier transform.
rfft(...): Real-valued fast Fourier transform.
rfft2d(...): 2D real-valued fast Fourier transform.
rfft3d(...): 3D real-valued fast Fourier transform.


Removes dimensions of size 1 from the shape of a tensor. (deprecated arguments)
Given a tensor input, this operation returns a tensor of the same type with all dimensions of size 1 removed. If you don't want to remove all size 1 dimensions, you can remove specific size 1 dimensions by specifying axis.
Or, to remove specific size 1 dimensions:


Operations for working with string Tensors.
as_string(...): Converts each entry in the given tensor to strings.
bytes_split(...): Split string elements of input into bytes.
format(...): Formats a string template using a list of tensors.
join(...): Perform element-wise concatenation of a list of string tensors.
length(...): Computes the length of each string given in the input tensor.
lower(...): Converts all uppercase characters into their respective lowercase replacements.
ngrams(...): Create a tensor of n-grams based on data.
reduce_join(...): Joins all strings into a single string, or joins along an axis.
regex_full_match(...): Check if the input matches the regex pattern.
regex_replace(...): Replace elements of input matching regex pattern with rewrite.
split(...): Split elements of input based on sep.
strip(...): Strip leading and trailing whitespaces from the Tensor.
substr(...): Return substrings from Tensor of strings.
to_hash_bucket(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_hash_bucket_fast(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_hash_bucket_strong(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_number(...): Converts each string in the input Tensor to the specified numeric type.
unicode_decode(...): Decodes each string in input into a sequence of Unicode code points.
unicode_decode_with_offsets(...): Decodes each string into a sequence of code points with start offsets.
unicode_encode(...): Encodes each sequence of Unicode code points in input into a string.
unicode_script(...): Determine the script codes of a given tensor of Unicode integer code points.
unicode_split(...): Splits each string in input into a sequence of Unicode code points.
unicode_split_with_offsets(...): Splits each string into a sequence of code points with start offsets.
unicode_transcode(...): Transcode the input text from a source encoding to a destination encoding.
unsorted_segment_join(...): Joins the elements of inputs based on segment_ids.
upper(...): Converts all lowercase characters into their respective uppercase replacements.


Computes the length of each string given in the input tensor.


Split elements of input based on sep.
Let N be the size of input (typically N will be the batch size). Split each element of input based on sep and return a SparseTensor or RaggedTensor containing the split tokens. Empty tokens are ignored.
If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings. For example, input of "1<>2<><>3" and sep of "<>" returns ["1", "2", "", "3"]. If sep is None or an empty string, consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace.
Note that the above mentioned behavior matches python's str.split.


Return substrings from Tensor of strings.
For each string in the input Tensor, creates a substring starting at index pos with a total length of len.
If len defines a substring that would extend beyond the length of the input string, or if len is negative, then as many characters as possible are used.
A negative pos indicates distance within the string backwards from the end.
If pos specifies an index which is out of range for any of the input strings, then an InvalidArgumentError is thrown.
pos and len must have the same shape, otherwise a ValueError is thrown on Op creation.
Examples
Using scalar pos and len:
Using pos and len with same shape as input:
Broadcasting pos and len onto input:
Broadcasting input onto pos and len:


Split elements of source based on delimiter. (deprecated arguments)
Let N be the size of source (typically N will be the batch size). Split each element of source based on delimiter and return a SparseTensor or RaggedTensor containing the split tokens. Empty tokens are ignored.
If sep is an empty string, each element of the source is split into individual strings, each containing one byte. (This includes splitting multibyte sequences of UTF-8.) If delimiter contains multiple bytes, it is treated as a set of delimiters with each considered a potential split point.


Converts each string in the input Tensor to its hash mod by a number of buckets.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.to_hash_bucket
The hash function is deterministic on the content of the string within the process.
Note that the hash function may change from time to time. This functionality will be deprecated and it's recommended to use tf.string_to_hash_bucket_fast() or tf.string_to_hash_bucket_strong().


Converts each string in the input Tensor to the specified numeric type.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.to_number
(Note that int32 overflow results in an error while float overflow results in a rounded value.)


Operations for writing summary data, for use in analysis and visualization.
See the Summaries and TensorBoard guide.
class Event: A ProtocolMessage
class FileWriter: Writes Summary protocol buffers to event files.
class FileWriterCache: Cache for file writers.
class SessionLog: A ProtocolMessage
class Summary: A ProtocolMessage
class SummaryDescription: A ProtocolMessage
class TaggedRunMetadata: A ProtocolMessage
all_v2_summary_ops(...): Returns all V2-style summary ops defined in the current default graph.
audio(...): Outputs a Summary protocol buffer with audio.
get_summary_description(...): Given a TensorSummary node_def, retrieve its SummaryDescription.
histogram(...): Outputs a Summary protocol buffer with a histogram.
image(...): Outputs a Summary protocol buffer with images.
initialize(...): Initializes summary writing for graph execution mode.
merge(...): Merges summaries.
merge_all(...): Merges all summaries collected in the default graph.
scalar(...): Outputs a Summary protocol buffer containing a single scalar value.
tensor_summary(...): Outputs a Summary protocol buffer with a serialized tensor.proto.
text(...): Summarizes textual data.


Returns all V2-style summary ops defined in the current default graph.
This includes ops from TF 2.0 tf.summary and TF 1.x tf.contrib.summary (except for tf.contrib.summary.graph and tf.contrib.summary.import_event), but does not include TF 1.x tf.summary ops.


Outputs a Summary protocol buffer with audio.
The summary has up to max_outputs summary values containing audio. The audio is built from tensor which must be 3-D with shape [batch_size, frames, channels] or 2-D with shape [batch_size, frames]. The values are assumed to be in the range of [-1.0, 1.0] with a sample rate of sample_rate.
The tag in the outputted Summary.Value protobufs is generated based on the name, with a suffix depending on the max_outputs setting:


Writes Summary protocol buffers to event files.
The FileWriter class provides a mechanism to create an event file in a given directory and add summaries and events to it. The class updates the file contents asynchronously. This allows a training program to call methods to add data to the file directly from the training loop, without slowing down training.
When constructed with a tf.compat.v1.Session parameter, a FileWriter instead forms a compatibility layer over new graph-based summaries to facilitate the use of new summary writing with pre-existing code that expects a FileWriter instance.
This class is not thread-safe.
View source
Adds an event to the event file.
View source
Adds a Graph to the event file.
The graph described by the protocol buffer will be displayed by TensorBoard. Most users pass a graph in the constructor instead.
View source
Adds a MetaGraphDef to the event file.
The MetaGraphDef allows running the given graph via saver.import_meta_graph().
View source
Adds a metadata information for a single session.run() call.
View source
Adds a SessionLog protocol buffer to the event file.
This method wraps the provided session in an Event protocol buffer and adds it to the event file.
View source
Adds a Summary protocol buffer to the event file.
This method wraps the provided summary in an Event protocol buffer and adds it to the event file.
You can pass the result of evaluating any summary op, using tf.Session.run or tf.Tensor.eval, to this function. Alternatively, you can pass a tf.compat.v1.Summary protocol buffer that you populate with your own data. The latter is commonly done to report evaluation results in event files.
View source
Flushes the event file to disk and close the file.
Call this method when you do not need the summary writer anymore.
View source
Flushes the event file to disk.
Call this method to make sure that all pending events have been written to disk.
View source
Returns the directory where event file will be written.
View source
Reopens the EventFileWriter.
Can be called after close() to add more events in the same directory. The events will go into a new events file.
Does nothing if the EventFileWriter was not closed.
View source
Make usable with "with" statement.
View source
Make usable with "with" statement.


Cache for file writers.
This class caches file writers, one per directory.
View source
Clear cached summary writers. Currently only used for unit tests.
View source
Returns the FileWriter for the specified directory.


Given a TensorSummary node_def, retrieve its SummaryDescription.
When a Summary op is instantiated, a SummaryDescription of associated metadata is stored in its NodeDef. This method retrieves the description.
Not compatible with eager execution. To write TensorBoard summaries under eager execution, use tf.contrib.summary instead.


Outputs a Summary protocol buffer with a histogram.
Adding a histogram summary makes it possible to visualize your data's distribution in TensorBoard. You can see a detailed explanation of the TensorBoard histogram dashboard here.
The generated Summary has one summary value containing a histogram for values.
This op reports an InvalidArgument error if any value is not finite.


Outputs a Summary protocol buffer with images.
The summary has up to max_outputs summary values containing images. The images are built from tensor which must be 4-D with shape [batch_size, height, width, channels] and where channels can be:
The images have the same number of channels as the input tensor. For float input, the values are normalized one image at a time to fit in the range [0, 255]. uint8 values are unchanged. The op uses two different normalization algorithms:
If the input values are all positive, they are rescaled so the largest one is 255.
If any input value is negative, the values are shifted so input value 0.0 is at 127. They are then rescaled so that either the smallest value is 0, or the largest one is 255.
The tag in the outputted Summary.Value protobufs is generated based on the name, with a suffix depending on the max_outputs setting:


Initializes summary writing for graph execution mode.
This operation is a no-op when executing eagerly.
This helper method provides a higher-level alternative to using tf.contrib.summary.summary_writer_initializer_op and tf.contrib.summary.graph.
Most users will also want to call tf.compat.v1.train.create_global_step which can happen before or after this function is called.


Merges summaries.
This op creates a Summary protocol buffer that contains the union of all the values in the input summaries.
When the Op is run, it reports an InvalidArgument error if multiple values in the summaries to merge use the same tag.
Not compatible with eager execution. To write TensorBoard summaries under eager execution, use tf.contrib.summary instead.


Merges all summaries collected in the default graph.
Not compatible with eager execution. To write TensorBoard summaries under eager execution, use tf.contrib.summary instead.


Outputs a Summary protocol buffer containing a single scalar value.
The generated Summary has a Tensor.proto containing the input Tensor.


Outputs a Summary protocol buffer with a serialized tensor.proto.


Summarizes textual data.
Text data summarized via this plugin will be visible in the Text Dashboard in TensorBoard. The standard TensorBoard Text Dashboard will render markdown in the strings, and will automatically organize 1d and 2d tensors into tables. If a tensor with more than 2 dimensions is provided, a 2d subarray will be displayed along with a warning message. (Note that this behavior is not intrinsic to the text summary api, but rather to the default TensorBoard text plugin.)


System configuration library.
get_build_info(...): Get a dictionary describing TensorFlow's build environment.
get_compile_flags(...): Get the compilation flags for custom operators.
get_include(...): Get the directory containing the TensorFlow C++ header files.
get_lib(...): Get the directory containing the TensorFlow framework library.
get_link_flags(...): Get the link flags for custom operators.


Returns an Op that initializes all tables of the default graph.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.initializers.tables_initializer
See the Low Level Intro guide, for an example of usage.


A ProtocolMessage
class CompositeTensor
class CooSparse


Testing.
class Benchmark: Abstract class that provides helpers for TensorFlow benchmarks.
class StubOutForTesting: Support class for stubbing methods out for unit testing.
class TestCase: Base class for tests that need to test TensorFlow.
assert_equal_graph_def(...): Asserts that two GraphDefs are (mostly) the same.
benchmark_config(...): Returns a tf.compat.v1.ConfigProto for disabling the dependency optimizer.
compute_gradient(...): Computes and returns the theoretical and numerical Jacobian. (deprecated)
compute_gradient_error(...): Computes the gradient error. (deprecated)
create_local_cluster(...): Create and start local servers and return the associated Server objects.
get_temp_dir(...): Returns a temporary directory for use during tests.
gpu_device_name(...): Returns the name of a GPU device if available or the empty string.
is_built_with_cuda(...): Returns whether TensorFlow was built with CUDA (GPU) support.
is_built_with_gpu_support(...): Returns whether TensorFlow was built with GPU (i.e. CUDA or ROCm) support.
is_built_with_rocm(...): Returns whether TensorFlow was built with ROCm (GPU) support.
is_built_with_xla(...): Returns whether TensorFlow was built with XLA support.
is_gpu_available(...): Returns whether TensorFlow can access a GPU. (deprecated)
main(...): Runs all unit tests.
test_src_dir_path(...): Creates an absolute test srcdir path given a relative path.


Asserts that two GraphDefs are (mostly) the same.
Compares two GraphDef protos for equality, ignoring versions and ordering of nodes, attrs, and control inputs. Node names are used to match up nodes between the graphs, so the naming of nodes must be consistent.


Computes and returns the theoretical and numerical Jacobian. (deprecated)
If x or y is complex, the Jacobian will still be real but the corresponding Jacobian dimension(s) will be twice as large. This is required even if both input and output is complex since TensorFlow graphs are not necessarily holomorphic, and may have gradients not expressible as complex numbers. For example, if x is complex with shape [m] and y is complex with shape [n], each Jacobian J will have shape [m * 2, n * 2] with


Computes the gradient error. (deprecated)
Computes the maximum error for dy/dx between the computed Jacobian and the numerically estimated Jacobian.
This function will modify the tensors passed in as it adds more operations and hence changing the consumers of the operations of the input tensors.
This function adds operations to the current session. To compute the error using a particular device, such as a GPU, use the standard methods for setting a device (e.g. using with sess.graph.device() or setting a device function in the session constructor).


Returns a temporary directory for use during tests.
There is no need to delete the directory after the test.


Support class for stubbing methods out for unit testing.
You want os.path.exists() to always return true during testing.
stubs = StubOutForTesting() stubs.Set(os.path, 'exists', lambda x: 1) ... stubs.CleanUp()
The above changes os.path.exists into a lambda that returns 1. Once the ... part of the code finishes, the CleanUp() looks up the old value of os.path.exists and restores it.
View source
Undoes all SmartSet() & Set() calls, restoring original definitions.
View source
In parent, replace child_name's old definition with new_child.
The parent could be a module when the child is a function at module scope. Or the parent could be a class when a class' method is being replaced. The named child is set to new_child, while the prior definition is saved away for later, when UnsetAll() is called.
This method supports the case where child_name is a staticmethod or a classmethod of parent.
View source
Replace obj.attr_name with new_attr.
This method is smart and works at the module, class, and instance level while preserving proper inheritance. It will not stub out C types however unless that has been explicitly allowed by the type.
This method supports the case where attr_name is a staticmethod or a classmethod of obj.
View source
Reverses SmartSet() calls, restoring things to original definitions.
This method is automatically called when the StubOutForTesting() object is deleted; there is no need to call it explicitly.
It is okay to call SmartUnsetAll() repeatedly, as later calls have no effect if no SmartSet() calls have been made.
View source
Reverses Set() calls, restoring things to their original definitions.
This method is automatically called when the StubOutForTesting() object is deleted; there is no need to call it explicitly.
It is okay to call UnsetAll() repeatedly, as later calls have no effect if no Set() calls have been made.
View source
View source


Creates an absolute test srcdir path given a relative path.


A Reader that outputs the lines of a file delimited by newlines.
Inherits From: ReaderBase
Newlines are stripped from the output. See ReaderBase for supported methods.
Readers are not compatible with eager execution. Instead, please use tf.data to get data into your model.
View source
Returns the number of records this reader has produced.
This is the same as the number of Read executions that have succeeded.
View source
Returns the number of work units this reader has finished processing.
View source
Returns the next record (key, value) pair produced by a reader.
Will dequeue a work unit from queue if necessary (e.g. when the Reader needs to start reading from a new file since it has finished with the previous file).
View source
Returns up to num_records (key, value) pairs produced by a reader.
Will dequeue a work unit from queue if necessary (e.g., when the Reader needs to start reading from a new file since it has finished with the previous file). It may return less than num_records even before the last batch.
View source
Restore a reader to its initial clean state.
View source
Restore a reader to a previously saved state.
Not all Readers support being restored, so this can produce an Unimplemented error.
View source
Produce a string tensor that encodes the state of a reader.
Not all Readers support being serialized, so this can produce an Unimplemented error.


A Reader that outputs the records from a TFRecords file.
Inherits From: ReaderBase
See ReaderBase for supported methods.
Readers are not compatible with eager execution. Instead, please use tf.data to get data into your model.
View source
Returns the number of records this reader has produced.
This is the same as the number of Read executions that have succeeded.
View source
Returns the number of work units this reader has finished processing.
View source
Returns the next record (key, value) pair produced by a reader.
Will dequeue a work unit from queue if necessary (e.g. when the Reader needs to start reading from a new file since it has finished with the previous file).
View source
Returns up to num_records (key, value) pairs produced by a reader.
Will dequeue a work unit from queue if necessary (e.g., when the Reader needs to start reading from a new file since it has finished with the previous file). It may return less than num_records even before the last batch.
View source
Restore a reader to its initial clean state.
View source
Restore a reader to a previously saved state.
Not all Readers support being restored, so this can produce an Unimplemented error.
View source
Produce a string tensor that encodes the state of a reader.
Not all Readers support being serialized, so this can produce an Unimplemented error.


Casts a tensor to type bfloat16. (deprecated)


Casts a tensor to type complex128. (deprecated)


Casts a tensor to type complex64. (deprecated)


Casts a tensor to type float64. (deprecated)


Casts a tensor to type float32. (deprecated)


Casts a tensor to type int32. (deprecated)


Casts a tensor to type int64. (deprecated)


Ops related to Tensor Processing Units.
experimental module: Public API for tf.tpu.experimental namespace.
class CrossShardOptimizer: An optimizer that averages gradients across TPU shards.
class PaddingSpec: Represents the type of padding policies for tpu.replicate.
class XLAOptions: XLA compilation options.
batch_parallel(...): Shards computation along the batch dimension for parallel execution.
bfloat16_scope(...): Scope class for bfloat16 variables so that the model uses custom getter.
core(...): Returns the device name for a core in a replicated TPU computation.
cross_replica_sum(...): Sum the input tensor across replicas according to group_assignment.
initialize_system(...): Initializes a distributed TPU system for use with TensorFlow.
outside_compilation(...): Builds part of a computation outside any current TPU replicate scope.
replicate(...): Builds a graph operator that runs a replicated TPU computation.
rewrite(...): Rewrites computation for execution on a TPU system.
shard(...): Shards computation for parallel execution.
shutdown_system(...): Shuts down a running a distributed TPU system.


Shards computation along the batch dimension for parallel execution.
Convenience wrapper around shard().
inputs must be a list of Tensors or None (equivalent to an empty list). Each input is split into num_shards pieces along the 0-th dimension, and computation is applied to each shard in parallel.
Tensors are broadcast to all shards if they are lexically captured by computation. e.g.,
x = tf.constant(7) def computation(): return x + 3 ... = shard(computation, ...)
The outputs from all shards are concatenated back together along their 0-th dimension.
Inputs and outputs of the computation must be at least rank-1 Tensors.


Scope class for bfloat16 variables so that the model uses custom getter.
This enables variables to be read as bfloat16 type when using get_variable.


Returns the device name for a core in a replicated TPU computation.


An optimizer that averages gradients across TPU shards.
Inherits From: Optimizer
View source
Apply gradients to variables.
Calls tpu_ops.cross_replica_sum() to sum gradient contributions across replicas, and then applies the real optimizer.
View source
Compute gradients of "loss" for the variables in "var_list".
This simply wraps compute_gradients() from the real optimizer. The gradients will be aggregated in apply_gradients() so that user can modify the gradients like clipping with per replica global norm if needed. The global norm with aggregated gradients can be bad as one replica's huge gradients can hurt the gradients from other replicas.
When the CrossShardOptimizer is constructed with reduction == losses.Reduction.MEAN (default), this function scales the loss by 1.0 / num_shards before computing the gradients. Assuming the optimizer uses the default implementation of compute_gradients(), the gradients of the scaled loss are scaled by 1.0 / num_shards compared to the gradients of the original loss. This scaling factor is important because apply_gradients() sums gradients across shards, rather than averaging them. However, the scaling factor must be taken into account when clipping the norm of the gradients or performing other postprocessing.
View source
View source
Return a slot named "name" created for "var" by the Optimizer.
This simply wraps the get_slot() from the actual optimizer.
View source
Return a list of the names of slots created by the Optimizer.
This simply wraps the get_slot_names() from the actual optimizer.
View source
Add operations to minimize loss by updating var_list.
This method simply combines calls compute_gradients() and apply_gradients(). If you want to process the gradient before applying them call compute_gradients() and apply_gradients() explicitly instead of using this function.
When eager execution is enabled, loss should be a Python function that takes no arguments and computes the value to be minimized. Minimization (and gradient computation) is done with respect to the elements of var_list if not None, else with respect to any trainable variables created during the execution of the loss function. gate_gradients, aggregation_method, colocate_gradients_with_ops and grad_loss are ignored when eager execution is enabled.
View source
Forwarding the variables from the underlying optimizer.


Sum the input tensor across replicas according to group_assignment.


Public API for tf.tpu.experimental namespace.
embedding module: Public API for tf.tpu.experimental.embedding namespace.
class AdagradParameters: Optimization parameters for Adagrad with TPU embeddings.
class AdamParameters: Optimization parameters for Adam with TPU embeddings.
class DeviceAssignment: Mapping from logical cores in a computation to the physical TPU topology.
class FtrlParameters: Optimization parameters for Ftrl with TPU embeddings.
class StochasticGradientDescentParameters: Optimization parameters for stochastic gradient descent for TPU embeddings.
class TPUSystemMetadata: Describes some metadata about the TPU system.
class Topology: Describes a set of TPU devices.
embedding_column(...): TPU version of tf.compat.v1.feature_column.embedding_column.
initialize_tpu_system(...): Initialize the TPU devices.
shared_embedding_columns(...): TPU version of tf.compat.v1.feature_column.shared_embedding_columns.
shutdown_tpu_system(...): Shuts down the TPU devices.


Optimization parameters for Adagrad with TPU embeddings.
Pass this to tf.estimator.tpu.experimental.EmbeddingConfigSpec via the optimization_parameters argument to set the optimizer and its parameters. See the documentation for tf.estimator.tpu.experimental.EmbeddingConfigSpec for more details.


Optimization parameters for Adam with TPU embeddings.
Pass this to tf.estimator.tpu.experimental.EmbeddingConfigSpec via the optimization_parameters argument to set the optimizer and its parameters. See the documentation for tf.estimator.tpu.experimental.EmbeddingConfigSpec for more details.


Public API for tf.tpu.experimental.embedding namespace.
class Adagrad: Optimization parameters for Adagrad with TPU embeddings.
class Adam: Optimization parameters for Adam with TPU embeddings.
class FeatureConfig: Configuration data for one embedding feature.
class SGD: Optimization parameters for stochastic gradient descent for TPU embeddings.
class TPUEmbedding: The TPUEmbedding mid level API.
class TableConfig: Configuration data for one embedding table.
serving_embedding_lookup(...): Apply standard lookup ops with tf.tpu.experimental.embedding configs.


TPU version of tf.compat.v1.feature_column.embedding_column.
Note that the interface for tf.tpu.experimental.embedding_column is different from that of tf.compat.v1.feature_column.embedding_column: The following arguments are NOT supported: ckpt_to_load_from, tensor_name_in_ckpt, max_norm and trainable.
Use this function in place of tf.compat.v1.feature_column.embedding_column when you want to use the TPU to accelerate your embedding lookups via TPU embeddings.


Optimization parameters for Ftrl with TPU embeddings.
Pass this to tf.estimator.tpu.experimental.EmbeddingConfigSpec via the optimization_parameters argument to set the optimizer and its parameters. See the documentation for tf.estimator.tpu.experimental.EmbeddingConfigSpec for more details.


TPU version of tf.compat.v1.feature_column.shared_embedding_columns.
Note that the interface for tf.tpu.experimental.shared_embedding_columns is different from that of tf.compat.v1.feature_column.shared_embedding_columns: The following arguments are NOT supported: ckpt_to_load_from, tensor_name_in_ckpt, max_norm and trainable.
Use this function in place of tf.compat.v1.feature_column.shared_embedding_columns` when you want to use the TPU to accelerate your embedding lookups via TPU embeddings.


Optimization parameters for stochastic gradient descent for TPU embeddings.
Pass this to tf.estimator.tpu.experimental.EmbeddingConfigSpec via the optimization_parameters argument to set the optimizer and its parameters. See the documentation for tf.estimator.tpu.experimental.EmbeddingConfigSpec for more details.


Initializes a distributed TPU system for use with TensorFlow.


Builds part of a computation outside any current TPU replicate scope.
tf.tpu.outside_compilation() is used to run ops in computation on CPU instead of running on TPU. For example, users can run ops that are not supported on TPU's (e.g. tf.summary.write()) by explicitly placing those ops on CPU's. Below usage of outside compilation will place ops in computation_with_string_ops on CPU.
Outside compilation should be called inside TPUReplicateContext. That is, tf.tpu.outside_compilation() should be called inside a function that is passed to tpu.split_compile_and_replicate() -- this is implied when outside compilation is invoked inside a function passed to TPUStrategy run(). If invoked outside of TPUReplicateContext, then this simply returns the result of computation, and therefore, would be a no-op. Note that outside compilation is different from tf.distribute.experimental.TPUStrategy.merge_call() as logic in outside compilation is replicated and executed separately for each replica. On the other hand, merge_call() requires a merge_fn to aggregate the inputs from different replicas and is executed only once.
For variables placed in TPU device, which includes variables created inside TPUStrategy scope, outside compilation logic must not include variable read/write. For variables placed on host, which is the case when variables created via TPUEstimator, variable read/write is only allowed if the variable is not accessed by any other ops in the TPU computation. Variable read/write from outside compilation cluster is not visible from TPU computation and vice versa. Therefore, if outside compilation logic contains such host variables read/write ops and if the variables are accessed by TPU computation as well, then this may lead to deadlock.
Internally, tf.tpu.outside_compilation() adds outside compilation attributes to all ops in computation. During later graph pass, these ops with outside compilation attribute is extracted out and replicated into a host-side graph. Inputs to this extract host-side graph is sent from TPU computation graph to host graph via a pair of XlaSendToHost and XlaRecvFromHost ops. Note that using tf.tpu.outside_compilation() may result in tensor transfer between TPU and CPU, leading to non-trivial performance impact.


Represents the type of padding policies for tpu.replicate.


Builds a graph operator that runs a replicated TPU computation.
Example for the basic usage that inputs has static shape:
If the inputs has dynamic shapes and you would like to automatically bucketize the inputs to avoid XLA recompilation. See the advanced example below:
Exceptions include:
1) None output: a NoOp would be returned which control-depends on computation. 2) Single value output: A tuple containing the value would be returned. 3) Operation-only outputs: a NoOp would be returned which control-depends on computation.


Rewrites computation for execution on a TPU system.
computation may return a list of operations and tensors. Tensors must come before operations in the returned list. The return value of rewrite is a list of tensors corresponding to the tensors from the output of computation.
All Operations constructed during computation will be executed when evaluating any of the returned output tensors, not just the ones returned.
1) None output: a NoOp would be returned which control-depends on computation. 2) Single value output: A tuple containing the value would be returned. 3) Operation-only outputs: a NoOp would be returned which control-depends on computation.


Shards computation for parallel execution.
inputs must be a list of Tensors or None (equivalent to an empty list), each of which has a corresponding split axis (from input_shard_axes). Each input is split into num_shards pieces along the corresponding axis, and computation is applied to each shard in parallel.
Tensors are broadcast to all shards if they are lexically captured by computation. e.g.,
x = tf.constant(7) def computation(): return x + 3 ... = shard(computation, ...)
as inputs.
If outputs_from_all_shards is true, the outputs from all shards of computation are concatenated back together along their output_shard_axes. Otherwise, each output is taken from an arbitrary shard.
Inputs and outputs of the computation must be at least rank-1 Tensors.


Shuts down a running a distributed TPU system.


Support for training models.
See the Training guide.
experimental module: Public API for tf.train.experimental namespace.
queue_runner module: Public API for tf.train.queue_runner namespace.
class AdadeltaOptimizer: Optimizer that implements the Adadelta algorithm.
class AdagradDAOptimizer: Adagrad Dual Averaging algorithm for sparse linear models.
class AdagradOptimizer: Optimizer that implements the Adagrad algorithm.
class AdamOptimizer: Optimizer that implements the Adam algorithm.
class BytesList: A ProtocolMessage
class Checkpoint: Groups trackable objects, saving and restoring them.
class CheckpointManager: Manages multiple checkpoints by keeping some and deleting unneeded ones.
class CheckpointOptions: Options for constructing a Checkpoint.
class CheckpointSaverHook: Saves checkpoints every N steps or seconds.
class CheckpointSaverListener: Interface for listeners that take action before or after checkpoint save.
class ChiefSessionCreator: Creates a tf.compat.v1.Session for a chief.
class ClusterDef: A ProtocolMessage
class ClusterSpec: Represents a cluster as a set of "tasks", organized into "jobs".
class Coordinator: A coordinator for threads.
class Example: A ProtocolMessage
class ExponentialMovingAverage: Maintains moving averages of variables by employing an exponential decay.
class Feature: A ProtocolMessage
class FeatureList: A ProtocolMessage
class FeatureLists: A ProtocolMessage
class Features: A ProtocolMessage
class FeedFnHook: Runs feed_fn and sets the feed_dict accordingly.
class FinalOpsHook: A hook which evaluates Tensors at the end of a session.
class FloatList: A ProtocolMessage
class FtrlOptimizer: Optimizer that implements the FTRL algorithm.
class GlobalStepWaiterHook: Delays execution until global step reaches wait_until_step.
class GradientDescentOptimizer: Optimizer that implements the gradient descent algorithm.
class Int64List: A ProtocolMessage
class JobDef: A ProtocolMessage
class LoggingTensorHook: Prints the given tensors every N local steps, every N seconds, or at end.
class LooperThread: A thread that runs code repeatedly, optionally on a timer.
class MomentumOptimizer: Optimizer that implements the Momentum algorithm.
class MonitoredSession: Session-like object that handles initialization, recovery and hooks.
class NanLossDuringTrainingError: Unspecified run-time error.
class NanTensorHook: Monitors the loss tensor and stops training if loss is NaN.
class Optimizer: Base class for optimizers.
class ProfilerHook: Captures CPU/GPU profiling information every N steps or seconds.
class ProximalAdagradOptimizer: Optimizer that implements the Proximal Adagrad algorithm.
class ProximalGradientDescentOptimizer: Optimizer that implements the proximal gradient descent algorithm.
class QueueRunner: Holds a list of enqueue operations for a queue, each to be run in a thread.
class RMSPropOptimizer: Optimizer that implements the RMSProp algorithm (Tielemans et al.
class Saver: Saves and restores variables.
class SaverDef: A ProtocolMessage
class Scaffold: Structure to create or gather pieces commonly needed to train a model.
class SecondOrStepTimer: Timer that triggers at most once every N seconds or once every N steps.
class SequenceExample: A ProtocolMessage
class Server: An in-process TensorFlow server, for use in distributed training.
class ServerDef: A ProtocolMessage
class SessionCreator: A factory for tf.Session.
class SessionManager: Training helper that restores from checkpoint and creates session.
class SessionRunArgs: Represents arguments to be added to a Session.run() call.
class SessionRunContext: Provides information about the session.run() call being made.
class SessionRunHook: Hook to extend calls to MonitoredSession.run().
class SessionRunValues: Contains the results of Session.run().
class SingularMonitoredSession: Session-like object that handles initialization, restoring, and hooks.
class StepCounterHook: Hook that counts steps per second.
class StopAtStepHook: Hook that requests stop at a specified step.
class SummarySaverHook: Saves summaries every N steps.
class Supervisor: A training helper that checkpoints models and computes summaries.
class SyncReplicasOptimizer: Class to synchronize, aggregate gradients and pass them to the optimizer.
class VocabInfo: Vocabulary information for warm-starting.
class WorkerSessionCreator: Creates a tf.compat.v1.Session for a worker.
MonitoredTrainingSession(...): Creates a MonitoredSession for training.
NewCheckpointReader(...): A function that returns a CheckPointReader.
add_queue_runner(...): Adds a QueueRunner to a collection in the graph. (deprecated)
assert_global_step(...): Asserts global_step_tensor is a scalar int Variable or Tensor.
basic_train_loop(...): Basic loop to train a model.
batch(...): Creates batches of tensors in tensors. (deprecated)
batch_join(...): Runs a list of tensors to fill a queue to create batches of examples. (deprecated)
checkpoint_exists(...): Checks whether a V1 or V2 checkpoint exists with the specified prefix. (deprecated)
checkpoints_iterator(...): Continuously yield new checkpoint files as they appear.
cosine_decay(...): Applies cosine decay to the learning rate.
cosine_decay_restarts(...): Applies cosine decay with restarts to the learning rate.
create_global_step(...): Create global step tensor in graph.
do_quantize_training_on_graphdef(...): A general quantization scheme is being developed in tf.contrib.quantize. (deprecated)
exponential_decay(...): Applies exponential decay to the learning rate.
export_meta_graph(...): Returns MetaGraphDef proto.
generate_checkpoint_state_proto(...): Generates a checkpoint state proto.
get_checkpoint_mtimes(...): Returns the mtimes (modification timestamps) of the checkpoints. (deprecated)
get_checkpoint_state(...): Returns CheckpointState proto from the "checkpoint" file.
get_global_step(...): Get the global step tensor.
get_or_create_global_step(...): Returns and create (if necessary) the global step tensor.
global_step(...): Small helper to get the global step.
import_meta_graph(...): Recreates a Graph saved in a MetaGraphDef proto.
init_from_checkpoint(...): Replaces tf.Variable initializers so they load from a checkpoint file.
input_producer(...): Output the rows of input_tensor to a queue for an input pipeline. (deprecated)
inverse_time_decay(...): Applies inverse time decay to the initial learning rate.
latest_checkpoint(...): Finds the filename of latest saved checkpoint file.
limit_epochs(...): Returns tensor num_epochs times and then raises an OutOfRange error. (deprecated)
linear_cosine_decay(...): Applies linear cosine decay to the learning rate.
list_variables(...): Lists the checkpoint keys and shapes of variables in a checkpoint.
load_checkpoint(...): Returns CheckpointReader for checkpoint found in ckpt_dir_or_file.
load_variable(...): Returns the tensor value of the given variable in the checkpoint.
match_filenames_once(...): Save the list of files matching pattern, so it is only computed once.
maybe_batch(...): Conditionally creates batches of tensors based on keep_input. (deprecated)
maybe_batch_join(...): Runs a list of tensors to conditionally fill a queue to create batches. (deprecated)
maybe_shuffle_batch(...): Creates batches by randomly shuffling conditionally-enqueued tensors. (deprecated)
maybe_shuffle_batch_join(...): Create batches by randomly shuffling conditionally-enqueued tensors. (deprecated)
natural_exp_decay(...): Applies natural exponential decay to the initial learning rate.
noisy_linear_cosine_decay(...): Applies noisy linear cosine decay to the learning rate.
piecewise_constant(...): Piecewise constant from boundaries and interval values.
piecewise_constant_decay(...): Piecewise constant from boundaries and interval values.
polynomial_decay(...): Applies a polynomial decay to the learning rate.
range_input_producer(...): Produces the integers from 0 to limit-1 in a queue. (deprecated)
remove_checkpoint(...): Removes a checkpoint given by checkpoint_prefix. (deprecated)
replica_device_setter(...): Return a device function to use when building a Graph for replicas.
sdca_fprint(...): Computes fingerprints of the input strings.
sdca_optimizer(...): Distributed version of Stochastic Dual Coordinate Ascent (SDCA) optimizer for
sdca_shrink_l1(...): Applies L1 regularization shrink step on the parameters.
shuffle_batch(...): Creates batches by randomly shuffling tensors. (deprecated)
shuffle_batch_join(...): Create batches by randomly shuffling tensors. (deprecated)
slice_input_producer(...): Produces a slice of each Tensor in tensor_list. (deprecated)
start_queue_runners(...): Starts all queue runners collected in the graph. (deprecated)
string_input_producer(...): Output strings (e.g. filenames) to a queue for an input pipeline. (deprecated)
summary_iterator(...): Returns a iterator for reading Event protocol buffers from an event file.
update_checkpoint_state(...): Updates the content of the 'checkpoint' file. (deprecated)
warm_start(...): Warm-starts a model using the given settings.
write_graph(...): Writes a graph proto to a file.