Wraps a stateless metric function with the Mean metric

metric_mean_wrapper(..., fn, name = NULL, dtype = NULL)

Arguments

...

named arguments to pass on to fn.

fn

The metric function to wrap, with signature fn(y_true, y_pred, ...).

name

(Optional) string name of the metric instance.

dtype

(Optional) data type of the metric result.

Value

A (subclassed) Metric instance that can be passed directly to compile(metrics = ), or used as a standalone object. See ?Metric for example usage.

Details

You could use this class to quickly build a mean metric from a function. The function needs to have the signature fn(y_true, y_pred) and return a per-sample loss array. MeanMetricWrapper$result() will return the average metric value across all samples seen so far.

For example:

accuracy <- function(y_true, y_pred)
  k_cast(y_true == y_pred, 'float32')

accuracy_metric <- metric_mean_wrapper(fn = accuracy)

model %>% compile(..., metrics=accuracy_metric)

See also