When I want to build a custom metric which can used with model.compile, I got confused about how to understand y_true and y_pred in the callable function. Here is an example given in the Keras documnets.
def my_metric_fn(y_true, y_pred):
squared_difference = tf.square(y_true - y_pred)
return tf.reduce_mean(squared_difference, axis=-1) # Note the `axis=-1`
model.compile(optimizer='adam', loss='mean_squared_error', metrics=[my_metric_fn])
From the codes, I think y_true and y_pred are batch of samples. But it also says that "Much like loss functions, any callable with signature metric_fn(y_true, y_pred) that returns an array of losses (one of sample in the input batch) can be passed to compile() as a metric".
Does that mean the output return in the callable is the loss for one single sample? Should we regard y_true and y_pred as single sample or batch of samples in metric/loss function?