# Keras IoU implementation

Are there any implementations of **Intersection over Union** metric in Keras 2.1.*?

Are there any implementations of **Intersection over Union** metric in Keras 2.1.*?

1 Answers

NN

2```
def mean_iou(y_true, y_pred):
y_pred = K.cast(K.greater(y_pred, .5), dtype='float32') # .5 is the threshold
inter = K.sum(K.sum(K.squeeze(y_true * y_pred, axis=3), axis=2), axis=1)
union = K.sum(K.sum(K.squeeze(y_true + y_pred, axis=3), axis=2), axis=1) - inter
return K.mean((inter + K.epsilon()) / (union + K.epsilon()))
```

Reply

Couldn't find what you were looking for?and we will find an expert to answer.

How helpful was this page?