# tf.TensorSpec

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/TensorSpec) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L33-L184) |

Describes a tf.Tensor.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.TensorSpec`](https://www.tensorflow.org/api_docs/python/tf/TensorSpec)

<br />

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

Metadata for describing the [`tf.Tensor`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/Tensor) objects accepted or returned
by some TensorFlow APIs.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `shape` | Value convertible to [`tf.TensorShape`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/TensorShape). The shape of the tensor. |
| `dtype` | Value convertible to [`tf.DType`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/dtypes/DType). The type of the tensor values. |
| `name` | Optional name for the Tensor. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If shape is not convertible to a [`tf.TensorShape`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/TensorShape), or dtype is not convertible to a [`tf.DType`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/dtypes/DType). |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `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` | <br /> <br /> |

<br />

## Methods

### `from_spec`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L62-L64)

    @classmethod
    from_spec(
        spec, name=None
    )

### `from_tensor`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L66-L73)

    @classmethod
    from_tensor(
        tensor, name=None
    )

### `is_compatible_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L90-L104)

    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`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/TensorShape#is_compatible_with)).

<br />

<br />

<br />

| Args ||
|---|---|
| `spec_or_tensor` | A tf.TensorSpec or a tf.Tensor |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| True if spec_or_tensor is compatible with self. ||

<br />

### `most_specific_compatible_type`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L125-L130)

    most_specific_compatible_type(
        other
    )

Returns the most specific TypeSpec compatible with `self` and `other`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | A `TypeSpec`. |

<br />

<br />

<br />

<br />

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

<br />

### `__eq__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L113-L118)

    __eq__(
        other
    )

Return self==value.

### `__ne__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/framework/tensor_spec.py#L120-L121)

    __ne__(
        other
    )

Return self!=value.