CategoryEncoding layer.
Inherits From: CategoryEncoding, PreprocessingLayer, Layer, Module
This layer provides options for condensing input data into denser representations. It accepts either integer values or strings as inputs, allows users to map those inputs into a contiguous integer space, and outputs either those integer values (one sample = 1D tensor of integer token indices) or a dense representation (one sample = 1D tensor of float values representing data about the sample's tokens).
If desired, the user can call this layer's adapt() method on a dataset. When this layer is adapted, it will analyze the dataset, determine the frequency of individual integer or string values, and create a 'vocabulary' from them. This vocabulary can have unlimited size or be capped, depending on the configuration options for this layer; if there are more unique values in the input than the maximum vocabulary size, the most frequent terms will be used to create the vocabulary.
View source
Fits the state of the preprocessing layer to the dataset.
Overrides the default adapt method to apply relevant preprocessing to the inputs before passing to the combiner.
View source
View source


Maps integers from a vocabulary to integer indices.
Inherits From: IntegerLookup, PreprocessingLayer, Layer, Module
View source
Fits the state of the preprocessing layer to the dataset.
Overrides the default adapt method to apply relevant preprocessing to the inputs before passing to the combiner.
View source
View source
Sets vocabulary data for this layer with inverse=False.
This method sets the vocabulary for this layer directly, instead of analyzing a dataset through 'adapt'. It should be used whenever the vocab information is already known. If vocabulary data is already present in the layer, this method will either replace it
View source


Feature-wise normalization of the data.
Inherits From: Normalization, PreprocessingLayer, Layer, Module
This layer will coerce its inputs into a distribution centered around 0 with standard deviation 1. It accomplishes this by precomputing the mean and variance of the data, and calling (input-mean)/sqrt(var) at runtime.
What happens in adapt: Compute mean and variance of the data and store them as the layer's weights. adapt should be called before fit, evaluate, or predict.
Calculate the mean and variance by analyzing the dataset in adapt.
Pass the mean and variance directly.
View source
Fits the state of the preprocessing layer to the data being passed.


Maps strings from a vocabulary to integer indices.
Inherits From: StringLookup, PreprocessingLayer, Layer, Module
View source
Fits the state of the preprocessing layer to the dataset.
Overrides the default adapt method to apply relevant preprocessing to the inputs before passing to the combiner.
View source
View source
Sets vocabulary data for this layer with inverse=False.
This method sets the vocabulary for this layer directly, instead of analyzing a dataset through 'adapt'. It should be used whenever the vocab information is already known. If vocabulary data is already present in the layer, this method will either replace it
View source


Text vectorization layer.
Inherits From: TextVectorization, PreprocessingLayer, Layer, Module
This layer has basic options for managing text in a Keras model. It transforms a batch of strings (one sample = one string) into either a list of token indices (one sample = 1D tensor of integer token indices) or a dense representation (one sample = 1D tensor of float values representing data about the sample's tokens).
The processing of each sample contains the following steps:
1) standardize each sample (usually lowercasing + punctuation stripping) 2) split each sample into substrings (usually words) 3) recombine substrings into tokens (usually ngrams) 4) index tokens (associate a unique int value with each token) 5) transform each sample using this index, either into a vector of ints or a dense float vector.
View source
Fits the state of the preprocessing layer to the dataset.
Overrides the default adapt method to apply relevant preprocessing to the inputs before passing to the combiner.
View source
View source
Sets vocabulary (and optionally document frequency) data for this layer.
This method sets the vocabulary and DF data for this layer directly, instead of analyzing a dataset through 'adapt'. It should be used whenever the vocab (and optionally document frequency) information is already known. If vocabulary data is already present in the layer, this method will replace it.


Gated Recurrent Unit - Cho et al. 2014.
Inherits From: RNN, Layer, Module
There are two variants. The default one is based on 1406.1078v3 and has reset gate applied to hidden state before matrix multiplication. The other one is based on original 1406.1078v1 and has the order reversed.
The second variant is compatible with CuDNNGRU (GPU-only) and allows inference on CPU. Thus it has separate biases for kernel and recurrent_kernel. Use 'reset_after'=True and recurrent_activation='sigmoid'.
View source
Reset the recorded states for the stateful RNN layer.
Can only be used when RNN layer is constructed with stateful = True. Args: states: Numpy arrays that contains the value for the initial state, which will be feed to cell at the first time step. When the value is None, zero filled numpy array will be created based on the cell state size.


Cell class for the GRU layer.
Inherits From: Layer, Module
View source
Get the dropout mask for RNN cell's input.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
View source
View source
Get the recurrent dropout mask for RNN cell.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
View source
Reset the cached dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.
View source
Reset the cached recurrent dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.


Long Short-Term Memory layer - Hochreiter 1997.
Inherits From: RNN, Layer, Module
Note that this cell is not optimized for performance on GPU. Please use tf.compat.v1.keras.layers.CuDNNLSTM for better performance on GPU.
View source
Reset the recorded states for the stateful RNN layer.
Can only be used when RNN layer is constructed with stateful = True. Args: states: Numpy arrays that contains the value for the initial state, which will be feed to cell at the first time step. When the value is None, zero filled numpy array will be created based on the cell state size.


Cell class for the LSTM layer.
Inherits From: Layer, Module
View source
Get the dropout mask for RNN cell's input.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
View source
View source
Get the recurrent dropout mask for RNN cell.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
View source
Reset the cached dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.
View source
Reset the cached recurrent dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.


Built-in loss functions.
class BinaryCrossentropy: Computes the cross-entropy loss between true labels and predicted labels.
class CategoricalCrossentropy: Computes the crossentropy loss between the labels and predictions.
class CategoricalHinge: Computes the categorical hinge loss between y_true and y_pred.
class CosineSimilarity: Computes the cosine similarity between labels and predictions.
class Hinge: Computes the hinge loss between y_true and y_pred.
class Huber: Computes the Huber loss between y_true and y_pred.
class KLDivergence: Computes Kullback-Leibler divergence loss between y_true and y_pred.
class LogCosh: Computes the logarithm of the hyperbolic cosine of the prediction error.
class Loss: Loss base class.
class MeanAbsoluteError: Computes the mean of absolute difference between labels and predictions.
class MeanAbsolutePercentageError: Computes the mean absolute percentage error between y_true and y_pred.
class MeanSquaredError: Computes the mean of squares of errors between labels and predictions.
class MeanSquaredLogarithmicError: Computes the mean squared logarithmic error between y_true and y_pred.
class Poisson: Computes the Poisson loss between y_true and y_pred.
class SparseCategoricalCrossentropy: Computes the crossentropy loss between the labels and predictions.
class SquaredHinge: Computes the squared hinge loss between y_true and y_pred.
KLD(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
MAE(...): Computes the mean absolute error between labels and predictions.
MAPE(...): Computes the mean absolute percentage error between y_true and y_pred.
MSE(...): Computes the mean squared error between labels and predictions.
MSLE(...): Computes the mean squared logarithmic error between y_true and y_pred.
binary_crossentropy(...): Computes the binary crossentropy loss.
categorical_crossentropy(...): Computes the categorical crossentropy loss.
categorical_hinge(...): Computes the categorical hinge loss between y_true and y_pred.
cosine(...): Computes the cosine similarity between labels and predictions.
cosine_proximity(...): Computes the cosine similarity between labels and predictions.
cosine_similarity(...): Computes the cosine similarity between labels and predictions.
deserialize(...): Deserializes a serialized loss class/function instance.
get(...): Retrieves a Keras loss as a function/Loss class instance.
hinge(...): Computes the hinge loss between y_true and y_pred.
kl_divergence(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
kld(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
kullback_leibler_divergence(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
log_cosh(...): Logarithm of the hyperbolic cosine of the prediction error.
logcosh(...): Logarithm of the hyperbolic cosine of the prediction error.
mae(...): Computes the mean absolute error between labels and predictions.
mape(...): Computes the mean absolute percentage error between y_true and y_pred.
mean_absolute_error(...): Computes the mean absolute error between labels and predictions.
mean_absolute_percentage_error(...): Computes the mean absolute percentage error between y_true and y_pred.
mean_squared_error(...): Computes the mean squared error between labels and predictions.
mean_squared_logarithmic_error(...): Computes the mean squared logarithmic error between y_true and y_pred.
mse(...): Computes the mean squared error between labels and predictions.
msle(...): Computes the mean squared logarithmic error between y_true and y_pred.
poisson(...): Computes the Poisson loss between y_true and y_pred.
serialize(...): Serializes loss function or Loss instance.
sparse_categorical_crossentropy(...): Computes the sparse categorical crossentropy loss.
squared_hinge(...): Computes the squared hinge loss between y_true and y_pred.


Built-in metrics.
class AUC: Computes the approximate AUC (Area under the curve) via a Riemann sum.
class Accuracy: Calculates how often predictions equal labels.
class BinaryAccuracy: Calculates how often predictions match binary labels.
class BinaryCrossentropy: Computes the crossentropy metric between the labels and predictions.
class CategoricalAccuracy: Calculates how often predictions matches one-hot labels.
class CategoricalCrossentropy: Computes the crossentropy metric between the labels and predictions.
class CategoricalHinge: Computes the categorical hinge metric between y_true and y_pred.
class CosineSimilarity: Computes the cosine similarity between the labels and predictions.
class FalseNegatives: Calculates the number of false negatives.
class FalsePositives: Calculates the number of false positives.
class Hinge: Computes the hinge metric between y_true and y_pred.
class KLDivergence: Computes Kullback-Leibler divergence metric between y_true and y_pred.
class LogCoshError: Computes the logarithm of the hyperbolic cosine of the prediction error.
class Mean: Computes the (weighted) mean of the given values.
class MeanAbsoluteError: Computes the mean absolute error between the labels and predictions.
class MeanAbsolutePercentageError: Computes the mean absolute percentage error between y_true and y_pred.
class MeanIoU: Computes the mean Intersection-Over-Union metric.
class MeanRelativeError: Computes the mean relative error by normalizing with the given values.
class MeanSquaredError: Computes the mean squared error between y_true and y_pred.
class MeanSquaredLogarithmicError: Computes the mean squared logarithmic error between y_true and y_pred.
class MeanTensor: Computes the element-wise (weighted) mean of the given tensors.
class Metric: Encapsulates metric logic and state.
class Poisson: Computes the Poisson metric between y_true and y_pred.
class Precision: Computes the precision of the predictions with respect to the labels.
class PrecisionAtRecall: Computes best precision where recall is >= specified value.
class Recall: Computes the recall of the predictions with respect to the labels.
class RecallAtPrecision: Computes best recall where precision is >= specified value.
class RootMeanSquaredError: Computes root mean squared error metric between y_true and y_pred.
class SensitivityAtSpecificity: Computes best sensitivity where specificity is >= specified value.
class SparseCategoricalAccuracy: Calculates how often predictions matches integer labels.
class SparseCategoricalCrossentropy: Computes the crossentropy metric between the labels and predictions.
class SparseTopKCategoricalAccuracy: Computes how often integer targets are in the top K predictions.
class SpecificityAtSensitivity: Computes best specificity where sensitivity is >= specified value.
class SquaredHinge: Computes the squared hinge metric between y_true and y_pred.
class Sum: Computes the (weighted) sum of the given values.
class TopKCategoricalAccuracy: Computes how often targets are in the top K predictions.
class TrueNegatives: Calculates the number of true negatives.
class TruePositives: Calculates the number of true positives.
KLD(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
MAE(...): Computes the mean absolute error between labels and predictions.
MAPE(...): Computes the mean absolute percentage error between y_true and y_pred.
MSE(...): Computes the mean squared error between labels and predictions.
MSLE(...): Computes the mean squared logarithmic error between y_true and y_pred.
binary_accuracy(...): Calculates how often predictions matches binary labels.
binary_crossentropy(...): Computes the binary crossentropy loss.
categorical_accuracy(...): Calculates how often predictions matches one-hot labels.
categorical_crossentropy(...): Computes the categorical crossentropy loss.
cosine(...): Computes the cosine similarity between labels and predictions.
cosine_proximity(...): Computes the cosine similarity between labels and predictions.
deserialize(...): Deserializes a serialized metric class/function instance.
get(...): Retrieves a Keras metric as a function/Metric class instance.
hinge(...): Computes the hinge loss between y_true and y_pred.
kl_divergence(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
kld(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
kullback_leibler_divergence(...): Computes Kullback-Leibler divergence loss between y_true and y_pred.
log_cosh(...): Logarithm of the hyperbolic cosine of the prediction error.
logcosh(...): Logarithm of the hyperbolic cosine of the prediction error.
mae(...): Computes the mean absolute error between labels and predictions.
mape(...): Computes the mean absolute percentage error between y_true and y_pred.
mean_absolute_error(...): Computes the mean absolute error between labels and predictions.
mean_absolute_percentage_error(...): Computes the mean absolute percentage error between y_true and y_pred.
mean_squared_error(...): Computes the mean squared error between labels and predictions.
mean_squared_logarithmic_error(...): Computes the mean squared logarithmic error between y_true and y_pred.
mse(...): Computes the mean squared error between labels and predictions.
msle(...): Computes the mean squared logarithmic error between y_true and y_pred.
poisson(...): Computes the Poisson loss between y_true and y_pred.
serialize(...): Serializes metric function or Metric instance.
sparse_categorical_accuracy(...): Calculates how often predictions matches integer labels.
sparse_categorical_crossentropy(...): Computes the sparse categorical crossentropy loss.
sparse_top_k_categorical_accuracy(...): Computes how often integer targets are in the top K predictions.
squared_hinge(...): Computes the squared hinge loss between y_true and y_pred.
top_k_categorical_accuracy(...): Computes how often targets are in the top K predictions.


Keras mixed precision API.
See the mixed precision guide to learn how to use the API.
experimental module: Public API for tf.keras.mixed_precision.experimental namespace.
class LossScaleOptimizer: An optimizer that applies loss scaling to prevent numeric underflow.


Public API for tf.keras.mixed_precision.experimental namespace.
class LossScaleOptimizer: An deprecated optimizer that applies loss scaling.


Code for model cloning, plus model-related API entries.
class Model: Model groups layers into an object with training and inference features.
class Sequential: Sequential groups a linear stack of layers into a tf.keras.Model.
clone_model(...): Clone any Model instance.
load_model(...): Loads a model saved via model.save().
model_from_config(...): Instantiates a Keras model from its config.
model_from_json(...): Parses a JSON model configuration string and returns a model instance.
model_from_yaml(...): Parses a yaml model configuration file and returns a model instance.
save_model(...): Saves a model as a TensorFlow SavedModel or HDF5 file.


Built-in optimizer classes.
For more examples see the base class tf.keras.optimizers.Optimizer.
schedules module: Public API for tf.keras.optimizers.schedules namespace.
class Adadelta: Optimizer that implements the Adadelta algorithm.
class Adagrad: Optimizer that implements the Adagrad algorithm.
class Adam: Optimizer that implements the Adam algorithm.
class Adamax: Optimizer that implements the Adamax algorithm.
class Ftrl: Optimizer that implements the FTRL algorithm.
class Nadam: Optimizer that implements the NAdam algorithm.
class Optimizer: Base class for Keras optimizers.
class RMSprop: Optimizer that implements the RMSprop algorithm.
class SGD: Gradient descent (with momentum) optimizer.
deserialize(...): Inverse of the serialize function.
get(...): Retrieves a Keras Optimizer instance.
serialize(...)


Public API for tf.keras.optimizers.schedules namespace.
class ExponentialDecay: A LearningRateSchedule that uses an exponential decay schedule.
class InverseTimeDecay: A LearningRateSchedule that uses an inverse time decay schedule.
class LearningRateSchedule: A serializable learning rate decay schedule.
class PiecewiseConstantDecay: A LearningRateSchedule that uses a piecewise constant decay schedule.
class PolynomialDecay: A LearningRateSchedule that uses a polynomial decay schedule.
deserialize(...)
serialize(...)


Keras data preprocessing utils.
image module: Set of tools for real-time data augmentation on image data.
sequence module: Utilities for preprocessing sequence data.
text module: Utilities for text input preprocessing.


Set of tools for real-time data augmentation on image data.
class DirectoryIterator: Iterator capable of reading images from a directory on disk.
class ImageDataGenerator: Generate batches of tensor image data with real-time data augmentation.
class Iterator: Base class for image data iterators.
class NumpyArrayIterator: Iterator yielding data from a Numpy array.
apply_affine_transform(...): Applies an affine transformation specified by the parameters given.
apply_brightness_shift(...): Performs a brightness shift.
apply_channel_shift(...): Performs a channel shift.
array_to_img(...): Converts a 3D Numpy array to a PIL Image instance.
img_to_array(...): Converts a PIL Image instance to a Numpy array.
load_img(...): Loads an image into PIL format.
random_brightness(...): Performs a random brightness shift.
random_channel_shift(...): Performs a random channel shift.
random_rotation(...): Performs a random rotation of a Numpy image tensor.
random_shear(...): Performs a random spatial shear of a Numpy image tensor.
random_shift(...): Performs a random spatial shift of a Numpy image tensor.
random_zoom(...): Performs a random spatial zoom of a Numpy image tensor.
save_img(...): Saves an image stored as a Numpy array to a path or file object.


Utilities for preprocessing sequence data.
class TimeseriesGenerator: Utility class for generating batches of temporal data.
make_sampling_table(...): Generates a word rank-based probabilistic sampling table.
pad_sequences(...): Pads sequences to the same length.
skipgrams(...): Generates skipgram word pairs.


Utilities for text input preprocessing.
class Tokenizer: Text tokenization utility class.
hashing_trick(...): Converts a text to a sequence of indexes in a fixed-size hashing space.
one_hot(...): One-hot encodes a text into a list of word indexes of size n.
text_to_word_sequence(...): Converts a text to a sequence of words (or tokens).
tokenizer_from_json(...): Parses a JSON tokenizer configuration file and returns a


Built-in regularizers.
class L1: A regularizer that applies a L1 regularization penalty.
class L1L2: A regularizer that applies both L1 and L2 regularization penalties.
class L2: A regularizer that applies a L2 regularization penalty.
class Regularizer: Regularizer base class.
class l1: A regularizer that applies a L1 regularization penalty.
class l2: A regularizer that applies a L2 regularization penalty.
deserialize(...)
get(...): Retrieve a regularizer instance from a config or identifier.
l1_l2(...): Create a regularizer that applies both L1 and L2 penalties.
serialize(...)


Public API for tf.keras.utils namespace.
class CustomObjectScope: Exposes custom classes/functions to Keras deserialization internals.
class GeneratorEnqueuer: Builds a queue out of a data generator.
class OrderedEnqueuer: Builds a Enqueuer from a Sequence.
class Progbar: Displays a progress bar.
class Sequence: Base object for fitting to a sequence of data, such as a dataset.
class SequenceEnqueuer: Base class to enqueue inputs.
class custom_object_scope: Exposes custom classes/functions to Keras deserialization internals.
deserialize_keras_object(...): Turns the serialized form of a Keras object back into an actual object.
get_custom_objects(...): Retrieves a live reference to the global dictionary of custom objects.
get_file(...): Downloads a file from a URL if it not already in the cache.
get_registered_name(...): Returns the name registered to an object within the Keras framework.
get_registered_object(...): Returns the class associated with name if it is registered with Keras.
get_source_inputs(...): Returns the list of input tensors necessary to compute tensor.
model_to_dot(...): Convert a Keras model to dot format.
normalize(...): Normalizes a Numpy array.
plot_model(...): Converts a Keras model to dot format and save to a file.
register_keras_serializable(...): Registers an object with the Keras serialization framework.
serialize_keras_object(...): Serialize a Keras object into a JSON-compatible representation.
to_categorical(...): Converts a class vector (integers) to binary class matrix.


Public API for tf.keras.wrappers namespace.
scikit_learn module: Wrapper for using the Scikit-Learn API with Keras models.


Wrapper for using the Scikit-Learn API with Keras models.
class KerasClassifier: Implementation of the scikit-learn classifier API for Keras.
class KerasRegressor: Implementation of the scikit-learn regressor API for Keras.


Public API for tf.layers namespace.
experimental module: Public API for tf.layers.experimental namespace.
class AveragePooling1D: Average Pooling layer for 1D inputs.
class AveragePooling2D: Average pooling layer for 2D inputs (e.g. images).
class AveragePooling3D: Average pooling layer for 3D inputs (e.g. volumes).
class BatchNormalization: Batch Normalization layer from (Ioffe et al., 2015).
class Conv1D: 1D convolution layer (e.g. temporal convolution).
class Conv2D: 2D convolution layer (e.g. spatial convolution over images).
class Conv2DTranspose: Transposed 2D convolution layer (sometimes called 2D Deconvolution).
class Conv3D: 3D convolution layer (e.g. spatial convolution over volumes).
class Conv3DTranspose: Transposed 3D convolution layer (sometimes called 3D Deconvolution).
class Dense: Densely-connected layer class.
class Dropout: Applies Dropout to the input.
class Flatten: Flattens an input tensor while preserving the batch axis (axis 0).
class InputSpec: Specifies the rank, dtype and shape of every input to a layer.
class Layer: Base layer class.
class MaxPooling1D: Max Pooling layer for 1D inputs.
class MaxPooling2D: Max pooling layer for 2D inputs (e.g. images).
class MaxPooling3D: Max pooling layer for 3D inputs (e.g. volumes).
class SeparableConv1D: Depthwise separable 1D convolution.
class SeparableConv2D: Depthwise separable 2D convolution.
average_pooling1d(...): Average Pooling layer for 1D inputs.
average_pooling2d(...): Average pooling layer for 2D inputs (e.g. images).
average_pooling3d(...): Average pooling layer for 3D inputs (e.g. volumes).
batch_normalization(...): Functional interface for the batch normalization layer from_config(Ioffe et al., 2015).
conv1d(...): Functional interface for 1D convolution layer (e.g. temporal convolution).
conv2d(...): Functional interface for the 2D convolution layer.
conv2d_transpose(...): Functional interface for transposed 2D convolution layer.
conv3d(...): Functional interface for the 3D convolution layer.
conv3d_transpose(...): Functional interface for transposed 3D convolution layer.
dense(...): Functional interface for the densely-connected layer.
dropout(...): Applies Dropout to the input.
flatten(...): Flattens an input tensor while preserving the batch axis (axis 0).
max_pooling1d(...): Max Pooling layer for 1D inputs.
max_pooling2d(...): Max pooling layer for 2D inputs (e.g. images).
max_pooling3d(...): Max pooling layer for 3D inputs (e.g.
separable_conv1d(...): Functional interface for the depthwise separable 1D convolution layer.
separable_conv2d(...): Functional interface for the depthwise separable 2D convolution layer.


Average Pooling layer for 1D inputs.
Inherits From: AveragePooling1D, Layer, Layer, Module


Average pooling layer for 2D inputs (e.g. images).
Inherits From: AveragePooling2D, Layer, Layer, Module


Average pooling layer for 3D inputs (e.g. volumes).
Inherits From: AveragePooling3D, Layer, Layer, Module


Average pooling layer for 2D inputs (e.g. images).


Average pooling layer for 3D inputs (e.g. volumes).


Batch Normalization layer from (Ioffe et al., 2015).
Inherits From: BatchNormalization, Layer, Layer, Module
Keras APIs handle BatchNormalization updates to the moving_mean and moving_variance as part of their fit() and evaluate() loops. However, if a custom training loop is used with an instance of Model, these updates need to be explicitly included. Here's a simple example of how it can be done:
Batch Normalization - Accelerating Deep Network Training by Reducing Internal Covariate Shift: Ioffe et al., 2015 (pdf) Batch Renormalization - Towards Reducing Minibatch Dependence in Batch-Normalized Models: Ioffe, 2017 (pdf)


Functional interface for the batch normalization layer from_config(Ioffe et al., 2015).
Batch Normalization - Accelerating Deep Network Training by Reducing Internal Covariate Shift: Ioffe et al., 2015 (pdf) Batch Renormalization - Towards Reducing Minibatch Dependence in Batch-Normalized Models: Ioffe, 2017 (pdf)


1D convolution layer (e.g. temporal convolution).
Inherits From: Conv1D, Layer, Layer, Module
This layer creates a convolution kernel that is convolved (actually cross-correlated) with the layer input to produce a tensor of outputs. If use_bias is True (and a bias_initializer is provided), a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.


2D convolution layer (e.g. spatial convolution over images).
Inherits From: Conv2D, Layer, Layer, Module
This layer creates a convolution kernel that is convolved (actually cross-correlated) with the layer input to produce a tensor of outputs. If use_bias is True (and a bias_initializer is provided), a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.


Transposed 2D convolution layer (sometimes called 2D Deconvolution).
Inherits From: Conv2DTranspose, Conv2D, Layer, Layer, Module
The need for transposed convolutions generally arises from the desire to use a transformation going in the opposite direction of a normal convolution, i.e., from something that has the shape of the output of some convolution to something that has the shape of its input while maintaining a connectivity pattern that is compatible with said convolution.


Functional interface for transposed 2D convolution layer.
The need for transposed convolutions generally arises from the desire to use a transformation going in the opposite direction of a normal convolution, i.e., from something that has the shape of the output of some convolution to something that has the shape of its input while maintaining a connectivity pattern that is compatible with said convolution.


3D convolution layer (e.g. spatial convolution over volumes).
Inherits From: Conv3D, Layer, Layer, Module
This layer creates a convolution kernel that is convolved (actually cross-correlated) with the layer input to produce a tensor of outputs. If use_bias is True (and a bias_initializer is provided), a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.


Transposed 3D convolution layer (sometimes called 3D Deconvolution).
Inherits From: Conv3DTranspose, Conv3D, Layer, Layer, Module


Functional interface for transposed 3D convolution layer.


Densely-connected layer class.
Inherits From: Dense, Layer, Layer, Module
This layer implements the operation: outputs = activation(inputs * kernel + bias) Where activation is the activation function passed as the activation argument (if not None), kernel is a weights matrix created by the layer, and bias is a bias vector created by the layer (only if use_bias is True).


Applies Dropout to the input.
Inherits From: Dropout, Layer, Layer, Module
Dropout consists in randomly setting a fraction rate of input units to 0 at each update during training time, which helps prevent overfitting. The units that are kept are scaled by 1 / (1 - rate), so that their sum is unchanged at training time and inference time.


Public API for tf.layers.experimental namespace.
keras_style_scope(...): Use Keras-style variable management.
set_keras_style(...): Use Keras-style variable management.


Use Keras-style variable management.
All tf.layers and tf RNN cells created in this scope use Keras-style variable management. Creating such layers with a scope= argument is disallowed, and reuse=True is disallowed.
The purpose of this scope is to allow users of existing layers to slowly transition to a Keras layers API without breaking existing functionality.
One example of this is when using TensorFlow's RNN classes with Keras Models or Networks. Because Keras models do not properly set variable scopes, users of RNNs may either accidentally share scopes between two different models, or get errors about variables that already exist.
The solution is to wrap the model construction and execution in a keras-style scope:


Use Keras-style variable management.
All tf.layers and tf RNN cells created after keras style ha been enabled use Keras-style variable management. Creating such layers with a scope= argument is disallowed, and reuse=True is disallowed.
The purpose of this function is to allow users of existing layers to slowly transition to Keras layers API without breaking existing functionality.
For more details, see the documentation for keras_style_scope.
Note, once keras style has been set, it is set globally for the entire program and cannot be unset.


Flattens an input tensor while preserving the batch axis (axis 0).
Inherits From: Flatten, Layer, Layer, Module


Base layer class.
Inherits From: Layer, Module
It is considered legacy, and we recommend the use of tf.keras.layers.Layer instead.
Read-only properties: name: The name of the layer (string). dtype: Default dtype of the layer's weights (default of None means use the type of the first input). trainable_variables: List of trainable variables. non_trainable_variables: List of non-trainable variables. variables: List of all variables of this layer, trainable and non-trainable. updates: List of update ops of this layer. losses: List of losses added by this layer. trainable_weights: List of variables to be included in backprop. non_trainable_weights: List of variables that should not be included in backprop. weights: The concatenation of the lists trainable_weights and non_trainable_weights (in this order).


Max Pooling layer for 1D inputs.
Inherits From: MaxPool1D, Layer, Layer, Module


Max pooling layer for 2D inputs (e.g. images).
Inherits From: MaxPool2D, Layer, Layer, Module


Max pooling layer for 3D inputs (e.g. volumes).
Inherits From: MaxPool3D, Layer, Layer, Module


Max pooling layer for 2D inputs (e.g. images).


Max pooling layer for 3D inputs (e.g.
volumes).


Depthwise separable 1D convolution.
Inherits From: SeparableConv1D, Layer, Layer, Module
This layer performs a depthwise convolution that acts separately on channels, followed by a pointwise convolution that mixes channels. If use_bias is True and a bias initializer is provided, it adds a bias vector to the output. It then optionally applies an activation function to produce the final output.


Depthwise separable 2D convolution.
Inherits From: SeparableConv2D, Layer, Layer, Module
This layer performs a depthwise convolution that acts separately on channels, followed by a pointwise convolution that mixes channels. If use_bias is True and a bias initializer is provided, it adds a bias vector to the output. It then optionally applies an activation function to produce the final output.


Functional interface for the depthwise separable 1D convolution layer.
This layer performs a depthwise convolution that acts separately on channels, followed by a pointwise convolution that mixes channels. If use_bias is True and a bias initializer is provided, it adds a bias vector to the output. It then optionally applies an activation function to produce the final output.


Functional interface for the depthwise separable 2D convolution layer.
This layer performs a depthwise convolution that acts separately on channels, followed by a pointwise convolution that mixes channels. If use_bias is True and a bias initializer is provided, it adds a bias vector to the output. It then optionally applies an activation function to produce the final output.


Operations for linear algebra.
experimental module: Public API for tf.linalg.experimental namespace.
class LinearOperator: Base class defining a [batch of] linear operator[s].
class LinearOperatorAdjoint: LinearOperator representing the adjoint of another operator.
class LinearOperatorBlockDiag: Combines one or more LinearOperators in to a Block Diagonal matrix.
class LinearOperatorBlockLowerTriangular: Combines LinearOperators into a blockwise lower-triangular matrix.
class LinearOperatorCirculant: LinearOperator acting like a circulant matrix.
class LinearOperatorCirculant2D: LinearOperator acting like a block circulant matrix.
class LinearOperatorCirculant3D: LinearOperator acting like a nested block circulant matrix.
class LinearOperatorComposition: Composes one or more LinearOperators.
class LinearOperatorDiag: LinearOperator acting like a [batch] square diagonal matrix.
class LinearOperatorFullMatrix: LinearOperator that wraps a [batch] matrix.
class LinearOperatorHouseholder: LinearOperator acting like a [batch] of Householder transformations.
class LinearOperatorIdentity: LinearOperator acting like a [batch] square identity matrix.
class LinearOperatorInversion: LinearOperator representing the inverse of another operator.
class LinearOperatorKronecker: Kronecker product between two LinearOperators.
class LinearOperatorLowRankUpdate: Perturb a LinearOperator with a rank K update.
class LinearOperatorLowerTriangular: LinearOperator acting like a [batch] square lower triangular matrix.
class LinearOperatorPermutation: LinearOperator acting like a [batch] of permutation matrices.
class LinearOperatorScaledIdentity: LinearOperator acting like a scaled [batch] identity matrix A = c I.
class LinearOperatorToeplitz: LinearOperator acting like a [batch] of toeplitz matrices.
class LinearOperatorTridiag: LinearOperator acting like a [batch] square tridiagonal matrix.
class LinearOperatorZeros: LinearOperator acting like a [batch] zero matrix.
adjoint(...): Transposes the last two dimensions of and conjugates tensor matrix.
band_part(...): Copy a tensor setting everything outside a central band in each innermost matrix to zero.
cholesky(...): Computes the Cholesky decomposition of one or more square matrices.
cholesky_solve(...): Solves systems of linear eqns A X = RHS, given Cholesky factorizations.
cross(...): Compute the pairwise cross product.
det(...): Computes the determinant of one or more square matrices.
diag(...): Returns a batched diagonal tensor with given batched diagonal values.
diag_part(...): Returns the batched diagonal part of a batched tensor.
eigh(...): Computes the eigen decomposition of a batch of self-adjoint matrices.
eigvalsh(...): Computes the eigenvalues of one or more self-adjoint matrices.
einsum(...): Tensor contraction over specified indices and outer product.
expm(...): Computes the matrix exponential of one or more square matrices.
eye(...): Construct an identity matrix, or a batch of matrices.
global_norm(...): Computes the global norm of multiple tensors.
inv(...): Computes the inverse of one or more square invertible matrices or their adjoints (conjugate transposes).
l2_normalize(...): Normalizes along dimension axis using an L2 norm. (deprecated arguments)
logdet(...): Computes log of the determinant of a hermitian positive definite matrix.
logm(...): Computes the matrix logarithm of one or more square matrices:
lstsq(...): Solves one or more linear least-squares problems.
lu(...): Computes the LU decomposition of one or more square matrices.
lu_matrix_inverse(...): Computes the inverse given the LU decomposition(s) of one or more matrices.
lu_reconstruct(...): The reconstruct one or more matrices from their LU decomposition(s).
lu_solve(...): Solves systems of linear eqns A X = RHS, given LU factorizations.
matmul(...): Multiplies matrix a by matrix b, producing a * b.
matrix_rank(...): Compute the matrix rank of one or more matrices.
matrix_transpose(...): Transposes last two dimensions of tensor a.
matvec(...): Multiplies matrix a by vector b, producing a * b.
norm(...): Computes the norm of vectors, matrices, and tensors. (deprecated arguments)
normalize(...): Normalizes tensor along dimension axis using specified norm.
pinv(...): Compute the Moore-Penrose pseudo-inverse of one or more matrices.
qr(...): Computes the QR decompositions of one or more matrices.
set_diag(...): Returns a batched matrix tensor with new batched diagonal values.
slogdet(...): Computes the sign and the log of the absolute value of the determinant of
solve(...): Solves systems of linear equations.
sqrtm(...): Computes the matrix square root of one or more square matrices:
svd(...): Computes the singular value decompositions of one or more matrices.
tensor_diag(...): Returns a diagonal tensor with a given diagonal values.
tensor_diag_part(...): Returns the diagonal part of the tensor.
tensordot(...): Tensor contraction of a and b along specified axes and outer product.
trace(...): Compute the trace of a tensor x.
transpose(...): Transposes last two dimensions of tensor a.
triangular_solve(...): Solve systems of linear equations with upper or lower triangular matrices.
tridiagonal_matmul(...): Multiplies tridiagonal matrix by matrix.
tridiagonal_solve(...): Solves tridiagonal systems of equations.


Public API for tf.linalg.experimental namespace.
conjugate_gradient(...): Conjugate gradient solver.


Normalizes along dimension axis using an L2 norm. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.l2_normalize, tf.compat.v1.nn.l2_normalize
For a 1-D tensor with axis = 0, computes
For x with more dimensions, independently normalizes each 1-D slice along dimension axis.


Public API for tf.lite namespace.
constants module: Public API for tf.lite.constants namespace.
experimental module: Public API for tf.lite.experimental namespace.
class Interpreter: Interpreter interface for TensorFlow Lite Models.
class OpHint: A class that helps build tflite function invocations.
class OpsSet: Enum class defining the sets of ops available to generate TFLite models.
class Optimize: Enum defining the optimizations to apply when generating tflite graphs.
class RepresentativeDataset: Representative dataset to evaluate optimizations.
class TFLiteConverter: Convert a TensorFlow model into output_format.
class TargetSpec: Specification of target device.
class TocoConverter: Convert a TensorFlow model into output_format using TOCO.
toco_convert(...): Convert a model using TOCO. (deprecated)


Public API for tf.lite.constants namespace.


Public API for tf.lite.experimental namespace.
nn module: Public API for tf.lite.experimental.nn namespace.
convert_op_hints_to_stubs(...): Converts a graphdef with LiteOp hints into stub operations.
get_potentially_supported_ops(...): Returns operations potentially supported by TensorFlow Lite.
load_delegate(...): Returns loaded Delegate object.


Converts a graphdef with LiteOp hints into stub operations.
This is used to prepare for toco conversion of complex intrinsic usages. Note: only one of session or graph_def should be used, not both.


Returns operations potentially supported by TensorFlow Lite.
The potentially support list contains a list of ops that are partially or fully supported, which is derived by simply scanning op names to check whether they can be handled without real conversion and specific parameters.
Given that some ops may be partially supported, the optimal way to determine if a model's operations are supported is by converting using the TensorFlow Lite converter.


Public API for tf.lite.experimental.nn namespace.
class TFLiteLSTMCell: Long short-term memory unit (LSTM) recurrent network cell.
class TfLiteRNNCell: The most basic RNN cell.
dynamic_rnn(...): Creates a recurrent neural network specified by RNNCell cell.


Creates a recurrent neural network specified by RNNCell cell.
Performs fully dynamic unrolling of inputs.
If time_major == False (default), this will be a Tensor shaped: [batch_size, max_time, cell.output_size].
If time_major == True, this will be a Tensor shaped: [max_time, batch_size, cell.output_size].
Note, if cell.output_size is a (possibly nested) tuple of integers or TensorShape objects, then outputs will be a tuple having the same structure as cell.output_size, containing Tensors having shapes corresponding to the shape data in cell.output_size.


Long short-term memory unit (LSTM) recurrent network cell.
Inherits From: RNNCell, Layer, Layer, Module
This is used only for TfLite, it provides hints and it also makes the variables in the desired for the tflite ops (transposed and separated).
The default non-peephole implementation is based on:
https://pdfs.semanticscholar.org/1154/0131eae85b2e11d53df7f1360eeb6476e7f4.pdf
Felix Gers, Jurgen Schmidhuber, and Fred Cummins. "Learning to forget: Continual prediction with LSTM." IET, 850-855, 1999.
The peephole implementation is based on:
https://research.google.com/pubs/archive/43905.pdf
Hasim Sak, Andrew Senior, and Francoise Beaufays. "Long short-term memory recurrent neural network architectures for large scale acoustic modeling." INTERSPEECH, 2014.
The class uses optional peep-hole connections, optional cell clipping, and an optional projection layer.
Note that this cell is not optimized for performance. Please use tf.contrib.cudnn_rnn.CudnnLSTM for better performance on GPU, or tf.contrib.rnn.LSTMBlockCell and tf.contrib.rnn.LSTMBlockFusedCell for better performance on CPU.
It can be represented by an Integer, a TensorShape or a tuple of Integers or TensorShapes.
View source
View source
Return zero-filled state tensor(s).
If state_size is a nested list or tuple, then the return value is a nested list or tuple (of the same structure) of 2-D tensors with the shapes [batch_size, s] for each s in state_size.


The most basic RNN cell.
Inherits From: RNNCell, Layer, Layer, Module
This is used only for TfLite, it provides hints and it also makes the variables in the desired for the tflite ops.
It can be represented by an Integer, a TensorShape or a tuple of Integers or TensorShapes.
View source
View source
Return zero-filled state tensor(s).
If state_size is a nested list or tuple, then the return value is a nested list or tuple (of the same structure) of 2-D tensors with the shapes [batch_size, s] for each s in state_size.


A class that helps build tflite function invocations.
It allows you to take a bunch of TensorFlow ops and annotate the construction such that toco knows how to convert it to tflite. This embeds a pseudo function in a TensorFlow graph. This allows embedding high-level API usage information in a lower level TensorFlow implementation so that an alternative implementation can be substituted later.
Essentially, any "input" into this pseudo op is fed into an identity, and attributes are added to that input before being used by the constituent ops that make up the pseudo op. A similar process is done to any output that is to be exported from the current op.
class OpHintArgumentTracker
View source
Add a wrapped input argument to the hint.
View source
Add a sequence of inputs to the function invocation.
View source
Add a wrapped output argument to the hint.
View source
Add a sequence of outputs to the function invocation.


Conceptually tracks indices of arguments of "OpHint functions".
The inputs and arguments of these functions both use an instance of the class so they can have independent numbering.
View source
Return a wrapped tensor of an input tensor as an argument.


Convert a TensorFlow model into output_format.
This is used to convert from a TensorFlow GraphDef, SavedModel or tf.keras model into either a TFLite FlatBuffer or graph visualization.
View source
Converts a TensorFlow GraphDef based on instance variables.
View source
Creates a TFLiteConverter class from a file containing a frozen GraphDef.
View source
Creates a TFLiteConverter class from a tf.keras model file.
View source
Creates a TFLiteConverter class from a SavedModel.
View source
Creates a TFLiteConverter class from a TensorFlow Session.
View source
Returns a list of the names of the input tensors.


Convert a TensorFlow model into output_format using TOCO.
This class has been deprecated. Please use lite.TFLiteConverter instead.
View source
Creates a TocoConverter class from a file containing a frozen graph. (deprecated)
View source
Creates a TocoConverter class from a tf.keras model file. (deprecated)
View source
Creates a TocoConverter class from a SavedModel. (deprecated)
View source
Creates a TocoConverter class from a TensorFlow Session. (deprecated)


Convert a model using TOCO. (deprecated)
Typically this function is used to convert from TensorFlow GraphDef to TFLite. Conversion can be customized by providing arguments that are forwarded to build_toco_convert_protos (see documentation for details). This function has been deprecated. Please use lite.TFLiteConverter instead.


A Reader that outputs the records from a LMDB 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.


Loads a TensorFlow plugin, containing file system implementation. (deprecated)
Pass library_filename to a platform-specific mechanism for dynamically loading a library. The rules for determining the exact location of the library are platform-specific and are not documented here.


Returns local variables.
Local variables - per process variables, usually not saved/restored to checkpoint and used for temporary or intermediate values. For example, they can be used as counters for metrics computation or number of epochs this machine has read data. The tf.contrib.framework.local_variable() function automatically adds the new variable to GraphKeys.LOCAL_VARIABLES. This convenience function returns the contents of that collection.
An alternative to local variables are global variables. See tf.compat.v1.global_variables


Returns an Op that initializes all local variables.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.initializers.local_variables
This is just a shortcut for variables_initializer(local_variables())


Logging and Summary Operations.
TaskLevelStatusMessage(...)
debug(...)
error(...)
fatal(...)
flush(...)
get_verbosity(...): Return how much logging output will be produced.
info(...)
log(...)
log_every_n(...): Log 'msg % args' at level 'level' once per 'n' times.
log_first_n(...): Log 'msg % args' at level 'level' only first 'n' times.
log_if(...): Log 'msg % args' at level 'level' only if condition is fulfilled.
set_verbosity(...): Sets the threshold for what messages will be logged.
vlog(...)
warn(...)
warning(...)


Return how much logging output will be produced.


Log 'msg % args' at level 'level' once per 'n' times.
Logs the 1st call, (N+1)st call, (2N+1)st call, etc. Not threadsafe.


Log 'msg % args' at level 'level' only first 'n' times.
Not threadsafe.


Log 'msg % args' at level 'level' only if condition is fulfilled.


Sets the threshold for what messages will be logged.


Public API for tf.lookup namespace.
experimental module: Public API for tf.lookup.experimental namespace.
class KeyValueTensorInitializer: Table initializers given keys and values tensors.
class StaticHashTable: A generic hash table that is immutable once initialized.
class StaticVocabularyTable: String to Id table that assigns out-of-vocabulary keys to hash buckets.
class TextFileIndex: The key and value content to get from each line.
class TextFileInitializer: Table initializers from a text file.


Public API for tf.lookup.experimental namespace.
class DatasetInitializer: Creates a table initializer from a tf.data.Dataset.
class DenseHashTable: A generic mutable hash table implementation using tensors as backing store.


A generic hash table that is immutable once initialized.
Inherits From: StaticHashTable
When running in graph mode, you must evaluate the tensor returned by tf.tables_initializer() before evaluating the tensor returned by this class's lookup() method. Example usage in graph mode:
In eager mode, no special code is needed to initialize the table. Example usage in eager mode:
View source
Returns tensors of all keys and values in the table.
View source
Looks up keys in a table, outputs the corresponding values.
The default_value is used for keys not present in the table.
View source
Compute the number of elements in this table.
View source
Looks up keys in a table, outputs the corresponding values.


String to Id table that assigns out-of-vocabulary keys to hash buckets.
Inherits From: StaticVocabularyTable
For example, if an instance of StaticVocabularyTable is initialized with a string-to-id initializer that maps:
The Vocabulary object will performs the following mapping:
If initializer is None, only out-of-vocabulary buckets are used.
The hash function used for generating out-of-vocabulary buckets ID is Fingerprint64.
View source
Looks up keys in the table, outputs the corresponding values.
It assigns out-of-vocabulary keys to buckets based in their hashes.
View source
Compute the number of elements in this table.
View source
Looks up keys in a table, outputs the corresponding values.


Loss operations for use in neural networks.
class Reduction: Types of loss reduction.
absolute_difference(...): Adds an Absolute Difference loss to the training procedure.
add_loss(...): Adds a externally defined loss to the collection of losses.
compute_weighted_loss(...): Computes the weighted loss.
cosine_distance(...): Adds a cosine-distance loss to the training procedure. (deprecated arguments)
get_losses(...): Gets the list of losses from the loss_collection.
get_regularization_loss(...): Gets the total regularization loss.
get_regularization_losses(...): Gets the list of regularization losses.
get_total_loss(...): Returns a tensor whose value represents the total loss.
hinge_loss(...): Adds a hinge loss to the training procedure.
huber_loss(...): Adds a Huber Loss term to the training procedure.
log_loss(...): Adds a Log Loss term to the training procedure.
mean_pairwise_squared_error(...): Adds a pairwise-errors-squared loss to the training procedure.
mean_squared_error(...): Adds a Sum-of-Squares loss to the training procedure.
sigmoid_cross_entropy(...): Creates a cross-entropy loss using tf.nn.sigmoid_cross_entropy_with_logits.
softmax_cross_entropy(...): Creates a cross-entropy loss using tf.nn.softmax_cross_entropy_with_logits_v2.
sparse_softmax_cross_entropy(...): Cross-entropy loss using tf.nn.sparse_softmax_cross_entropy_with_logits.


Adds an Absolute Difference loss to the training procedure.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a Tensor of shape [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the weights vector. If the shape of weights matches the shape of predictions, then the loss of each measurable element of predictions is scaled by the corresponding value of weights.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a externally defined loss to the collection of losses.


Computes the weighted loss.
When calculating the gradient of a weighted loss contributions from both losses and weights are considered. If your weights depend on some model parameters but you do not want this to affect the loss gradient, you need to apply tf.stop_gradient to weights before passing them to compute_weighted_loss.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a cosine-distance loss to the training procedure. (deprecated arguments)
Note that the function assumes that predictions and labels are already unit-normalized.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Gets the list of losses from the loss_collection.


Returns a tensor whose value represents the total loss.
In particular, this adds any losses you have added with tf.add_loss() to any regularization losses that have been added by regularization parameters on layers constructors e.g. tf.layers. Be very sure to use this if you are constructing a loss_op manually. Otherwise regularization arguments on tf.layers methods will not function.


Adds a hinge loss to the training procedure.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a Huber Loss term to the training procedure.
For each value x in error=labels-predictions, the following is calculated:
where d is delta.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the weights vector. If the shape of weights matches the shape of predictions, then the loss of each measurable element of predictions is scaled by the corresponding value of weights.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a Log Loss term to the training procedure.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the weights vector. If the shape of weights matches the shape of predictions, then the loss of each measurable element of predictions is scaled by the corresponding value of weights.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a pairwise-errors-squared loss to the training procedure.
Unlike mean_squared_error, which is a measure of the differences between corresponding elements of predictions and labels, mean_pairwise_squared_error is a measure of the differences between pairs of corresponding elements of predictions and labels.
For example, if labels=[a, b, c] and predictions=[x, y, z], there are three pairs of differences are summed to compute the loss: loss = [ ((a-b) - (x-y)).^2 + ((a-c) - (x-z)).^2 + ((b-c) - (y-z)).^2 ] / 3
Note that since the inputs are of shape [batch_size, d0, ... dN], the corresponding pairs are computed within each batch sample but not across samples within a batch. For example, if predictions represents a batch of 16 grayscale images of dimension [batch_size, 100, 200], then the set of pairs is drawn from each image, but not across images.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the weights vector.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Adds a Sum-of-Squares loss to the training procedure.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the weights vector. If the shape of weights matches the shape of predictions, then the loss of each measurable element of predictions is scaled by the corresponding value of weights.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Types of loss reduction.
Contains the following values:
View source
View source


Creates a cross-entropy loss using tf.nn.sigmoid_cross_entropy_with_logits.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of shape [batch_size], then the loss weights apply to each corresponding sample.
If label_smoothing is nonzero, smooth the labels towards 1/2:
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Creates a cross-entropy loss using tf.nn.softmax_cross_entropy_with_logits_v2.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of shape [batch_size], then the loss weights apply to each corresponding sample.
If label_smoothing is nonzero, smooth the labels towards 1/num_classes: new_onehot_labels = onehot_labels * (1 - label_smoothing)
Note that onehot_labels and logits must have the same shape, e.g. [batch_size, num_classes]. The shape of weights must be broadcastable to loss, whose shape is decided by the shape of logits. In case the shape of logits is [batch_size, num_classes], loss is a Tensor of shape [batch_size].
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Cross-entropy loss using tf.nn.sparse_softmax_cross_entropy_with_logits.
weights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If weights is a tensor of shape [batch_size], then the loss weights apply to each corresponding sample.
The loss_collection argument is ignored when executing eagerly. Consider holding on to the return value or collecting losses via a tf.keras.Model.


Given an arbitrary function, wrap it so that it does variable sharing.
This wraps func_ in a Template and partially evaluates it. Templates are functions that create variables the first time they are called and reuse them thereafter. In order for func_ to be compatible with a Template it must have the following properties:
In the following example, both z and w will be scaled by the same y. It is important to note that if we didn't assign scalar_name and used a different name for z and w that a ValueError would be thrown because it couldn't reuse the variable.
As a safe-guard, the returned function will raise a ValueError after the first call if trainable variables are created by calling tf.Variable.
If all of these are true, then 2 properties are enforced by the template:
Depending on the value of create_scope_now_, the full variable scope may be captured either at the time of first call or at the time of construction. If this option is set to True, then all Tensors created by repeated calls to the template will have an extra trailing _N+1 to their name, as the first time the scope is entered in the Template constructor no Tensors are created.


Operators for manipulating tensors.
batch_to_space_nd(...): BatchToSpace for N-D tensors of type T.
gather_nd(...): Gather slices from params into a Tensor with shape specified by indices.
reshape(...): Reshapes a tensor.
reverse(...): Reverses specific dimensions of a tensor.
roll(...): Rolls the elements of a tensor along an axis.
scatter_nd(...): Scatter updates into a new tensor according to indices.
space_to_batch_nd(...): SpaceToBatch for N-D tensors of type T.
tile(...): Constructs a tensor by tiling a given tensor.


Transforms elems by applying fn to each element unstacked on axis 0. (deprecated arguments)
See also tf.scan.
map_fn unstacks elems on axis 0 to obtain a sequence of elements; calls fn to transform each element; and then stacks the transformed values back together.
If elems is a single tensor and fn's signature is tf.Tensor->tf.Tensor, then map_fn(fn, elems) is equivalent to tf.stack([fn(elem) for elem in tf.unstack(elems)]). E.g.:
map_fn(fn, elems).shape = [elems.shape[0]] + fn(elems[0]).shape.
map_fn also supports functions with multi-arity inputs and outputs:
If elems is a tuple (or nested structure) of tensors, then those tensors must all have the same outer-dimension size (num_elems); and fn is used to transform each tuple (or structure) of corresponding slices from elems. E.g., if elems is a tuple (t1, t2, t3), then fn is used to transform each tuple of slices (t1[i], t2[i], t3[i]) (where 0 <= i < num_elems).
If fn returns a tuple (or nested structure) of tensors, then the result is formed by stacking corresponding elements from those structures.
If fn's input and output signatures are different, then the output signature must be specified using fn_output_signature. (The input and output signatures are differ if their structures, dtypes, or tensor types do not match). E.g.:
fn_output_signature can be specified using any of the following:
map_fn supports tf.RaggedTensor inputs and outputs. In particular:
If elems is a RaggedTensor, then fn will be called with each row of that ragged tensor.
If the result of map_fn should be a RaggedTensor, then use a tf.RaggedTensorSpec to specify fn_output_signature.
E.g.:
map_fn supports tf.sparse.SparseTensor inputs and outputs. In particular:
If elems is a SparseTensor, then fn will be called with each row of that sparse tensor. In particular, the value passed to fn will be a tf.sparse.SparseTensor with one fewer dimension than elems.
If the result of map_fn should be a SparseTensor, then use a tf.SparseTensorSpec to specify fn_output_signature. The individual SparseTensors returned by fn will be stacked into a single SparseTensor with one more dimension.
If the function is expressible as TensorFlow ops, use:
Otherwise, use:
map_fn will apply the operations used by fn to each element of elems, resulting in O(elems.shape[0]) total operations. This is somewhat mitigated by the fact that map_fn can process elements in parallel. However, a transform expressed using map_fn is still typically less efficient than an equivalent transform expressed using vectorized operations.
map_fn should typically only be used if one of the following is true:
E.g., the example given above that maps fn=lambda t: tf.range(t, t + 3) across elems could be rewritten more efficiently using vectorized ops:
In some cases, tf.vectorized_map can be used to automatically convert a function to a vectorized eqivalent.
When executing eagerly, map_fn does not execute in parallel even if parallel_iterations is set to a value > 1. You can still get the performance benefits of running a function in parallel by using the tf.function decorator:


Math Operations.
TensorFlow provides a variety of math functions including:
See: tf.linalg for matrix and tensor functions.
TensorFlow provides several operations that you can use to perform common math computations on tensor segments. Here a segmentation is a partitioning of a tensor along the first dimension, i.e. it defines a mapping from the first dimension onto segment_ids. The segment_ids tensor should be the size of the first dimension, d0, with consecutive IDs in the range 0 to k, where k<d0. In particular, a segmentation of a matrix tensor is a mapping of rows to segments.
The standard segment_* functions assert that the segment indices are sorted. If you have unsorted indices use the equivalent unsorted_segment_ function. These functions take an additional argument num_segments so that the output tensor can be efficiently allocated.
special module: Public API for tf.math.special namespace.
abs(...): Computes the absolute value of a tensor.
accumulate_n(...): Returns the element-wise sum of a list of tensors.
acos(...): Computes acos of x element-wise.
acosh(...): Computes inverse hyperbolic cosine of x element-wise.
add(...): Returns x + y element-wise.
add_n(...): Adds all input tensors element-wise.
angle(...): Returns the element-wise argument of a complex (or real) tensor.
argmax(...): Returns the index with the largest value across axes of a tensor. (deprecated arguments)
argmin(...): Returns the index with the smallest value across axes of a tensor. (deprecated arguments)
asin(...): Computes the trignometric inverse sine of x element-wise.
asinh(...): Computes inverse hyperbolic sine of x element-wise.
atan(...): Computes the trignometric inverse tangent of x element-wise.
atan2(...): Computes arctangent of y/x element-wise, respecting signs of the arguments.
atanh(...): Computes inverse hyperbolic tangent of x element-wise.
bessel_i0(...): Computes the Bessel i0 function of x element-wise.
bessel_i0e(...): Computes the Bessel i0e function of x element-wise.
bessel_i1(...): Computes the Bessel i1 function of x element-wise.
bessel_i1e(...): Computes the Bessel i1e function of x element-wise.
betainc(...): Compute the regularized incomplete beta integral \(I_x(a, b)\).
bincount(...): Counts the number of occurrences of each value in an integer array.
ceil(...): Return the ceiling of the input, element-wise.
confusion_matrix(...): Computes the confusion matrix from predictions and labels.
conj(...): Returns the complex conjugate of a complex number.
cos(...): Computes cos of x element-wise.
cosh(...): Computes hyperbolic cosine of x element-wise.
count_nonzero(...): Computes number of nonzero elements across dimensions of a tensor. (deprecated arguments) (deprecated arguments)
cumprod(...): Compute the cumulative product of the tensor x along axis.
cumsum(...): Compute the cumulative sum of the tensor x along axis.
cumulative_logsumexp(...): Compute the cumulative log-sum-exp of the tensor x along axis.
digamma(...): Computes Psi, the derivative of Lgamma (the log of the absolute value of
divide(...): Computes Python style division of x by y.
divide_no_nan(...): Computes a safe divide which returns 0 if the y is zero.
equal(...): Returns the truth value of (x == y) element-wise.
erf(...): Computes the Gauss error function of x element-wise.
erfc(...): Computes the complementary error function of x element-wise.
erfcinv(...): Computes the inverse of complementary error function.
erfinv(...): Compute inverse error function.
exp(...): Computes exponential of x element-wise. \(y = e^x\).
expm1(...): Computes exp(x) - 1 element-wise.
floor(...): Returns element-wise largest integer not greater than x.
floordiv(...): Divides x / y elementwise, rounding toward the most negative integer.
floormod(...): Returns element-wise remainder of division. When x < 0 xor y < 0 is
greater(...): Returns the truth value of (x > y) element-wise.
greater_equal(...): Returns the truth value of (x >= y) element-wise.
igamma(...): Compute the lower regularized incomplete Gamma function P(a, x).
igammac(...): Compute the upper regularized incomplete Gamma function Q(a, x).
imag(...): Returns the imaginary part of a complex (or real) tensor.
in_top_k(...): Says whether the targets are in the top K predictions.
invert_permutation(...): Computes the inverse permutation of a tensor.
is_finite(...): Returns which elements of x are finite.
is_inf(...): Returns which elements of x are Inf.
is_nan(...): Returns which elements of x are NaN.
is_non_decreasing(...): Returns True if x is non-decreasing.
is_strictly_increasing(...): Returns True if x is strictly increasing.
l2_normalize(...): Normalizes along dimension axis using an L2 norm. (deprecated arguments)
lbeta(...): Computes \(ln(|Beta(x)|)\), reducing along the last dimension.
less(...): Returns the truth value of (x < y) element-wise.
less_equal(...): Returns the truth value of (x <= y) element-wise.
lgamma(...): Computes the log of the absolute value of Gamma(x) element-wise.
log(...): Computes natural logarithm of x element-wise.
log1p(...): Computes natural logarithm of (1 + x) element-wise.
log_sigmoid(...): Computes log sigmoid of x element-wise.
log_softmax(...): Computes log softmax activations. (deprecated arguments)
logical_and(...): Logical AND function.
logical_not(...): Returns the truth value of NOT x element-wise.
logical_or(...): Returns the truth value of x OR y element-wise.
logical_xor(...): Logical XOR function.
maximum(...): Returns the max of x and y (i.e. x > y ? x : y) element-wise.
minimum(...): Returns the min of x and y (i.e. x < y ? x : y) element-wise.
mod(...): Returns element-wise remainder of division. When x < 0 xor y < 0 is
multiply(...): Returns an element-wise x * y.
multiply_no_nan(...): Computes the product of x and y and returns 0 if the y is zero, even if x is NaN or infinite.
ndtri(...): Compute quantile of Standard Normal.
negative(...): Computes numerical negative value element-wise.
nextafter(...): Returns the next representable value of x1 in the direction of x2, element-wise.
not_equal(...): Returns the truth value of (x != y) element-wise.
polygamma(...): Compute the polygamma function \(\psi^{(n)}(x)\).
polyval(...): Computes the elementwise value of a polynomial.
pow(...): Computes the power of one value to another.
real(...): Returns the real part of a complex (or real) tensor.
reciprocal(...): Computes the reciprocal of x element-wise.
reciprocal_no_nan(...): Performs a safe reciprocal operation, element wise.
reduce_all(...): Computes the "logical and" of elements across dimensions of a tensor. (deprecated arguments)
reduce_any(...): Computes the "logical or" of elements across dimensions of a tensor. (deprecated arguments)
reduce_euclidean_norm(...): Computes the Euclidean norm of elements across dimensions of a tensor.
reduce_logsumexp(...): Computes log(sum(exp(elements across dimensions of a tensor))). (deprecated arguments)
reduce_max(...): Computes the maximum of elements across dimensions of a tensor. (deprecated arguments)
reduce_mean(...): Computes the mean of elements across dimensions of a tensor.
reduce_min(...): Computes the minimum of elements across dimensions of a tensor. (deprecated arguments)
reduce_prod(...): Computes the product of elements across dimensions of a tensor. (deprecated arguments)
reduce_std(...): Computes the standard deviation of elements across dimensions of a tensor.
reduce_sum(...): Computes the sum of elements across dimensions of a tensor. (deprecated arguments)
reduce_variance(...): Computes the variance of elements across dimensions of a tensor.
rint(...): Returns element-wise integer closest to x.
round(...): Rounds the values of a tensor to the nearest integer, element-wise.
rsqrt(...): Computes reciprocal of square root of x element-wise.
scalar_mul(...): Multiplies a scalar times a Tensor or IndexedSlices object.
segment_max(...): Computes the maximum along segments of a tensor.
segment_mean(...): Computes the mean along segments of a tensor.
segment_min(...): Computes the minimum along segments of a tensor.
segment_prod(...): Computes the product along segments of a tensor.
segment_sum(...): Computes the sum along segments of a tensor.
sigmoid(...): Computes sigmoid of x element-wise.
sign(...): Returns an element-wise indication of the sign of a number.
sin(...): Computes sine of x element-wise.
sinh(...): Computes hyperbolic sine of x element-wise.
sobol_sample(...): Generates points from the Sobol sequence.
softmax(...): Computes softmax activations. (deprecated arguments)
softplus(...): Computes softplus: log(exp(features) + 1).
softsign(...): Computes softsign: features / (abs(features) + 1).
sqrt(...): Computes element-wise square root of the input tensor.
square(...): Computes square of x element-wise.
squared_difference(...): Returns conj(x - y)(x - y) element-wise.
subtract(...): Returns x - y element-wise.
tan(...): Computes tan of x element-wise.
tanh(...): Computes hyperbolic tangent of x element-wise.
top_k(...): Finds values and indices of the k largest entries for the last dimension.
truediv(...): Divides x / y elementwise (using Python 3 division operator semantics).
unsorted_segment_max(...): Computes the maximum along segments of a tensor.
unsorted_segment_mean(...): Computes the mean along segments of a tensor.
unsorted_segment_min(...): Computes the minimum along segments of a tensor.
unsorted_segment_prod(...): Computes the product along segments of a tensor.
unsorted_segment_sqrt_n(...): Computes the sum along segments of a tensor divided by the sqrt(N).
unsorted_segment_sum(...): Computes the sum along segments of a tensor.
xdivy(...): Returns 0 if x == 0, and x / y otherwise, elementwise.
xlog1py(...): Compute x * log1p(y).
xlogy(...): Returns 0 if x == 0, and x * log(y) otherwise, elementwise.
zero_fraction(...): Returns the fraction of zeros in value.
zeta(...): Compute the Hurwitz zeta function \(\zeta(x, q)\).


Says whether the targets are in the top K predictions.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.in_top_k
This outputs a batch_size bool array, an entry out[i] is true if the prediction for the target class is finite (not inf, -inf, or nan) and among the top k predictions among all predictions for example i. Note that the behavior of InTopK differs from the TopK op in its handling of ties; if multiple classes have the same prediction value and straddle the top-k boundary, all of those classes are considered to be in the top k.
More formally, let
\(predictions_i\) be the predictions for all classes for example i, \(targets_i\) be the target class for example i, \(out_i\) be the output for example i,


Computes log softmax activations. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.log_softmax
For each batch i and class j we have


Computes softmax activations. (deprecated arguments)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.softmax
This function performs the equivalent of
See: https://en.wikipedia.org/wiki/Softmax_function


Public API for tf.math.special namespace.
bessel_i0(...): Computes the Bessel i0 function of x element-wise.
bessel_i0e(...): Computes the Bessel i0e function of x element-wise.
bessel_i1(...): Computes the Bessel i1 function of x element-wise.
bessel_i1e(...): Computes the Bessel i1e function of x element-wise.
bessel_j0(...): Computes the Bessel j0 function of x element-wise.
bessel_j1(...): Computes the Bessel j1 function of x element-wise.
bessel_k0(...): Computes the Bessel k0 function of x element-wise.
bessel_k0e(...): Computes the Bessel k0e function of x element-wise.
bessel_k1(...): Computes the Bessel k1 function of x element-wise.
bessel_k1e(...): Computes the Bessel k1e function of x element-wise.
bessel_y0(...): Computes the Bessel y0 function of x element-wise.
bessel_y1(...): Computes the Bessel y1 function of x element-wise.
dawsn(...): Computes Dawson's integral of x element-wise.
expint(...): Computes the Exponential integral of x element-wise.
fresnel_cos(...): Computes Fresnel's cosine integral of x element-wise.
fresnel_sin(...): Computes Fresnel's sine integral of x element-wise.
spence(...): Computes Spence's integral of x element-wise.


A ProtocolMessage
class CollectionDefEntry
class MetaInfoDef
class SignatureDefEntry


A ProtocolMessage
class FunctionAliasesEntry


Evaluation-related metrics.
accuracy(...): Calculates how often predictions matches labels.
auc(...): Computes the approximate AUC via a Riemann sum. (deprecated)
average_precision_at_k(...): Computes average precision@k of predictions with respect to sparse labels.
false_negatives(...): Computes the total number of false negatives.
false_negatives_at_thresholds(...): Computes false negatives at provided threshold values.
false_positives(...): Sum the weights of false positives.
false_positives_at_thresholds(...): Computes false positives at provided threshold values.
mean(...): Computes the (weighted) mean of the given values.
mean_absolute_error(...): Computes the mean absolute error between the labels and predictions.
mean_cosine_distance(...): Computes the cosine distance between the labels and predictions.
mean_iou(...): Calculate per-step mean Intersection-Over-Union (mIOU).
mean_per_class_accuracy(...): Calculates the mean of the per-class accuracies.
mean_relative_error(...): Computes the mean relative error by normalizing with the given values.
mean_squared_error(...): Computes the mean squared error between the labels and predictions.
mean_tensor(...): Computes the element-wise (weighted) mean of the given tensors.
percentage_below(...): Computes the percentage of values less than the given threshold.
precision(...): Computes the precision of the predictions with respect to the labels.
precision_at_k(...): Computes precision@k of the predictions with respect to sparse labels.
precision_at_thresholds(...): Computes precision values for different thresholds on predictions.
precision_at_top_k(...): Computes precision@k of the predictions with respect to sparse labels.
recall(...): Computes the recall of the predictions with respect to the labels.
recall_at_k(...): Computes recall@k of the predictions with respect to sparse labels.
recall_at_thresholds(...): Computes various recall values for different thresholds on predictions.
recall_at_top_k(...): Computes recall@k of top-k predictions with respect to sparse labels.
root_mean_squared_error(...): Computes the root mean squared error between the labels and predictions.
sensitivity_at_specificity(...): Computes the specificity at a given sensitivity.
sparse_average_precision_at_k(...): Renamed to average_precision_at_k, please use that method instead. (deprecated)
sparse_precision_at_k(...): Renamed to precision_at_k, please use that method instead. (deprecated)
specificity_at_sensitivity(...): Computes the specificity at a given sensitivity.
true_negatives(...): Sum the weights of true_negatives.
true_negatives_at_thresholds(...): Computes true negatives at provided threshold values.
true_positives(...): Sum the weights of true_positives.
true_positives_at_thresholds(...): Computes true positives at provided threshold values.


Calculates how often predictions matches labels.
The accuracy function creates two local variables, total and count that are used to compute the frequency with which predictions matches labels. This frequency is ultimately returned as accuracy: an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the accuracy. Internally, an is_correct operation computes a Tensor with elements 1.0 where the corresponding elements of predictions and labels match and 0.0 otherwise. Then update_op increments total with the reduced sum of the product of weights and is_correct, and it increments count with the reduced sum of weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the approximate AUC via a Riemann sum. (deprecated)
The auc function creates four local variables, true_positives, true_negatives, false_positives and false_negatives that are used to compute the AUC. To discretize the AUC curve, a linearly spaced set of thresholds is used to compute pairs of recall and precision values. The area under the ROC-curve is therefore computed using the height of the recall values by the false positive rate, while the area under the PR-curve is the computed using the height of the precision values by the recall.
This value is ultimately returned as auc, an idempotent operation that computes the area under a discretized curve of precision versus recall values (computed using the aforementioned variables). The num_thresholds variable controls the degree of discretization with larger numbers of thresholds more closely approximating the true AUC. The quality of the approximation may vary dramatically depending on num_thresholds.
For best results, predictions should be distributed approximately uniformly in the range [0, 1] and not peaked around 0 or 1. The quality of the AUC approximation may be poor if this is not the case. Setting summation_method to 'minoring' or 'majoring' can help quantify the error in the approximation by providing lower or upper bound estimate of the AUC. The thresholds parameter can be used to manually specify thresholds which split the predictions more evenly.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the auc.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes average precision@k of predictions with respect to sparse labels.
average_precision_at_k creates two local variables, average_precision_at_<k>/total and average_precision_at_<k>/max, that are used to compute the frequency. This frequency is ultimately returned as average_precision_at_<k>: an idempotent operation that simply divides average_precision_at_<k>/total by average_precision_at_<k>/max.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the precision_at_<k>. Internally, a top_k operation computes a Tensor indicating the top k predictions. Set operations applied to top_k and labels calculate the true positives and false positives weighted by weights. Then update_op increments true_positive_at_<k> and false_positive_at_<k> using these values.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the total number of false negatives.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes false negatives at provided threshold values.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Sum the weights of false positives.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes false positives at provided threshold values.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the (weighted) mean of the given values.
The mean function creates two local variables, total and count that are used to compute the average of values. This average is ultimately returned as mean which is an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean. update_op increments total with the reduced sum of the product of values and weights, and it increments count with the reduced sum of weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the mean absolute error between the labels and predictions.
The mean_absolute_error function creates two local variables, total and count that are used to compute the mean absolute error. This average is weighted by weights, and it is ultimately returned as mean_absolute_error: an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean_absolute_error. Internally, an absolute_errors operation computes the absolute value of the differences between predictions and labels. Then update_op increments total with the reduced sum of the product of weights and absolute_errors, and it increments count with the reduced sum of weights
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the cosine distance between the labels and predictions.
The mean_cosine_distance function creates two local variables, total and count that are used to compute the average cosine distance between predictions and labels. This average is weighted by weights, and it is ultimately returned as mean_distance, which is an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean_distance.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Calculate per-step mean Intersection-Over-Union (mIOU).
Mean Intersection-Over-Union is a common evaluation metric for semantic image segmentation, which first computes the IOU for each semantic class and then computes the average over classes. IOU is defined as follows: IOU = true_positive / (true_positive + false_positive + false_negative). The predictions are accumulated in a confusion matrix, weighted by weights, and mIOU is then calculated from it.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean_iou.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Calculates the mean of the per-class accuracies.
Calculates the accuracy for each class, then takes the mean of that.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates the accuracy of each class and returns them.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the mean relative error by normalizing with the given values.
The mean_relative_error function creates two local variables, total and count that are used to compute the mean relative absolute error. This average is weighted by weights, and it is ultimately returned as mean_relative_error: an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean_reative_error. Internally, a relative_errors operation divides the absolute value of the differences between predictions and labels by the normalizer. Then update_op increments total with the reduced sum of the product of weights and relative_errors, and it increments count with the reduced sum of weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the mean squared error between the labels and predictions.
The mean_squared_error function creates two local variables, total and count that are used to compute the mean squared error. This average is weighted by weights, and it is ultimately returned as mean_squared_error: an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean_squared_error. Internally, a squared_error operation computes the element-wise square of the difference between predictions and labels. Then update_op increments total with the reduced sum of the product of weights and squared_error, and it increments count with the reduced sum of weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the element-wise (weighted) mean of the given tensors.
In contrast to the mean function which returns a scalar with the mean, this function returns an average tensor with the same shape as the input tensors.
The mean_tensor function creates two local variables, total_tensor and count_tensor that are used to compute the average of values. This average is ultimately returned as mean which is an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the mean. update_op increments total with the reduced sum of the product of values and weights, and it increments count with the reduced sum of weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the percentage of values less than the given threshold.
The percentage_below function creates two local variables, total and count that are used to compute the percentage of values that fall below threshold. This rate is weighted by weights, and it is ultimately returned as percentage which is an idempotent operation that simply divides total by count.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the percentage.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes the precision of the predictions with respect to the labels.
The precision function creates two local variables, true_positives and false_positives, that are used to compute the precision. This value is ultimately returned as precision, an idempotent operation that simply divides true_positives by the sum of true_positives and false_positives.
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the precision. update_op weights each prediction by the corresponding value in weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes precision@k of the predictions with respect to sparse labels.
If class_id is specified, we calculate precision by considering only the entries in the batch for which class_id is in the top-k highest predictions, and computing the fraction of them for which class_id is indeed a correct label. If class_id is not specified, we'll calculate precision as how often on average a class among the top-k classes with the highest predicted values of a batch entry is correct and can be found in the label for that entry.
precision_at_k creates two local variables, true_positive_at_<k> and false_positive_at_<k>, that are used to compute the precision@k frequency. This frequency is ultimately returned as precision_at_<k>: an idempotent operation that simply divides true_positive_at_<k> by total (true_positive_at_<k> + false_positive_at_<k>).
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the precision_at_<k>. Internally, a top_k operation computes a Tensor indicating the top k predictions. Set operations applied to top_k and labels calculate the true positives and false positives weighted by weights. Then update_op increments true_positive_at_<k> and false_positive_at_<k> using these values.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes precision values for different thresholds on predictions.
The precision_at_thresholds function creates four local variables, true_positives, true_negatives, false_positives and false_negatives for various values of thresholds. precision[i] is defined as the total weight of values in predictions above thresholds[i] whose corresponding entry in labels is True, divided by the total weight of values in predictions above thresholds[i] (true_positives[i] / (true_positives[i] + false_positives[i])).
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the precision.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes precision@k of the predictions with respect to sparse labels.
Differs from sparse_precision_at_k in that predictions must be in the form of top k class indices, whereas sparse_precision_at_k expects logits. Refer to sparse_precision_at_k for more details.


Computes the recall of the predictions with respect to the labels.
The recall function creates two local variables, true_positives and false_negatives, that are used to compute the recall. This value is ultimately returned as recall, an idempotent operation that simply divides true_positives by the sum of true_positives and false_negatives.
For estimation of the metric over a stream of data, the function creates an update_op that updates these variables and returns the recall. update_op weights each prediction by the corresponding value in weights.
If weights is None, weights default to 1. Use weights of 0 to mask values.


Computes recall@k of the predictions with respect to sparse labels.
If class_id is specified, we calculate recall by considering only the entries in the batch for which class_id is in the label, and computing the fraction of them for which class_id is in the top-k predictions. If class_id is not specified, we'll calculate recall as how often on average a class among the labels of a batch entry is in the top-k predictions.
sparse_recall_at_k creates two local variables, true_positive_at_<k> and false_negative_at_<k>, that are used to compute the recall_at_k frequency. This frequency is ultimately returned as recall_at_<k>: an idempotent operation that simply divides true_positive_at_<k> by total (true_positive_at_<k> + false_negative_at_<k>).
For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the recall_at_<k>. Internally, a top_k operation computes a Tensor indicating the top k predictions. Set operations applied to top_k and labels calculate the true positives and false negatives weighted by weights. Then update_op increments true_positive_at_<k> and false_negative_at_<k> using these values.
If weights is None, weights default to 1. Use weights of 0 to mask values.