Code Interpretation mask-rcnn (V): Calculation of mask_iou

I thought that only box iou value can be calculated, but after I saw maskrcnn, found that the model was iou mask calculation method is that the trick

mask1 and mask2 must have the same height and width, then the accumulated value of the same position, i.e. crossing the area, and after mask1 and mask2

And set all of the accumulated value, and then calculates the similar box iou calculated.

However, I sake of simplicity, the variable considered as a mask, and mask1 and mask2 are equal to a, the following is a detailed Code:

 

import numpy as np
a=np.array([[1,0,1,0,1,1],[1,0,1,0,1,0]])
print(a > .5)
masks = np.reshape(a > .5, (-1, 1)).astype(np.float32) # flatten two dimension,but line only one
print('masks=',masks)
area1 = np.sum(masks, axis=0) # 计算mask_面积
print('mask_area1=',area1)

mask_intersections = np.dot(masks.T, masks)
print('mask_intersections=',mask_intersections)
union = area1[:, None]+area1[None,:]-mask_intersections
print(union)
iou_mask=union/mask_intersections
print('iou_mask=',iou_mask)

结果如下:

 

 

 

Guess you like

Origin www.cnblogs.com/tangjunjun/p/12043777.html