Created
December 15, 2018 12:34
-
-
Save Jojozzc/3346ef72faa6268af50f3c447053fb7c to your computer and use it in GitHub Desktop.
Intersection over Union
This file contains hidden or 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
def cal_IoU(img, lab, nb_class): | |
for i in range(nb_class): | |
mask1 = (img == (i + 1)).astype('uint8') | |
mask2 = (lab == (i + 1)).astype('uint8') | |
mask_and = cv2.bitwise_and(mask1, mask2) | |
mask_or = cv2.bitwise_or(mask1, mask2) | |
s1 = np.sum(mask_and) | |
s2 = np.sum(mask_or) | |
if np.sum(mask2) == 0: | |
if np.sum(mask1) == 0: | |
return 1.0 | |
else: | |
return 0.0 | |
else: | |
return s1/s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment