<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/framework/dtypes.py#L885-L945) |

Converts the given `type_value` to a [`tf.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType).

#### View aliases


**Main aliases**

[`tf.as_dtype`](https://www.tensorflow.org/api_docs/python/tf/dtypes/as_dtype)
**Compat aliases for migration**

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

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

<br />

    tf.dtypes.as_dtype(
        type_value
    )

Inputs can be existing [`tf.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType) objects, a [`DataType`
enum](https://www.tensorflow.org/code/tensorflow/core/framework/types.proto),
a string type name, or a
[`numpy.dtype`](https://numpy.org/doc/stable/reference/generated/numpy.dtype.html).

#### Examples:

    tf.as_dtype(2)  # Enum value for float64.
    tf.float64

    tf.as_dtype('float')
    tf.float32

    tf.as_dtype(np.int32)
    tf.int32

> [!NOTE]
> **Note:** `DType` values are interned (i.e. a single instance of each dtype is stored in a map). When passed a new `DType` object, `as_dtype` always returns the interned value.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `type_value` | A value that can be converted to a [`tf.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType) object. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `DType` corresponding to `type_value`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `type_value` cannot be converted to a `DType`. |

<br />