17 lines
417 B
Python
17 lines
417 B
Python
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
|