标签:box log line nump dimen url bsp 计算 img
我以为只有box能计算iou值,但我看了maskrcnn后,发现该模型对mask进行了iou的计算,该方法巧妙之处在于
mask1与mask2必须有相同的height and width,而后在同一个位置的值累加,即交叉面积,而后将mask1与mask2
所有值累加为并集,而后计算类似于box的iou计算了。
然而,我为了简化,将变量a看作mask,并将mask1与mask2均等于a,以下是详细代码:
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)
结果如下:
标签:box log line nump dimen url bsp 计算 img
原文地址:https://www.cnblogs.com/tangjunjun/p/12043777.html