Skip to content

Instantly share code, notes, and snippets.

View kivantium's full-sized avatar

Kawana Kiyoshi kivantium

View GitHub Profile
@meetps
meetps / computeIoU.py
Created February 11, 2017 14:02
Intersection over Union for Python [ Keras ]
import numpy as np
def computeIoU(y_pred_batch, y_true_batch):
return np.mean(np.asarray([pixelAccuracy(y_pred_batch[i], y_true_batch[i]) for i in range(len(y_true_batch))]))
def pixelAccuracy(y_pred, y_true):
y_pred = np.argmax(np.reshape(y_pred,[N_CLASSES_PASCAL,img_rows,img_cols]),axis=0)
y_true = np.argmax(np.reshape(y_true,[N_CLASSES_PASCAL,img_rows,img_cols]),axis=0)
y_pred = y_pred * (y_true>0)