Created
February 11, 2017 14:02
-
-
Save meetps/6a5ad112559ef1536d0191f8b9fe8d1e to your computer and use it in GitHub Desktop.
Intersection over Union for Python [ Keras ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
How does this actually work in the scope of a full model? Also this does not look like IOU. Can u explain more??