Class TensorSpec
Describes a tf.Tensor.
Aliases:
- Class
tf.compat.v1.TensorSpec
- Class
tf.compat.v2.TensorSpec
Used in the guide:
U
si
ng
t
he
S
av
ed
Mo
de
lf
o
rm
at
Used in the tutorials:
B
et
te
rp
e
rf
or
ma
nc
ew
i
th
t
f.
fu
nc
ti
on
T
ra
ns
fo
rm
er
m
od
el
f
or
l
an
gu
ag
eu
n
de
rs
ta
nd
in
g`` tf.TensorMetadata for describing the objects accepted or returned by some TensorFlow APIs.
init
__init__(
shape,
dtype=tf.dtypes.float32,
name=None
)
Creates a TensorSpec.
Args:
shape
: Value convertible totf.TensorShape
. Theshape
of the tensor.dtype
: Value convertible totf.DType
. The type of the tensor values.name
: Optionalname
for the Tensor.
Raises:
TypeError
: If shape is not convertible to atf.TensorShape
, or dtype is not convertible to atf.DType
.
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.
value_type
Methods
eq
__eq__(other)
Return self==value.
ne
__ne__(other)
Return self!=value.
from_spec
@classmethod
from_spec(
cls,
spec,
name=None
)
from_tensor
@classmethod
from_tensor(
cls,
tensor,
name=None
)
is_compatible_with
is_compatible_with(spec_or_tensor)
Returns True if spec_or_tensor is compatible with this TensorSpec. tf.TensorShape.is_compatible_withTwo tensors are considered compatible if they have the same dtype and their shapes are compatible (see ).
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
most_specific_compatible_type(other)
Returns the most specific TypeSpec compatible with self
and other
.
Args:
other
: ATypeSpec
.
Raises:
ValueError
: If there is no TypeSpec that is compatible with bothself
andother
.