A TensorShape represents a possibly-partial shape specification for aTensor. It may be one of the following:
Fully-known shape: has a known number of dimensions and a known size for each dimension. e.g. TensorShape([16, 256])
Partially-known shape: has a known number of dimensions, and an unknown size for one or more dimension. e.g. TensorShape([None, 256])
Unknown shape: has an unknown number of dimensions, and an unknown size in all dimensions. e.g. TensorShape(None)
If a tensor is produced by an operation of type "Foo", its shape may be inferred if there is a registered shape function for"Foo". See Shape functionsfor details of shape functions and how to register them. Alternatively, the shape may be set explicitly using tf.Tensor.set_shape.
Args
dims
A list of Dimensions, or None if the shape is unspecified.
Raises
TypeError
If dims cannot be converted to a list of dimensions.
Attributes
dims
Returns a list of Dimensions, or None if the shape is unspecified.
ndims
Deprecated accessor for rank.
rank
Returns the rank of this shape, or None if it is unspecified.
Two possibly-partially-defined shapes are compatible if there exists a fully-defined shape that both shapes can represent. Thus, compatibility allows the shape inference code to reason about partially-defined shapes. For example:
TensorShape(None) is compatible with all shapes.
TensorShape([None, None]) is compatible with all two-dimensional shapes, such as TensorShape([32, 784]), and also TensorShape(None). It is not compatible with, for example, TensorShape([None]) or TensorShape([None, None, None]).
TensorShape([32, None]) is compatible with all two-dimensional shapes with size 32 in the 0th dimension, and also TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32]), TensorShape([32, None, 1]) or TensorShape([64, None]).
TensorShape([32, 784]) is compatible with itself, and also TensorShape([32, None]), TensorShape([None, 784]), TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32, 1, 784]) or TensorShape([None]).
The compatibility relation is reflexive and symmetric, but not transitive. For example, TensorShape([32, 784]) is compatible with TensorShape(None), and TensorShape(None) is compatible with TensorShape([4, 4]), but TensorShape([32, 784]) is not compatible with TensorShape([4, 4]).
Returns the most specific TensorShape compatible with self and other.
TensorShape([None, 1]) is the most specific TensorShape compatible with both TensorShape([2, 1]) and TensorShape([5, 1]). Note that TensorShape(None) is also compatible with above mentioned TensorShapes.
TensorShape([1, 2, 3]) is the most specific TensorShape compatible with both TensorShape([1, 2, 3]) and TensorShape([1, 2, 3]). There are more less specific TensorShapes compatible with above mentioned TensorShapes, e.g. TensorShape([1, 2, None]), TensorShape(None).
Args
other
Another TensorShape.
Returns
A TensorShape which is the most specific compatible shape of selfand other.
Returns the value of a dimension or a shape, depending on the key.
Args
key
If key is an integer, returns the dimension at that index; otherwise if key is a slice, returns a TensorShape whose dimensions are those selected by the slice from self.
Returns
An integer if key is an integer, or a TensorShape if key is a slice.
Raises
ValueError
If key is a slice and self is completely unknown and the step is set.