# NOT RUN {
# create metric using backend tensor functions
metric_mean_pred <- custom_metric("mean_pred", function(y_true, y_pred) {
k_mean(y_pred)
})
model %>% compile(
optimizer = optimizer_rmsprop(),
loss = loss_binary_crossentropy,
metrics = c('accuracy', metric_mean_pred)
)
# create custom metric to wrap metric with parameter
metric_top_3_categorical_accuracy <-
custom_metric("top_3_categorical_accuracy", function(y_true, y_pred) {
metric_top_k_categorical_accuracy(y_true, y_pred, k = 3)
})
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = metric_top_3_categorical_accuracy
)
# }
Run the code above in your browser using DataLab