ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

tf.contrib.framework.BoundedTensorSpec

View source on GitHub

A TensorSpec that specifies minimum and maximum values.

Inherits From: TensorSpec

Example usage:

spec = tensor_spec.BoundedTensorSpec((1, 2, 3), tf.float32, 0, (5, 5, 5))
tf_minimum = tf.convert_to_tensor(spec.minimum, dtype=spec.dtype)
tf_maximum = tf.convert_to_tensor(spec.maximum, dtype=spec.dtype)

Bounds are meant to be inclusive. This is especially important for integer types. The following spec will be satisfied by tensors with values in the set {0, 1, 2}:

spec = tensor_spec.BoundedTensorSpec((3, 5), tf.int32, 0, 2)

shape Value convertible to tf.TensorShape. The shape of the tensor.
dtype Value convertible to tf.DType. The type of the tensor values.
minimum Number or sequence specifying the minimum element bounds (inclusive). Must be broadcastable to shape.
maximum Number or sequence specifying the maximum element bounds (inclusive). Must be broadcastable to shape.
name Optional string containing a semantic name for the corresponding array. Defaults to None.

ValueError If minimum or maximum are not provided or not broadcastable to shape.
TypeError If the shape is not an iterable or if the dtype is an invalid numpy dtype.

dtype Returns the dtype of elements in the tensor.
maximum Returns a NumPy array specifying the maximum bounds (inclusive).
minimum Returns a NumPy array specifying the minimum bounds (inclusive).
name Returns the (optionally provided) name of the described tensor.
shape Returns the TensorShape that represents the shape of the tensor.
value_type

Methods

from_spec

View source

from_tensor

View source

is_compatible_with

View source

Returns True if spec_or_tensor is compatible with this TensorSpec.

Two tensors are considered compatible if they have the same dtype and their shapes are compatible (see tf.TensorShape.is_compatible_with).

Args
spec_or_tensor A tf.TensorSpec or a tf.Tensor

Returns
True if spec_or_tensor is compatible with self.

most_specific_compatible_type

View source

Returns the most specific TypeSpec compatible with self and other.

Args
other A TypeSpec.

Raises
ValueError If there is no TypeSpec that is compatible with both self and other.

__eq__

View source

Return self==value.

__ne__

View source

Return self!=value.