Fake-quantize the 'inputs' tensor, type float to 'outputs' tensor of same type.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_args, tf.compat.v1.quantization.fake_quant_with_min_max_args
Attributes
Before quantization, min and max values are adjusted with the following logic. It is suggested to have min <= 0 <= max. If 0 is not in the range of values, the behavior can be unexpected:
Quantization is called fake since the output is still in floating point.


Compute gradients for a FakeQuantWithMinMaxArgs operation.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_args_gradient, tf.compat.v1.quantization.fake_quant_with_min_max_args_gradient


Fake-quantize the 'inputs' tensor of type float via global float scalars
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_vars, tf.compat.v1.quantization.fake_quant_with_min_max_vars
Fake-quantize the inputs tensor of type float via global float scalars min and max to outputs tensor of same shape as inputs.
Attributes
Before quantization, min and max values are adjusted with the following logic. It is suggested to have min <= 0 <= max. If 0 is not in the range of values, the behavior can be unexpected:
This operation has a gradient and thus allows for training min and max values.


Compute gradients for a FakeQuantWithMinMaxVars operation.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_vars_gradient, tf.compat.v1.quantization.fake_quant_with_min_max_vars_gradient


Fake-quantize the 'inputs' tensor of type float via per-channel floats
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_vars_per_channel, tf.compat.v1.quantization.fake_quant_with_min_max_vars_per_channel
Fake-quantize the inputs tensor of type float per-channel and one of the shapes: [d], [b, d] [b, h, w, d] via per-channel floats min and max of shape [d] to outputs tensor of same shape as inputs.
Attributes
Before quantization, min and max values are adjusted with the following logic. It is suggested to have min <= 0 <= max. If 0 is not in the range of values, the behavior can be unexpected:
This operation has a gradient and thus allows for training min and max values.


Compute gradients for a FakeQuantWithMinMaxVarsPerChannel operation.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.fake_quant_with_min_max_vars_per_channel_gradient, tf.compat.v1.quantization.fake_quant_with_min_max_vars_per_channel_gradient


Quantize the 'input' tensor of type float to 'output' tensor of type 'T'.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.quantization.quantize, tf.compat.v1.quantize
[min_range, max_range] are scalar floats that specify the range for the 'input' data. The 'mode' attribute controls exactly which calculations are used to convert the float values to their quantized equivalents. The 'round_mode' attribute controls which rounding tie-breaking algorithm is used when rounding float values to their quantized equivalents.
In 'MIN_COMBINED' mode, each value of the tensor will undergo the following:
here range(T) = numeric_limits<T>::max() - numeric_limits<T>::min()
MIN_COMBINED Mode Example
Assume the input is type float and has a possible range of [0.0, 6.0] and the output type is quint8 ([0, 255]). The min_range and max_range values should be specified as 0.0 and 6.0. Quantizing from float to quint8 will multiply each value of the input by 255/6 and cast to quint8.
If the output type was qint8 ([-128, 127]), the operation will additionally subtract each value by 128 prior to casting, so that the range of values aligns with the range of qint8.
If the mode is 'MIN_FIRST', then this approach is used:
The biggest difference between this and MIN_COMBINED is that the minimum range is rounded first, before it's subtracted from the rounded value. With MIN_COMBINED, a small bias is introduced where repeated iterations of quantizing and dequantizing will introduce a larger and larger error.
SCALED mode Example
SCALED mode matches the quantization approach used in QuantizeAndDequantize{V2|V3}.
If the mode is SCALED, the quantization is performed by multiplying each input value by a scaling_factor. The scaling_factor is determined from min_range and max_range to be as large as possible such that the range from min_range to max_range is representable within values of type T.
We next use the scale_factor to adjust min_range and max_range as follows:
e.g. if T = qint8, and initially min_range = -10, and max_range = 9, we would compare -128/-10.0 = 12.8 to 127/9.0 = 14.11, and set scaling_factor = 12.8 In this case, min_range would remain -10, but max_range would be adjusted to 127 / 12.8 = 9.921875
So we will quantize input values in the range (-10, 9.921875) to (-128, 127).
The input tensor can now be quantized by clipping values to the range min_range to max_range, then multiplying by scale_factor as follows:
The adjusted min_range and max_range are returned as outputs 2 and 3 of this operation. These outputs should be used as the range for any further calculations.
narrow_range (bool) attribute
If true, we do not use the minimum quantized value. i.e. for int8 the quantized output, it would be restricted to the range -127..127 instead of the full -128..127 range. This is provided for compatibility with certain inference backends. (Only applies to SCALED mode)
axis (int) attribute
An optional axis attribute can specify a dimension index of the input tensor, such that quantization ranges will be calculated and applied separately for each slice of the tensor along that dimension. This is useful for per-channel quantization.
If axis is specified, min_range and max_range
if axis=None, per-tensor quantization is performed as normal.
ensure_minimum_range (float) attribute
Ensures the minimum quantization range is at least this value. The legacy default value for this is 0.01, but it is strongly suggested to set it to 0 for new uses.


Concatenates quantized tensors along one dimension.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.quantization.quantized_concat, tf.compat.v1.quantized_concat


Quantizes then dequantizes a tensor. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.quantization.quantize_and_dequantize


Quantizes then dequantizes a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.quantization.quantize_and_dequantize_v2
Updates the gradient definition for quantization that is outside the range to be 0.To simulate the V1 the behavior of tf.quantization.quantize_and_dequantize(...) use tf.grad_pass_through(tf.quantization.quantize_and_dequantize_v2)(...).


Returns the gradient of QuantizeAndDequantizeV4.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.quantize_and_dequantize_v4
This is almost identical to QuantizeAndDequantizeV2, except that it returns a gradient of 1 for inputs that are within the quantization range, or 0 otherwise.


Public API for tf.queue namespace.
class FIFOQueue: A queue implementation that dequeues elements in first-in first-out order.
class PaddingFIFOQueue: A FIFOQueue that supports batching variable-sized tensors by padding.
class PriorityQueue: A queue implementation that dequeues elements in prioritized order.
class QueueBase: Base class for queue implementations.
class RandomShuffleQueue: A queue implementation that dequeues elements in a random order.


