Missed TensorFlow World? Check out the recap. Learn more

tf.TensorSpec

TensorFlow 2.0 version View source on GitHub

Class TensorSpec

Describes a tf.Tensor.

Aliases:

  • Class tf.compat.v1.TensorSpec
  • Class tf.compat.v2.TensorSpec
  • Class tf.contrib.eager.TensorSpec
  • Class tf.contrib.framework.TensorSpec

Metadata for describing the tf.Tensor objects accepted or returned by some TensorFlow APIs.

__init__

View source

__init__(
    shape,
    dtype=tf.dtypes.float32,
    name=None
)

Creates a TensorSpec.

Args:

  • shape: Value convertible to tf.TensorShape. The shape of the tensor.
  • dtype: Value convertible to tf.DType. The type of the tensor values.
  • name: Optional name for the Tensor.

Raises:

Properties

dtype

Returns the dtype of elements in the tensor.

name

Returns the (optionally provided) name of the described tensor.

shape

Returns the TensorShape that represents the shape of the tensor.

Methods

__eq__

View source

__eq__(other)

__ne__

View source

__ne__(other)

from_spec

View source

@classmethod
from_spec(
    cls,
    spec,
    name=None
)

from_tensor

View source

@classmethod
from_tensor(
    cls,
    tensor,
    name=None
)

is_compatible_with

View source

is_compatible_with(spec_or_tensor)

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.