Custom metric function
Details
You can provide an arbitrary R function as a custom metric. Note that
the y_true
and y_pred
parameters are tensors, so computations on
them should use op_*
tensor functions.
Use the custom_metric()
function to define a custom metric.
Note that a name ('mean_pred'
) is provided for the custom metric
function: this name is used within training progress output.
If you want to save and load a model with custom metrics, you should
also call register_keras_serializable()
, or
specify the metric in the call the load_model()
. For example:
load_model("my_model.keras", c('mean_pred' = metric_mean_pred))
.
Alternatively, you can wrap all of your code in a call to
with_custom_object_scope()
which will allow you to refer to the
metric by name just like you do with built in keras metrics.
Alternative ways of supplying custom metrics:
custom_metric():
Arbitrary R function.metric_mean_wrapper()
: Wrap an arbitrary R function in aMetric
instance.Create a custom
Metric()
subclass.
See also
Other metrics: Metric()
metric_auc()
metric_binary_accuracy()
metric_binary_crossentropy()
metric_binary_focal_crossentropy()
metric_binary_iou()
metric_categorical_accuracy()
metric_categorical_crossentropy()
metric_categorical_focal_crossentropy()
metric_categorical_hinge()
metric_cosine_similarity()
metric_f1_score()
metric_false_negatives()
metric_false_positives()
metric_fbeta_score()
metric_hinge()
metric_huber()
metric_iou()
metric_kl_divergence()
metric_log_cosh()
metric_log_cosh_error()
metric_mean()
metric_mean_absolute_error()
metric_mean_absolute_percentage_error()
metric_mean_iou()
metric_mean_squared_error()
metric_mean_squared_logarithmic_error()
metric_mean_wrapper()
metric_one_hot_iou()
metric_one_hot_mean_iou()
metric_poisson()
metric_precision()
metric_precision_at_recall()
metric_r2_score()
metric_recall()
metric_recall_at_precision()
metric_root_mean_squared_error()
metric_sensitivity_at_specificity()
metric_sparse_categorical_accuracy()
metric_sparse_categorical_crossentropy()
metric_sparse_top_k_categorical_accuracy()
metric_specificity_at_sensitivity()
metric_squared_hinge()
metric_sum()
metric_top_k_categorical_accuracy()
metric_true_negatives()
metric_true_positives()