Guest User

Untitled

a guest
Oct 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. def as_keras_metric(method):
  2. import functools
  3. from keras import backend as K
  4. import tensorflow as tf
  5. @functools.wraps(method)
  6. def wrapper(self, args, **kwargs):
  7. """ Wrapper for turning tensorflow metrics into keras metrics """
  8. value, update_op = method(self, args, **kwargs)
  9. K.get_session().run(tf.local_variables_initializer())
  10. with tf.control_dependencies([update_op]):
  11. value = tf.identity(value)
  12. return value
  13. return wrapper
  14.  
  15. @as_keras_metric
  16. def bmac_metric(Y_true, Y_pred):
  17. return tf.metrics.mean_per_class_accuracy(tf.argmax(Y_true, axis=1), tf.argmax(Y_pred, axis=1), 3)
Add Comment
Please, Sign In to add comment