A queue implementation that dequeues elements in first-in first-out order.
Inherits From: QueueBase
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.FIFOQueue, tf.compat.v1.queue.FIFOQueue
See tf.queue.QueueBase for a description of the methods on this class.
View source
Closes this queue.
This operation signals that no more elements will be enqueued in the given queue. Subsequent enqueue and enqueue_many operations will fail. Subsequent dequeue and dequeue_many operations will continue to succeed if sufficient elements remain in the queue. Subsequently dequeue and dequeue_many operations that would otherwise block waiting for more elements (if close hadn't been called) will now fail immediately.
If cancel_pending_enqueues is True, all pending requests will also be canceled.
View source
Dequeues one element from this queue.
If the queue is empty when this operation executes, it will block until there is an element to dequeue.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue is empty, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. All of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are less than n elements left, then an OutOfRange exception is raised.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue contains fewer than n elements, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. If the queue has not been closed, all of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are more than 0 but fewer than n elements remaining, then instead of raising a tf.errors.OutOfRangeError like tf.QueueBase.dequeue_many, less than n elements are returned immediately. If the queue is closed and there are 0 elements left in the queue, then a tf.errors.OutOfRangeError is raised just like in dequeue_many. Otherwise the behavior is identical to dequeue_many.
View source
Enqueues one element to this queue.
If the queue is full when this operation executes, it will block until the element has been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Enqueues zero or more elements to this queue.
This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.
If the queue is full when this operation executes, it will block until all of the elements have been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Create a queue using the queue reference from queues[index].
View source
Returns true if queue is closed.
This operation returns true if the queue is closed and false if the queue is open.
View source
Compute the number of elements in this queue.


A FIFOQueue that supports batching variable-sized tensors by padding.
Inherits From: QueueBase
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.PaddingFIFOQueue, tf.compat.v1.io.PaddingFIFOQueue, tf.compat.v1.queue.PaddingFIFOQueue
A PaddingFIFOQueue may contain components with dynamic shape, while also supporting dequeue_many. See the constructor for more details.
See tf.queue.QueueBase for a description of the methods on this class.
View source
Closes this queue.
This operation signals that no more elements will be enqueued in the given queue. Subsequent enqueue and enqueue_many operations will fail. Subsequent dequeue and dequeue_many operations will continue to succeed if sufficient elements remain in the queue. Subsequently dequeue and dequeue_many operations that would otherwise block waiting for more elements (if close hadn't been called) will now fail immediately.
If cancel_pending_enqueues is True, all pending requests will also be canceled.
View source
Dequeues one element from this queue.
If the queue is empty when this operation executes, it will block until there is an element to dequeue.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue is empty, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. All of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are less than n elements left, then an OutOfRange exception is raised.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue contains fewer than n elements, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. If the queue has not been closed, all of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are more than 0 but fewer than n elements remaining, then instead of raising a tf.errors.OutOfRangeError like tf.QueueBase.dequeue_many, less than n elements are returned immediately. If the queue is closed and there are 0 elements left in the queue, then a tf.errors.OutOfRangeError is raised just like in dequeue_many. Otherwise the behavior is identical to dequeue_many.
View source
Enqueues one element to this queue.
If the queue is full when this operation executes, it will block until the element has been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Enqueues zero or more elements to this queue.
This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.
If the queue is full when this operation executes, it will block until all of the elements have been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Create a queue using the queue reference from queues[index].
View source
Returns true if queue is closed.
This operation returns true if the queue is closed and false if the queue is open.
View source
Compute the number of elements in this queue.


A queue implementation that dequeues elements in prioritized order.
Inherits From: QueueBase
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.PriorityQueue, tf.compat.v1.io.PriorityQueue, tf.compat.v1.queue.PriorityQueue
See tf.queue.QueueBase for a description of the methods on this class.
View source
Closes this queue.
This operation signals that no more elements will be enqueued in the given queue. Subsequent enqueue and enqueue_many operations will fail. Subsequent dequeue and dequeue_many operations will continue to succeed if sufficient elements remain in the queue. Subsequently dequeue and dequeue_many operations that would otherwise block waiting for more elements (if close hadn't been called) will now fail immediately.
If cancel_pending_enqueues is True, all pending requests will also be canceled.
View source
Dequeues one element from this queue.
If the queue is empty when this operation executes, it will block until there is an element to dequeue.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue is empty, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. All of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are less than n elements left, then an OutOfRange exception is raised.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue contains fewer than n elements, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. If the queue has not been closed, all of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are more than 0 but fewer than n elements remaining, then instead of raising a tf.errors.OutOfRangeError like tf.QueueBase.dequeue_many, less than n elements are returned immediately. If the queue is closed and there are 0 elements left in the queue, then a tf.errors.OutOfRangeError is raised just like in dequeue_many. Otherwise the behavior is identical to dequeue_many.
View source
Enqueues one element to this queue.
If the queue is full when this operation executes, it will block until the element has been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Enqueues zero or more elements to this queue.
This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.
If the queue is full when this operation executes, it will block until all of the elements have been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Create a queue using the queue reference from queues[index].
View source
Returns true if queue is closed.
This operation returns true if the queue is closed and false if the queue is open.
View source
Compute the number of elements in this queue.


Base class for queue implementations.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.QueueBase, tf.compat.v1.io.QueueBase, tf.compat.v1.queue.QueueBase
A queue is a TensorFlow data structure that stores tensors across multiple steps, and exposes operations that enqueue and dequeue tensors.
Each queue element is a tuple of one or more tensors, where each tuple component has a static dtype, and may have a static shape. The queue implementations support versions of enqueue and dequeue that handle single elements, versions that support enqueuing and dequeuing a batch of elements at once.
See tf.queue.FIFOQueue and tf.queue.RandomShuffleQueue for concrete implementations of this class, and instructions on how to create them.
View source
Closes this queue.
This operation signals that no more elements will be enqueued in the given queue. Subsequent enqueue and enqueue_many operations will fail. Subsequent dequeue and dequeue_many operations will continue to succeed if sufficient elements remain in the queue. Subsequently dequeue and dequeue_many operations that would otherwise block waiting for more elements (if close hadn't been called) will now fail immediately.
If cancel_pending_enqueues is True, all pending requests will also be canceled.
View source
Dequeues one element from this queue.
If the queue is empty when this operation executes, it will block until there is an element to dequeue.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue is empty, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. All of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are less than n elements left, then an OutOfRange exception is raised.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue contains fewer than n elements, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. If the queue has not been closed, all of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are more than 0 but fewer than n elements remaining, then instead of raising a tf.errors.OutOfRangeError like tf.QueueBase.dequeue_many, less than n elements are returned immediately. If the queue is closed and there are 0 elements left in the queue, then a tf.errors.OutOfRangeError is raised just like in dequeue_many. Otherwise the behavior is identical to dequeue_many.
View source
Enqueues one element to this queue.
If the queue is full when this operation executes, it will block until the element has been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Enqueues zero or more elements to this queue.
This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.
If the queue is full when this operation executes, it will block until all of the elements have been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Create a queue using the queue reference from queues[index].
View source
Returns true if queue is closed.
This operation returns true if the queue is closed and false if the queue is open.
View source
Compute the number of elements in this queue.


A queue implementation that dequeues elements in a random order.
Inherits From: QueueBase
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.RandomShuffleQueue, tf.compat.v1.io.RandomShuffleQueue, tf.compat.v1.queue.RandomShuffleQueue
See tf.queue.QueueBase for a description of the methods on this class.
View source
Closes this queue.
This operation signals that no more elements will be enqueued in the given queue. Subsequent enqueue and enqueue_many operations will fail. Subsequent dequeue and dequeue_many operations will continue to succeed if sufficient elements remain in the queue. Subsequently dequeue and dequeue_many operations that would otherwise block waiting for more elements (if close hadn't been called) will now fail immediately.
If cancel_pending_enqueues is True, all pending requests will also be canceled.
View source
Dequeues one element from this queue.
If the queue is empty when this operation executes, it will block until there is an element to dequeue.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue is empty, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. All of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are less than n elements left, then an OutOfRange exception is raised.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed, the queue contains fewer than n elements, and there are no pending enqueue operations that can fulfill this request, tf.errors.OutOfRangeError will be raised. If the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Dequeues and concatenates n elements from this queue.
This operation concatenates queue-element component tensors along the 0th dimension to make a single component tensor. If the queue has not been closed, all of the components in the dequeued tuple will have size n in the 0th dimension.
If the queue is closed and there are more than 0 but fewer than n elements remaining, then instead of raising a tf.errors.OutOfRangeError like tf.QueueBase.dequeue_many, less than n elements are returned immediately. If the queue is closed and there are 0 elements left in the queue, then a tf.errors.OutOfRangeError is raised just like in dequeue_many. Otherwise the behavior is identical to dequeue_many.
View source
Enqueues one element to this queue.
If the queue is full when this operation executes, it will block until the element has been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Enqueues zero or more elements to this queue.
This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.
If the queue is full when this operation executes, it will block until all of the elements have been enqueued.
At runtime, this operation may raise an error if the queue is tf.QueueBase.close before or during its execution. If the queue is closed before this operation runs, tf.errors.CancelledError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is tf.Session.close, tf.errors.CancelledError will be raised.
View source
Create a queue using the queue reference from queues[index].
View source
Returns true if queue is closed.
This operation returns true if the queue is closed and false if the queue is open.
View source
Compute the number of elements in this queue.


Ragged Tensors.
This package defines ops for manipulating ragged tensors (tf.RaggedTensor), which are tensors with non-uniform shapes. In particular, each RaggedTensor has one or more ragged dimensions, which are dimensions whose slices may have different lengths. For example, the inner (column) dimension of rt=[[3, 1, 4, 1], [], [5, 9, 2], [6], []] is ragged, since the column slices (rt[0, :], ..., rt[4, :]) have different lengths. For a more detailed description of ragged tensors, see the tf.RaggedTensor class documentation and the Ragged Tensor Guide.
Arguments that accept RaggedTensors are marked in bold.
boolean_mask(...): Applies a boolean mask to data without flattening the mask dimensions.
constant(...): Constructs a constant RaggedTensor from a nested Python list.
cross(...): Generates feature cross from a list of tensors.
cross_hashed(...): Generates hashed feature cross from a list of tensors.
map_flat_values(...): Applies op to the values of one or more RaggedTensors.
range(...): Returns a RaggedTensor containing the specified sequences of numbers.
row_splits_to_segment_ids(...): Generates the segmentation corresponding to a RaggedTensor row_splits.
segment_ids_to_row_splits(...): Generates the RaggedTensor row_splits corresponding to a segmentation.
stack(...): Stacks a list of rank-R tensors into one rank-(R+1) RaggedTensor.
stack_dynamic_partitions(...): Stacks dynamic partitions of a Tensor or RaggedTensor.


Applies a boolean mask to data without flattening the mask dimensions.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.boolean_mask
Returns a potentially ragged tensor that is formed by retaining the elements in data where the corresponding value in mask is True.
output[a1...aA, i, b1...bB] = data[a1...aA, j, b1...bB]
Where j is the ith True entry of mask[a1...aA].
Note that output preserves the mask dimensions a1...aA; this differs from tf.boolean_mask, which flattens those dimensions.


Constructs a constant RaggedTensor from a nested Python list.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.constant
All scalar values in pylist must have the same nesting depth K, and the returned RaggedTensor will have rank K. If pylist contains no scalar values, then K is one greater than the maximum depth of empty lists in pylist. All scalar values in pylist must be compatible with dtype.


Generates feature cross from a list of tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.cross
The input tensors must have rank=2, and must all have the same number of rows. The result is a RaggedTensor with the same number of rows as the inputs, where result[row] contains a list of all combinations of values formed by taking a single value from each input's corresponding row (inputs[i][row]). Values are combined by joining their strings with 'X'. E.g.:


Generates hashed feature cross from a list of tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.cross_hashed
The input tensors must have rank=2, and must all have the same number of rows. The result is a RaggedTensor with the same number of rows as the inputs, where result[row] contains a list of all combinations of values formed by taking a single value from each input's corresponding row (inputs[i][row]). Values are combined by hashing together their fingerprints. E.g.:


Applies op to the values of one or more RaggedTensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.map_flat_values
Replaces any RaggedTensor in args or kwargs with its flat_values tensor, and then calls op. Returns a RaggedTensor that is constructed from the input RaggedTensors' nested_row_splits and the value returned by the op.
If the input arguments contain multiple RaggedTensors, then they must have identical nested_row_splits.


Returns a RaggedTensor containing the specified sequences of numbers.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.range
Each row of the returned RaggedTensor contains a single sequence:
If start[i] < limits[i] and deltas[i] > 0, then output[i] will be an empty list. Similarly, if start[i] > limits[i] and deltas[i] < 0, then output[i] will be an empty list. This behavior is consistent with the Python range function, but differs from the tf.range op, which returns an error for these cases.
The input tensors starts, limits, and deltas may be scalars or vectors. The vector inputs must all have the same size. Scalar inputs are broadcast to match the size of the vector inputs.


Generates the segmentation corresponding to a RaggedTensor row_splits.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.row_splits_to_segment_ids
Returns an integer vector segment_ids, where segment_ids[i] == j if splits[j] <= i < splits[j+1]. Example:


Generates the RaggedTensor row_splits corresponding to a segmentation.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.segment_ids_to_row_splits
Returns an integer vector splits, where splits[0] = 0 and splits[i] = splits[i-1] + count(segment_ids==i). Example:


Stacks a list of rank-R tensors into one rank-(R+1) RaggedTensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.stack
Given a list of tensors or ragged tensors with the same rank R (R >= axis), returns a rank-R+1 RaggedTensor result such that result[i0...iaxis] is [value[i0...iaxis] for value in values].


Stacks dynamic partitions of a Tensor or RaggedTensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ragged.stack_dynamic_partitions
Returns a RaggedTensor output with num_partitions rows, where the row output[i] is formed by stacking all slices data[j1...jN] such that partitions[j1...jN] = i. Slices of data are stacked in row-major order.
If num_partitions is an int (not a Tensor), then this is equivalent to tf.ragged.stack(tf.dynamic_partition(data, partitions, num_partitions)).


Represents a ragged tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.RaggedTensor
A RaggedTensor is a tensor with one or more ragged dimensions, which are dimensions whose slices may have different lengths. For example, the inner (column) dimension of rt=[[3, 1, 4, 1], [], [5, 9, 2], [6], []] is ragged, since the column slices (rt[0, :], ..., rt[4, :]) have different lengths. Dimensions whose slices all have the same length are called uniform dimensions. The outermost dimension of a RaggedTensor is always uniform, since it consists of a single slice (and so there is no possibility for differing slice lengths).
The total number of dimensions in a RaggedTensor is called its rank, and the number of ragged dimensions in a RaggedTensor is called its ragged-rank. A RaggedTensor's ragged-rank is fixed at graph creation time: it can't depend on the runtime values of Tensors, and can't vary dynamically for different session runs.
Note that the __init__ constructor is private. Please use one of the following methods to construct a RaggedTensor:
Many ops support both Tensors and RaggedTensors. The term "potentially ragged tensor" may be used to refer to a tensor that might be either a Tensor or a RaggedTensor. The ragged-rank of a Tensor is zero.
When documenting the shape of a RaggedTensor, ragged dimensions can be indicated by enclosing them in parentheses. For example, the shape of a 3-D RaggedTensor that stores the fixed-size word embedding for each word in a sentence, for each sentence in a batch, could be written as [num_sentences, (num_words), embedding_size]. The parentheses around (num_words) indicate that dimension is ragged, and that the length of each element list in that dimension may vary for each item.
Internally, a RaggedTensor consists of a concatenated list of values that are partitioned into variable-length rows. In particular, each RaggedTensor consists of:
A values tensor, which concatenates the variable-length rows into a flattened list. For example, the values tensor for [[3, 1, 4, 1], [], [5, 9, 2], [6], []] is [3, 1, 4, 1, 5, 9, 2, 6].
A row_splits vector, which indicates how those flattened values are divided into rows. In particular, the values for row rt[i] are stored in the slice rt.values[rt.row_splits[i]:rt.row_splits[i+1]].
In addition to row_splits, ragged tensors provide support for five other row-partitioning schemes:
row_lengths: a vector with shape [nrows], which specifies the length of each row.
value_rowids and nrows: value_rowids is a vector with shape [nvals], corresponding one-to-one with values, which specifies each value's row index. In particular, the row rt[row] consists of the values rt.values[j] where value_rowids[j]==row. nrows is an integer scalar that specifies the number of rows in the RaggedTensor. (nrows is used to indicate trailing empty rows.)
row_starts: a vector with shape [nrows], which specifies the start offset of each row. Equivalent to row_splits[:-1].
row_limits: a vector with shape [nrows], which specifies the stop offset of each row. Equivalent to row_splits[1:].
uniform_row_length: A scalar tensor, specifying the length of every row. This row-partitioning scheme may only be used if all rows have the same length.
Example: The following ragged tensors are equivalent, and all represent the nested list [[3, 1, 4, 1], [], [5, 9, 2], [6], []].
RaggedTensors with multiple ragged dimensions can be defined by using a nested RaggedTensor for the values tensor. Each nested RaggedTensor adds a single ragged dimension.
The factory function RaggedTensor.from_nested_row_splits may be used to construct a RaggedTensor with multiple ragged dimensions directly, by providing a list of row_splits tensors:
RaggedTensors with uniform inner dimensions can be defined by using a multidimensional Tensor for values.
RaggedTensors with uniform outer dimensions can be defined by using one or more RaggedTensor with a uniform_row_length row-partitioning tensor. For example, a RaggedTensor with shape [2, 2, None] can be constructed with this method from a RaggedTensor values with shape [4, None]:
Note that rt6 only contains one ragged dimension (the innermost dimension). In contrast, if from_row_splits is used to construct a similar RaggedTensor, then that RaggedTensor will have two ragged dimensions:
Uniform and ragged outer dimensions may be interleaved, meaning that a tensor with any combination of ragged and uniform dimensions may be created. For example, a RaggedTensor t4 with shape [3, None, 4, 8, None, 2] could be constructed as follows:
Concretely, if rt.values is a Tensor, then rt.flat_values is rt.values; otherwise, rt.flat_values is rt.values.flat_values.
Conceptually, flat_values is the tensor formed by flattening the outermost dimension and all of the ragged dimensions into a single dimension.
rt.flat_values.shape = [nvals] + rt.shape[rt.ragged_rank + 1:] (where nvals is the number of items in the flattened dimensions).
rt.nested_row_splits is a tuple containing the row_splits tensors for all ragged dimensions in rt, ordered from outermost to innermost. In particular, rt.nested_row_splits = (rt.row_splits,) + value_splits where:
rt.row_splits specifies where the values for each row begin and end in rt.values. In particular, the values for row rt[i] are stored in the slice rt.values[rt.row_splits[i]:rt.row_splits[i+1]].
A RaggedTensor's rows are only considered to be uniform (i.e. non-ragged) if it can be determined statically (at graph construction time) that the rows all have the same length.
rt.values is a potentially ragged tensor formed by flattening the two outermost dimensions of rt into a single dimension.
rt.values.shape = [nvals] + rt.shape[2:] (where nvals is the number of items in the outer two dimensions of rt).
rt.ragged_rank = self.ragged_rank - 1
View source
Returns the tight bounding box shape for this RaggedTensor.
View source
View source
Creates a RaggedTensor from a nested list of row_lengths tensors.
View source
Creates a RaggedTensor from a nested list of row_splits tensors.
View source
Creates a RaggedTensor from a nested list of value_rowids tensors.
View source
Creates a RaggedTensor with rows partitioned by row_lengths.
The returned RaggedTensor corresponds with the python list defined by:
View source
Creates a RaggedTensor with rows partitioned by row_limits.
Equivalent to: from_row_splits(values, concat([0, row_limits])).
View source
Creates a RaggedTensor with rows partitioned by row_splits.
The returned RaggedTensor corresponds with the python list defined by:
View source
Creates a RaggedTensor with rows partitioned by row_starts.
Equivalent to: from_row_splits(values, concat([row_starts, nvals])).
View source
Converts a 2D tf.sparse.SparseTensor to a RaggedTensor.
Each row of the output RaggedTensor will contain the explicit values from the same row in st_input. st_input must be ragged-right. If not it is not ragged-right, then an error will be generated.
Currently, only two-dimensional SparseTensors are supported.
View source
Converts a tf.Tensor into a RaggedTensor.
The set of absent/default values may be specified using a vector of lengths or a padding value (but not both). If lengths is specified, then the output tensor will satisfy output[row] = tensor[row][:lengths[row]]. If 'lengths' is a list of lists or tuple of lists, those lists will be used as nested row lengths. If padding is specified, then any row suffix consisting entirely of padding will be excluded from the returned RaggedTensor. If neither lengths nor padding is specified, then the returned RaggedTensor will have no absent/default values.
View source
Creates a RaggedTensor with rows partitioned by uniform_row_length.
This method can be used to create RaggedTensors with multiple uniform outer dimensions. For example, a RaggedTensor with shape [2, 2, None] can be constructed with this method from a RaggedTensor values with shape [4, None]:
Note that rt1 only contains one ragged dimension (the innermost dimension). In contrast, if from_row_splits is used to construct a similar RaggedTensor, then that RaggedTensor will have two ragged dimensions:
result.rank = values.rank + 1. result.ragged_rank = values.ragged_rank + 1.
View source
Creates a RaggedTensor with rows partitioned by value_rowids.
The returned RaggedTensor corresponds with the python list defined by:
View source
The statically known shape of this ragged tensor.
Alias for shape property.
View source
Merges outer_axis...inner_axis into a single dimension.
Returns a copy of this RaggedTensor with the specified range of dimensions flattened into a single dimension, with elements in row-major order.
To mimic the behavior of np.flatten (which flattens all dimensions), use rt.merge_dims(0, -1). To mimic the behavior oftf.layers.Flatten(which flattens all dimensions except the outermost batch dimension), usert.merge_dims(1, -1)`.
View source
Returns a tuple containing the row_lengths for all ragged dimensions.
rt.nested_row_lengths() is a tuple containing the row_lengths tensors for all ragged dimensions in rt, ordered from outermost to innermost.
View source
Returns a tuple containing the value_rowids for all ragged dimensions.
rt.nested_value_rowids is a tuple containing the value_rowids tensors for all ragged dimensions in rt, ordered from outermost to innermost. In particular, rt.nested_value_rowids = (rt.value_rowids(),) + value_ids where:
View source
Returns the number of rows in this ragged tensor.
I.e., the size of the outermost dimension of the tensor.
View source
Returns a numpy array with the values for this RaggedTensor.
Requires that this RaggedTensor was constructed in eager execution mode.
Ragged dimensions are encoded using numpy arrays with dtype=object and rank=1, where each element is a single row.
In the following example, the value returned by RaggedTensor.numpy() contains three numpy array objects: one for each row (with rank=1 and dtype=int64), and one to combine them (with rank=1 and dtype=object):
Uniform dimensions are encoded using multidimensional numpy arrays. In the following example, the value returned by RaggedTensor.numpy() contains a single numpy array object, with rank=2 and dtype=int64:
View source
Returns the lengths of the rows in this ragged tensor.
rt.row_lengths()[i] indicates the number of values in the ith row of rt.
View source
Returns the limit indices for rows in this ragged tensor.
These indices specify where the values for each row end in self.values. rt.row_limits(self) is equal to rt.row_splits[:-1].
View source
Returns the start indices for rows in this ragged tensor.
These indices specify where the values for each row begin in self.values. rt.row_starts() is equal to rt.row_splits[:-1].
View source
Returns a nested Python list with the values for this RaggedTensor.
Requires that rt was constructed in eager execution mode.
View source
Converts this RaggedTensor into a tf.sparse.SparseTensor.
View source
Converts this RaggedTensor into a tf.Tensor.
If shape is specified, then the result is padded and/or truncated to the specified shape.
View source
Returns the row indices for the values in this ragged tensor.
rt.value_rowids() corresponds one-to-one with the outermost dimension of rt.values, and specifies the row containing each value. In particular, the row rt[row] consists of the values rt.values[j] where rt.value_rowids()[j] == row.
View source
Returns a copy of self with flat_values replaced by new_value.
Preserves cached row-partitioning tensors such as self.cached_nrows and self.cached_value_rowids if they have values.
View source
Returns a copy of this RaggedTensor with the given row_splits dtype.
For RaggedTensors with multiple ragged dimensions, the row_splits for all nested RaggedTensor objects are cast to the given dtype.
View source
Returns a copy of self with values replaced by new_value.
Preserves cached row-partitioning tensors such as self.cached_nrows and self.cached_value_rowids if they have values.
View source
Computes the absolute value of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Given a tensor x of complex numbers, this operation returns a tensor of type float32 or float64 that is the absolute value of each element in x. For a complex number \(a + bj\), its absolute value is computed as \(\sqrt{a^2 + b^2}\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)
Returns x + y element-wise.
Given two input tensors, the tf.add operation computes the sum for every element in the tensor.
Both input and output have a range (-inf, inf).
View source
Logical AND function.
The operation works for the following input types:
View source
Dummy method to prevent a RaggedTensor from being used as a Python bool.
View source
Divides x / y elementwise (using Python 2 division operator semantics). (deprecated)
This function divides x and y, forcing Python 2 semantics. That is, if x and y are both integers then the result will be an integer. This is in contrast to Python 3, where division with / is always a float while division with // is always an integer.
View source
The operation invoked by the Tensor.eq operator.
Compares two tensors element-wise for equality if they are broadcast-compatible; or returns False if they are not broadcast-compatible. (Note that this behavior differs from tf.math.equal, which raises an exception if the two tensors are not broadcast-compatible.)
This method is exposed in TensorFlow's API so that library developers can register dispatching for Tensor.eq to allow it to handle custom composite tensors & other custom objects.
The API symbol is not intended to be called by users directly and does appear in TensorFlow's generated documentation.
View source
Divides x / y elementwise, rounding toward the most negative integer.
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.
x and y must have the same type, and the result will have the same type as well.
Returns the truth value of (x >= y) element-wise.
View source
Returns the specified piece of this RaggedTensor.
Supports multidimensional indexing and slicing, with one restriction: indexing into a ragged inner dimension is not allowed. This case is problematic because the indicated value may exist in some rows but not others. In such cases, it's not obvious whether we should (1) report an IndexError; (2) use a default value; or (3) skip that value and return a tensor with fewer rows than we started with. Following the guiding principles of Python ("In the face of ambiguity, refuse the temptation to guess"), we simply disallow this operation.
Returns the truth value of (x > y) element-wise.
Returns the truth value of NOT x element-wise.
Returns the truth value of (x <= y) element-wise.
Returns the truth value of (x < y) element-wise.
Returns element-wise remainder of division. When x < 0 xor y < 0 is
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.
View source
Returns an element-wise x * y.
Since tf.math.multiply will convert its arguments to Tensors, you can also pass in non-Tensor arguments:
If x.shape is not thes same as y.shape, they will be broadcast to a compatible shape. (More about broadcasting here.)
A Tensor. Has the same type as x.
View source
The operation invoked by the Tensor.ne operator.
Compares two tensors element-wise for inequality if they are broadcast-compatible; or returns True if they are not broadcast-compatible. (Note that this behavior differs from tf.math.not_equal, which raises an exception if the two tensors are not broadcast-compatible.)
This method is exposed in TensorFlow's API so that library developers can register dispatching for Tensor.ne to allow it to handle custom composite tensors & other custom objects.
The API symbol is not intended to be called by users directly and does appear in TensorFlow's generated documentation.
Computes numerical negative value element-wise.
I.e., \(y = -x\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.negative(x.values, ...), x.dense_shape)
View source
Dummy method to prevent a RaggedTensor from being used as a Python bool.
Returns the truth value of x OR y element-wise.
View source
Computes the power of one value to another.
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example:
Returns x + y element-wise.
Given two input tensors, the tf.add operation computes the sum for every element in the tensor.
Both input and output have a range (-inf, inf).
View source
Logical AND function.
The operation works for the following input types:
View source
Divides x / y elementwise (using Python 2 division operator semantics). (deprecated)
This function divides x and y, forcing Python 2 semantics. That is, if x and y are both integers then the result will be an integer. This is in contrast to Python 3, where division with / is always a float while division with // is always an integer.
View source
Divides x / y elementwise, rounding toward the most negative integer.
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.
x and y must have the same type, and the result will have the same type as well.
Returns element-wise remainder of division. When x < 0 xor y < 0 is
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.
View source
Returns an element-wise x * y.
Since tf.math.multiply will convert its arguments to Tensors, you can also pass in non-Tensor arguments:
If x.shape is not thes same as y.shape, they will be broadcast to a compatible shape. (More about broadcasting here.)
A Tensor. Has the same type as x.
Returns the truth value of x OR y element-wise.
View source
Computes the power of one value to another.
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example:
View source
Returns x - y element-wise.
View source
Divides x / y elementwise (using Python 3 division operator semantics).
This function forces Python 3 division operator semantics where all integer arguments are cast to floating types first. This op is generated by normal x / y division in Python 3 and in Python 2.7 with from __future__ import division. If you want integer division that rounds down, use x // y or tf.math.floordiv.
x and y must have the same numeric type. If the inputs are floating point, the output will have the same type. If the inputs are integral, the inputs are cast to float32 for int8 and int16 and float64 for int32 and int64 (matching the behavior of Numpy).
View source
Logical XOR function.
x ^ y = (x | y) & ~(x & y)
The operation works for the following input types:
View source
Returns x - y element-wise.
View source
Divides x / y elementwise (using Python 3 division operator semantics).
This function forces Python 3 division operator semantics where all integer arguments are cast to floating types first. This op is generated by normal x / y division in Python 3 and in Python 2.7 with from __future__ import division. If you want integer division that rounds down, use x // y or tf.math.floordiv.
x and y must have the same numeric type. If the inputs are floating point, the output will have the same type. If the inputs are integral, the inputs are cast to float32 for int8 and int16 and float64 for int32 and int64 (matching the behavior of Numpy).
View source
Logical XOR function.
x ^ y = (x | y) & ~(x & y)
The operation works for the following input types:


Type specification for a tf.RaggedTensor.
Inherits From: TypeSpec
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.RaggedTensorSpec
Defaults to shape.ndims - 1.
In particular, all values that are compatible with this TypeSpec must be an instance of this type.
View source
View source
Returns true if spec_or_value is compatible with this TypeSpec.
View source
Returns the most specific TypeSpec compatible with self and other.
View source
Return self==value.
View source
Return self!=value.


Public API for tf.random namespace.
experimental module: Public API for tf.random.experimental namespace.
class Algorithm: An enumeration.
class Generator: Random-number generator.
all_candidate_sampler(...): Generate the set of all classes.
categorical(...): Draws samples from a categorical distribution.
create_rng_state(...): Creates a RNG state from an integer or a vector.
fixed_unigram_candidate_sampler(...): Samples a set of classes using the provided (fixed) base distribution.
gamma(...): Draws shape samples from each of the given Gamma distribution(s).
get_global_generator(...): Retrieves the global generator.
learned_unigram_candidate_sampler(...): Samples a set of classes from a distribution learned during training.
log_uniform_candidate_sampler(...): Samples a set of classes using a log-uniform (Zipfian) base distribution.
normal(...): Outputs random values from a normal distribution.
poisson(...): Draws shape samples from each of the given Poisson distribution(s).
set_global_generator(...): Replaces the global generator with another Generator object.
set_seed(...): Sets the global random seed.
shuffle(...): Randomly shuffles a tensor along its first dimension.
stateless_binomial(...): Outputs deterministic pseudorandom values from a binomial distribution.
stateless_categorical(...): Draws deterministic pseudorandom samples from a categorical distribution.
stateless_gamma(...): Outputs deterministic pseudorandom values from a gamma distribution.
stateless_normal(...): Outputs deterministic pseudorandom values from a normal distribution.
stateless_parameterized_truncated_normal(...): Outputs random values from a truncated normal distribution.
stateless_poisson(...): Outputs deterministic pseudorandom values from a Poisson distribution.
stateless_truncated_normal(...): Outputs deterministic pseudorandom values, truncated normally distributed.
stateless_uniform(...): Outputs deterministic pseudorandom values from a uniform distribution.
truncated_normal(...): Outputs random values from a truncated normal distribution.
uniform(...): Outputs random values from a uniform distribution.
uniform_candidate_sampler(...): Samples a set of classes using a uniform base distribution.


An enumeration.
Main aliases
tf.random.experimental.Algorithm
See Migration guide for more details.
tf.compat.v1.random.Algorithm, tf.compat.v1.random.experimental.Algorithm


Generate the set of all classes.
Main aliases
tf.nn.all_candidate_sampler
See Migration guide for more details.
tf.compat.v1.nn.all_candidate_sampler, tf.compat.v1.random.all_candidate_sampler
Deterministically generates and returns the set of all possible classes. For testing purposes. There is no need to use this, since you might as well use full softmax or full logistic regression.


Draws samples from a categorical distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.categorical


Creates a RNG state from an integer or a vector.
Main aliases
tf.random.experimental.create_rng_state
See Migration guide for more details.
tf.compat.v1.random.create_rng_state, tf.compat.v1.random.experimental.create_rng_state


Public API for tf.random.experimental namespace.
class Algorithm: An enumeration.
class Generator: Random-number generator.
create_rng_state(...): Creates a RNG state from an integer or a vector.
get_global_generator(...): Retrieves the global generator.
set_global_generator(...): Replaces the global generator with another Generator object.
stateless_fold_in(...): Folds in data to an RNG seed to form a new RNG seed.
stateless_split(...): Splits an RNG seed into num new seeds by adding a leading axis.


Folds in data to an RNG seed to form a new RNG seed.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.experimental.stateless_fold_in
For example, in a distributed-training setting, suppose we have a master seed and a replica ID. We want to fold the replica ID into the master seed to form a "replica seed" to be used by that replica later on, so that different replicas will generate different random numbers but the reproducibility of the whole system can still be controlled by the master seed:


Splits an RNG seed into num new seeds by adding a leading axis.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.experimental.stateless_split


Samples a set of classes using the provided (fixed) base distribution.
Main aliases
tf.nn.fixed_unigram_candidate_sampler
See Migration guide for more details.
tf.compat.v1.nn.fixed_unigram_candidate_sampler, tf.compat.v1.random.fixed_unigram_candidate_sampler
This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max).
The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution.
The base distribution is read from a file or passed in as an in-memory array. There is also an option to skew the distribution by applying a distortion power to the weights.
In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.


Draws shape samples from each of the given Gamma distribution(s).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.gamma, tf.compat.v1.random_gamma
alpha is the shape parameter describing the distribution(s), and beta is the inverse scale parameter(s).
The samples are differentiable w.r.t. alpha and beta. The derivatives are computed using the approach described in (Figurnov et al., 2018).
Implicit Reparameterization Gradients: Figurnov et al., 2018 (pdf)


Random-number generator.
Main aliases
tf.random.experimental.Generator
See Migration guide for more details.
tf.compat.v1.random.Generator, tf.compat.v1.random.experimental.Generator
Creating a generator from a seed:
Creating a generator from a non-deterministic state:
All the constructors allow explicitly choosing an Random-Number-Generation (RNG) algorithm. Supported algorithms are "philox" and "threefry". For example:
CPU, GPU and TPU with the same algorithm and seed will generate the same integer random numbers. Float-point results (such as the output of normal) may have small numerical discrepancies between different devices.
This class uses a tf.Variable to manage its internal state. Every time random numbers are generated, the state of the generator will change. For example:
The shape of the state is algorithm-specific.
There is also a global generator:
For a counter-base RNG algorithm such as Philox and ThreeFry (as described in paper 'Parallel Random Numbers: As Easy as 1, 2, 3' [https://www.thesalmons.org/john/random123/papers/random123sc11.pdf]), the RNG state consists of two parts: counter and key. The output is generated via the formula: output=hash(key, counter), i.e. a hashing of the counter parametrized by the key. Two RNGs with two different keys can be thought as generating two independent random-number streams (a stream is formed by increasing the counter).
View source
Outputs random values from a binomial distribution.
The generated values follow a binomial distribution with specified count and probability of success parameters.
View source
Creates a generator from a key and a counter.
This constructor only applies if the algorithm is a counter-based algorithm. See method key for the meaning of "key" and "counter".
View source
Creates a generator by non-deterministically initializing its state.
The source of the non-determinism will be platform- and time-dependent.
View source
Creates a generator from a seed.
A seed is a 1024-bit unsigned integer represented either as a Python integer or a vector of integers. Seeds shorter than 1024-bit will be padded. The padding, the internal structure of a seed and the way a seed is converted to a state are all opaque (unspecified). The only semantics specification of seeds is that two different seeds are likely to produce two independent generators (but no guarantee).
View source
Creates a generator from a state.
See __init__ for description of state and alg.
View source
Generates seeds for stateless random ops.
View source
Outputs random values from a normal distribution.
View source
Resets the generator by a new state.
See __init__ for the meaning of "state".
View source
Resets the generator by a new key-counter pair.
See from_key_counter for the meaning of "key" and "counter".
View source
Resets the generator by a new seed.
See from_seed for the meaning of "seed".
View source
Advance the counter of a counter-based RNG.
View source
Returns a list of independent Generator objects.
Two generators are independent of each other in the sense that the random-number streams they generate don't have statistically detectable correlations. The new generators are also independent of the old one. The old generator's state will be changed (like other random-number generating methods), so two calls of split will return different new generators.
The new generators will be put on the current device (possible different from the old generator's), for example:
View source
Outputs random values from a truncated normal distribution.
The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked.
View source
Outputs random values from a uniform distribution.
The generated values follow a uniform distribution in the range [minval, maxval). The lower bound minval is included in the range, while the upper bound maxval is excluded. (For float numbers especially low-precision types like bfloat16, because of rounding, the result may sometimes include maxval.)
For floats, the default range is [0, 1). For ints, at least maxval must be specified explicitly.
In the integer case, the random integers are slightly biased unless maxval - minval is an exact power of two. The bias is small for values of maxval - minval significantly smaller than the range of the output (either 2**32 or 2**64).
For full-range random integers, pass minval=None and maxval=None with an integer dtype (for integer dtypes, minval and maxval must be both None or both not None).
View source
Uniform distribution on an integer type's entire range.
This method is the same as setting minval and maxval to None in the uniform method.


Retrieves the global generator.
Main aliases
tf.random.experimental.get_global_generator
See Migration guide for more details.
tf.compat.v1.random.experimental.get_global_generator, tf.compat.v1.random.get_global_generator
This function will create the global generator the first time it is called, and the generator will be placed at the default device at that time, so one needs to be careful when this function is first called. Using a generator placed on a less-ideal device will incur performance regression.


Samples a set of classes from a distribution learned during training.
Main aliases
tf.nn.learned_unigram_candidate_sampler
See Migration guide for more details.
tf.compat.v1.nn.learned_unigram_candidate_sampler, tf.compat.v1.random.learned_unigram_candidate_sampler
This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max).
The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution.
The base distribution for this operation is constructed on the fly during training. It is a unigram distribution over the target classes seen so far during training. Every integer in [0, range_max) begins with a weight of 1, and is incremented by 1 each time it is seen as a target class. The base distribution is not saved to checkpoints, so it is reset when the model is reloaded.
In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.


Samples a set of classes using a log-uniform (Zipfian) base distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.log_uniform_candidate_sampler, tf.compat.v1.random.log_uniform_candidate_sampler
This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max).
The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution.
The base distribution for this operation is an approximately log-uniform or Zipfian distribution:
P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)
This sampler is useful when the target classes approximately follow such a distribution - for example, if the classes represent words in a lexicon sorted in decreasing order of frequency. If your classes are not ordered by decreasing frequency, do not use this op.
In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.


Outputs random values from a normal distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.normal, tf.compat.v1.random_normal
Example that generates a new set of random values every time:
Example that outputs a reproducible result:
In this case, we are setting both the global and operation-level seed to ensure this result is reproducible. See tf.random.set_seed for more information.


Draws shape samples from each of the given Poisson distribution(s).
lam is the rate parameter describing the distribution(s).


Replaces the global generator with another Generator object.
Main aliases
tf.random.experimental.set_global_generator
See Migration guide for more details.
tf.compat.v1.random.experimental.set_global_generator, tf.compat.v1.random.set_global_generator
This function creates a new Generator object (and the Variable object within), which does not work well with tf.function because (1) tf.function puts restrictions on Variable creation thus reset_global_generator can't be freely used inside tf.function; (2) redirecting a global variable to a new object is problematic with tf.function because the old object may be captured by a 'tf.function'ed function and still be used by it. A 'tf.function'ed function only keeps weak references to variables, so deleting a variable and then calling that function again may raise an error, as demonstrated by random_test.py/RandomTest.testResetGlobalGeneratorBadWithDefun .


Sets the global random seed.
Operations that rely on a random seed actually derive it from two seeds: the global and operation-level seeds. This sets the global seed.
Its interactions with operation-level seeds is as follows:
To illustrate the user-visible effects, consider these examples:
If neither the global seed nor the operation seed is set, we get different results for every call to the random op and every re-run of the program:
(now close the program and run it again)
If the global seed is set but the operation seed is not set, we get different results for every call to the random op, but the same sequence for every re-run of the program:
(now close the program and run it again)
The reason we get 'A2' instead 'A1' on the second call of tf.random.uniform above is because the second call uses a different operation seed.
Note that tf.function acts like a re-run of a program in this case. When the global seed is set but operation seeds are not set, the sequence of random numbers are the same for each tf.function. For example:
If the operation seed is set, we get different results for every call to the random op, but the same sequence for every re-run of the program:
(now close the program and run it again)
The reason we get 'A2' instead 'A1' on the second call of tf.random.uniform above is because the same tf.random.uniform kernel (i.e. internal representation) is used by TensorFlow for all calls of it with the same arguments, and the kernel maintains an internal counter which is incremented every time it is executed, generating different results.
Calling tf.random.set_seed will reset any such counters:
When multiple identical random ops are wrapped in a tf.function, their behaviors change because the ops no long share the same counter. For example:
The second call of foo returns '(A2, A2)' instead of '(A1, A1)' because tf.random.uniform maintains an internal counter. If you want foo to return '(A1, A1)' every time, use the stateless random ops such as tf.random.stateless_uniform. Also see tf.random.experimental.Generator for a new set of stateful random ops that use external variables to manage their states.


Randomly shuffles a tensor along its first dimension.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.shuffle, tf.compat.v1.random_shuffle
The tensor is shuffled along dimension 0, such that each value[j] is mapped to one and only one output[i]. For example, a mapping that might occur for a 3x2 tensor is:


Outputs deterministic pseudorandom values from a binomial distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_binomial
The generated values follow a binomial distribution with specified count and probability of success parameters.
This is a stateless version of tf.random.Generator.binomial: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.


Draws deterministic pseudorandom samples from a categorical distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_categorical
This is a stateless version of tf.categorical: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.


Outputs deterministic pseudorandom values from a gamma distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_gamma
The generated values follow a gamma distribution with specified concentration (alpha) and inverse scale (beta) parameters.
This is a stateless version of tf.random.gamma: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.
A slight difference exists in the interpretation of the shape parameter between stateless_gamma and gamma: in gamma, the shape is always prepended to the shape of the broadcast of alpha with beta; whereas in stateless_gamma the shape parameter must always encompass the shapes of each of alpha and beta (which must broadcast together to match the trailing dimensions of shape).
The samples are differentiable w.r.t. alpha and beta. The derivatives are computed using the approach described in (Figurnov et al., 2018).


Outputs deterministic pseudorandom values from a normal distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_normal
This is a stateless version of tf.random.normal: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.


Outputs random values from a truncated normal distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_parameterized_truncated_normal
The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked.
Sample from a Truncated normal, with deferring shape parameters that broadcast.


Outputs deterministic pseudorandom values from a Poisson distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_poisson
The generated values follow a Poisson distribution with specified rate parameter.
This is a stateless version of tf.random.poisson: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware, but may change between versions of TensorFlow or on non-CPU/GPU hardware.
A slight difference exists in the interpretation of the shape parameter between stateless_poisson and poisson: in poisson, the shape is always prepended to the shape of lam; whereas in stateless_poisson the shape of lam must match the trailing dimensions of shape.


Outputs deterministic pseudorandom values, truncated normally distributed.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_truncated_normal
This is a stateless version of tf.random.truncated_normal: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.
The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked.


Outputs deterministic pseudorandom values from a uniform distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.stateless_uniform
This is a stateless version of tf.random.uniform: if run twice with the same seeds and shapes, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.
The generated values follow a uniform distribution in the range [minval, maxval). The lower bound minval is included in the range, while the upper bound maxval is excluded.
For floats, the default range is [0, 1). For ints, at least maxval must be specified explicitly.
In the integer case, the random integers are slightly biased unless maxval - minval is an exact power of two. The bias is small for values of maxval - minval significantly smaller than the range of the output (either 2**32 or 2**64).
For full-range (i.e. inclusive of both max and min) random integers, pass minval=None and maxval=None with an integer dtype. For an integer dtype either both minval and maxval must be None or neither may be None. For example:


Outputs random values from a truncated normal distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.truncated_normal, tf.compat.v1.truncated_normal
The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked.


Outputs random values from a uniform distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.random.uniform, tf.compat.v1.random_uniform
The generated values follow a uniform distribution in the range [minval, maxval). The lower bound minval is included in the range, while the upper bound maxval is excluded.
For floats, the default range is [0, 1). For ints, at least maxval must be specified explicitly.
In the integer case, the random integers are slightly biased unless maxval - minval is an exact power of two. The bias is small for values of maxval - minval significantly smaller than the range of the output (either 2**32 or 2**64).
The seed argument produces a deterministic sequence of tensors across multiple calls. To repeat that sequence, use tf.random.set_seed:
Without tf.random.set_seed but with a seed argument is specified, small changes to function graphs or previously executed operations will change the returned value. See tf.random.set_seed for details.


Samples a set of classes using a uniform base distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.nn.uniform_candidate_sampler, tf.compat.v1.random.uniform_candidate_sampler
This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max).
The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution.
The base distribution for this operation is the uniform distribution over the range of integers [0, range_max).
In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.


Initializer that generates tensors with a normal distribution.
Initializers allow you to pre-specify an initialization strategy, encoded in the Initializer object, without knowing the shape and dtype of the variable being initialized.
View source
Instantiates an initializer from a configuration dictionary.
View source
Returns the configuration of the initializer as a JSON-serializable dict.
View source
Returns a tensor object initialized as specified by the initializer.


Initializer that generates tensors with a uniform distribution.
Initializers allow you to pre-specify an initialization strategy, encoded in the Initializer object, without knowing the shape and dtype of the variable being initialized.
View source
Instantiates an initializer from a configuration dictionary.
View source
Returns the configuration of the initializer as a JSON-serializable dict.
View source
Returns a tensor object initialized as specified by the initializer.


Creates a sequence of numbers.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.range
Creates a sequence of numbers that begins at start and extends by increments of delta up to but not including limit.
The dtype of the resulting tensor is inferred from the inputs unless it is provided explicitly.
Like the Python builtin range, start defaults to 0, so that range(n) = range(0, n).
Equivalent to np.arange


Returns the rank of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.rank
See also tf.shape.
Returns a 0-D int32 Tensor representing the rank of input.
Equivalent to np.ndim


Raise a exception to abort the process when called.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Abort
If exit_without_error is true, the process will exit normally, otherwise it will exit with a SIGABORT signal.
Returns nothing but an exception.


Computes the absolute value of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Abs
Given a tensor x, this operation returns a tensor containing the absolute value of each element in x. For example, if x is an input element and y is an output element, this operation computes \(y = |x|\).


Returns the element-wise sum of a list of tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AccumulateNV2
tf.accumulate_n_v2 performs the same operation as tf.add_n, but does not wait for all of its inputs to be ready before beginning to sum. This can save memory if inputs are ready at different times, since minimum temporary storage is proportional to the output size rather than the inputs size.
Unlike the original accumulate_n, accumulate_n_v2 is differentiable.
Returns a Tensor of same shape and type as the elements of inputs.


Applies a gradient to a given accumulator.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AccumulatorApplyGradient
Does not add if local_step is lesser than the accumulator's global_step.


Returns the number of gradients aggregated in the given accumulators.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AccumulatorNumAccumulated


Updates the accumulator with a new value for global_step.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AccumulatorSetGlobalStep
Logs warning if the accumulator's value is already higher than new_global_step.


Extracts the average gradient in the given ConditionalAccumulator.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AccumulatorTakeGradient
The op blocks until sufficient (i.e., more than num_required) gradients have been accumulated. If the accumulator has already aggregated more than num_required gradients, it returns the average of the accumulated gradients. Also automatically increments the recorded global_step in the accumulator by 1, and resets the aggregate to 0.


Computes acos of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Acos
Provided an input tensor, the tf.math.acos operation returns the inverse cosine of each element of the tensor. If y = tf.math.cos(x) then, x = tf.math.acos(y).
Input range is [-1, 1] and the output has a range of [0, pi].


Computes inverse hyperbolic cosine of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Acosh
Given an input tensor, the function computes inverse hyperbolic cosine of every element. Input range is [1, inf]. It returns nan if the input lies outside the range.


Returns x + y element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Add
Given two input tensors, the tf.add operation computes the sum for every element in the tensor.
Both input and output have a range (-inf, inf).


Add an N-minibatch SparseTensor to a SparseTensorsMap, return N handles.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AddManySparseToTensorsMap
A SparseTensor of rank R is represented by three tensors: sparse_indices, sparse_values, and sparse_shape, where
sparse_indices.shape[1] == sparse_shape.shape[0] == R
An N-minibatch of SparseTensor objects is represented as a SparseTensor having a first sparse_indices column taking values between [0, N), where the minibatch size N == sparse_shape[0].
The input SparseTensor must have rank R greater than 1, and the first dimension is treated as the minibatch dimension. Elements of the SparseTensor must be sorted in increasing order of this first dimension. The stored SparseTensor objects pointed to by each row of the output sparse_handles will have rank R-1.
The SparseTensor values can then be read out as part of a minibatch by passing the given keys as vector elements to TakeManySparseFromTensorsMap. To ensure the correct SparseTensorsMap is accessed, ensure that the same container and shared_name are passed to that Op. If no shared_name is provided here, instead use the name of the Operation created by calling AddManySparseToTensorsMap as the shared_name passed to TakeManySparseFromTensorsMap. Ensure the Operations are colocated.


Add all input tensors element wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AddN
Inputs must be of same size and shape.


Add a SparseTensor to a SparseTensorsMap return its handle.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AddSparseToTensorsMap
A SparseTensor is represented by three tensors: sparse_indices, sparse_values, and sparse_shape.
This operator takes the given SparseTensor and adds it to a container object (a SparseTensorsMap). A unique key within this container is generated in the form of an int64, and this is the value that is returned.
The SparseTensor can then be read out as part of a minibatch by passing the key as a vector element to TakeManySparseFromTensorsMap. To ensure the correct SparseTensorsMap is accessed, ensure that the same container and shared_name are passed to that Op. If no shared_name is provided here, instead use the name of the Operation created by calling AddSparseToTensorsMap as the shared_name passed to TakeManySparseFromTensorsMap. Ensure the Operations are colocated.


Returns x + y element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AddV2


Deprecated. Disallowed in GraphDef version >= 2.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AdjustContrast


Adjust the contrast of one or more images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AdjustContrastv2
images is a tensor of at least 3 dimensions. The last 3 dimensions are interpreted as [height, width, channels]. The other dimensions only represent a collection of images, such as [batch, height, width, channels].
Contrast is adjusted independently for each channel of each image.
For each channel, the Op first computes the mean of the image pixels in the channel and then adjusts each component of each pixel to (x - mean) * contrast_factor + mean.


Adjust the hue of one or more images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AdjustHue
images is a tensor of at least 3 dimensions. The last dimension is interpreted as channels, and must be three.
The input image is considered in the RGB colorspace. Conceptually, the RGB colors are first mapped into HSV. A delta is then applied all the hue values, and then remapped back to RGB colorspace.


Adjust the saturation of one or more images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AdjustSaturation
images is a tensor of at least 3 dimensions. The last dimension is interpreted as channels, and must be three.
The input image is considered in the RGB colorspace. Conceptually, the RGB colors are first mapped into HSV. A scale is then applied all the saturation values, and then remapped back to RGB colorspace.


Computes the "logical and" of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.All
Reduces input along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained with length 1.


Generates labels for candidate sampling with a learned unigram distribution.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AllCandidateSampler
See explanations of candidate sampling and the data formats at go/candidate-sampling.
For each batch, this op picks a single set of sampled candidate labels.
The advantages of sampling candidates per-batch are simplicity and the possibility of efficient dense matrix multiplication. The disadvantage is that the sampled candidates must be chosen independently of the context and of the true labels.


An Op to exchange data across TPU replicas.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AllToAll
On each replica, the input is split into split_count blocks along split_dimension and send to the other replicas given group_assignment. After receiving split_count - 1 blocks from other replicas, we concatenate the blocks along concat_dimension as the output.
For example, suppose there are 2 TPU replicas: replica 0 receives input: [[A, B]] replica 1 receives input: [[C, D]]
group_assignment=[[0, 1]] concat_dimension=0 split_dimension=1 split_count=2
replica 0's output: [[A], [C]] replica 1's output: [[B], [D]]


Returns the argument of a complex number.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Angle
Given a tensor input of complex numbers, this operation returns a tensor of type float that is the argument of each element in input. All elements in input must be complex numbers of the form \(a + bj\), where a is the real part and b is the imaginary part.
The argument returned by this operation is of the form \(atan2(b, a)\).
Equivalent to np.angle.


A container for an iterator resource.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousIterator


A container for an iterator resource.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousIteratorV2


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousMemoryCache


A container for a multi device iterator resource.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousMultiDeviceIterator


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousRandomSeedGenerator


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.AnonymousSeedGenerator


Computes the "logical or" of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.Any
Reduces input along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained with length 1.


Update '*var' according to the adadelta scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdadelta
accum = rho() * accum + (1 - rho()) * grad.square(); update = (update_accum + epsilon).sqrt() * (accum + epsilon()).rsqrt() * grad; update_accum = rho() * update_accum + (1 - rho()) * update.square(); var -= update;


Update '*var' according to the adagrad scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdagrad
accum += grad * grad var -= lr * grad * (1 / sqrt(accum))


Update '*var' according to the proximal adagrad scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdagradDA


Update '*var' according to the adagrad scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdagradV2
accum += grad * grad var -= lr * grad * (1 / sqrt(accum))


Update '*var' according to the Adam algorithm.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdam


Update '*var' according to the AdaMax algorithm.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAdaMax
mt <- beta1 * m{t-1} + (1 - beta1) * g vt <- max(beta2 * v{t-1}, abs(g)) variable <- variable - learning_rate / (1 - beta1^t) * m_t / (v_t + epsilon)


Update '*var' according to the AddSign update.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyAddSign
mt <- beta1 * m{t-1} + (1 - beta1) * g update <- (alpha + sign_decay * sign(g) *sign(m)) * g variable <- variable - lr_t * update


Update '*var' according to the centered RMSProp algorithm.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyCenteredRMSProp
The centered RMSProp algorithm uses an estimate of the centered second moment (i.e., the variance) for normalization, as opposed to regular RMSProp, which uses the (uncentered) second moment. This often helps with training, but is slightly more expensive in terms of computation and memory.
Note that in dense implementation of this algorithm, mg, ms, and mom will update even if the grad is zero, but in this sparse implementation, mg, ms, and mom will not update in iterations during which the grad is zero.
mean_square = decay * mean_square + (1-decay) * gradient ** 2 mean_grad = decay * mean_grad + (1-decay) * gradient
Delta = learning_rate * gradient / sqrt(mean_square + epsilon - mean_grad ** 2)
mg <- rho * mg{t-1} + (1-rho) * grad ms <- rho * ms{t-1} + (1-rho) * grad * grad mom <- momentum * mom_{t-1} + lr * grad / sqrt(ms - mg * mg + epsilon) var <- var - mom


Update '*var' according to the Ftrl-proximal scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyFtrl
accum_new = accum + grad * grad linear += grad - (accum_new^(-lr_power) - accum^(-lr_power)) / lr * var quadratic = 1.0 / (accum_new^(lr_power) * lr) + 2 * l2 var = (sign(linear) * l1 - linear) / quadratic if |linear| > l1 else 0.0 accum = accum_new


Update '*var' according to the Ftrl-proximal scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyFtrlV2
grad_with_shrinkage = grad + 2 * l2_shrinkage * var accum_new = accum + grad * grad linear += grad_with_shrinkage - (accum_new^(-lr_power) - accum^(-lr_power)) / lr * var quadratic = 1.0 / (accum_new^(lr_power) * lr) + 2 * l2 var = (sign(linear) * l1 - linear) / quadratic if |linear| > l1 else 0.0 accum = accum_new


Update '*var' by subtracting 'alpha' * 'delta' from it.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyGradientDescent


Update '*var' according to the momentum scheme.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.raw_ops.ApplyMomentum
Set use_nesterov = True if you want to use Nesterov momentum.
accum = accum * momentum + grad var -= lr * accum