Last active
January 12, 2021 20:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creating a customized function to compute the AUC ROC curve in our keras or tensorflow model.