IoU is calculated as follows (the code file is available as Selective_search.ipynb in GitHub):
- Define the IoU extraction function, demonstrated in the following code:
from copy import deepcopyimport numpy as npdef extract_iou(candidate, current_y,img_shape): boxA = deepcopy(candidate) boxB = deepcopy(current_y) img1 = np.zeros(img_shape) img1[boxA[1]:boxA[3],boxA[0]:boxA[2]]=1 img2 = np.zeros(img_shape) img2[int(boxB[1]):int(boxB[3]),int(boxB[0]):int(boxB[2])]=1 iou = np.sum(img1*img2)/(np.sum(img1)+np.sum(img2)- np.sum(img1*img2)) return iou
In the preceding function, we take the candidate, actual object region, and image shape as input.
Further, we initialized two zero-value arrays of the same shape for the candidate image ...