Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Last active January 12, 2021 20:52
Show Gist options
  • Save rocreguant/c6430501efd9c74838c51a59f81f0a96 to your computer and use it in GitHub Desktop.
Save rocreguant/c6430501efd9c74838c51a59f81f0a96 to your computer and use it in GitHub Desktop.
This gist is about how to create a AUC metric for tensorflow/Keras
def auc_roc(y_true, y_pred):
    # can be any tensorflow metric
    value, update_op = tf.contrib.metrics.streaming_auc(y_pred, y_true)
    # find all variables created for this metric
metric_vars = [i for i in tf.local_variables() if 'auc_roc' in i.name.split('/')[1]]
    # Add metric variables to GLOBAL_VARIABLES collection.
# They will be initialized for new session.
for v in metric_vars:
    tf.add_to_collection(tf.GraphKeys.GLOBAL_VARIABLES, v)
    # force to update metric values
with tf.control_dependencies([update_op]):
    value = tf.identity(value)
return value
@rocreguant
Copy link
Author

Creating a customized function to compute the AUC ROC curve in our keras or tensorflow model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment