Skip to content

Instantly share code, notes, and snippets.

@meetps
Created February 11, 2017 14:02
Show Gist options
  • Save meetps/6a5ad112559ef1536d0191f8b9fe8d1e to your computer and use it in GitHub Desktop.
Save meetps/6a5ad112559ef1536d0191f8b9fe8d1e to your computer and use it in GitHub Desktop.
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)
return 1.0 * np.sum((y_pred==y_true)*(y_true>0)) / np.sum(y_true>0)
@pGit1
Copy link

pGit1 commented Mar 25, 2017

How does this actually work in the scope of a full model? Also this does not look like IOU. Can u explain more??

@silencemao
Copy link

i want to know what is the different between mean IU and dice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment