wko-on-cloud-n/src/metrics.py

17 lines
417 B
Python
Raw Normal View History

2022-02-16 00:36:06 +01:00
from keras import backend as K
def IOU(y_true,
y_pred,
smooth=1e-7):
'''
Taken from https://github.com/keras-team/keras-contrib/blob/master/keras_contrib/losses/jaccard.py
'''
intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
sum_ = K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1)
jacc = (intersection + smooth) / \
(sum_ - intersection + smooth)
return jacc