# tf.keras.metrics.get

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/metrics/__init__.py#L173-L215) |

Retrieves a Keras metric as a `function`/`Metric` class instance.

#### View aliases


**Main aliases**

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

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

\`tf.compat.v1.keras.metrics.get\`

<br />

    tf.keras.metrics.get(
        identifier
    )

The `identifier` may be the string name of a metric function or class.

    metric = tf.keras.metrics.get("categorical_crossentropy")
    type(metric)
    <class 'function'>
    metric = tf.keras.metrics.get("CategoricalCrossentropy")
    type(metric)
    <class '...metrics.CategoricalCrossentropy'>

You can also specify `config` of the metric to this function by passing dict
containing `class_name` and `config` as an identifier. Also note that the
`class_name` must map to a `Metric` class

    identifier = {"class_name": "CategoricalCrossentropy",
                  "config": {"from_logits": True} }
    metric = tf.keras.metrics.get(identifier)
    type(metric)
    <class '...metrics.CategoricalCrossentropy'>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `identifier` | A metric identifier. One of None or string name of a metric function/class or metric configuration dictionary or a metric function or a metric class instance |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A Keras metric as a `function`/ `Metric` class instance. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `identifier` cannot be interpreted. |

<br />