tf.keras.metrics.Metric

Encapsulates metric logic and state.

Inherits From: Layer, Module

Used in the notebooks

Used in the guide

name (Optional) string name of the metric instance.
dtype (Optional) data type of the metric result.
**kwargs Additional layer keywords arguments.

Standalone usage:

m = SomeMetric(...)
for input in ...:
  m.update_state(input)
print('Final result: ', m.result().numpy())

Usage with compile() API:

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(64, activation='relu'))
model.add(tf.keras.layers.Dense(64, activation='relu'))
model.add(tf.keras.layers.Dense(10, activation='softmax'))