in mask2former_video/data_video/datasets/ytvis_api/ytvoseval.py [0:0]
def computeIoU(self, vidId, catId):
p = self.params
if p.useCats:
gt = self._gts[vidId,catId]
dt = self._dts[vidId,catId]
else:
gt = [_ for cId in p.catIds for _ in self._gts[vidId,cId]]
dt = [_ for cId in p.catIds for _ in self._dts[vidId,cId]]
if len(gt) == 0 and len(dt) ==0:
return []
inds = np.argsort([-d['score'] for d in dt], kind='mergesort')
dt = [dt[i] for i in inds]
if len(dt) > p.maxDets[-1]:
dt=dt[0:p.maxDets[-1]]
if p.iouType == 'segm':
g = [g['segmentations'] for g in gt]
d = [d['segmentations'] for d in dt]
elif p.iouType == 'bbox':
g = [g['bboxes'] for g in gt]
d = [d['bboxes'] for d in dt]
else:
raise Exception('unknown iouType for iou computation')
# compute iou between each dt and gt region
iscrowd = [int(o['iscrowd']) for o in gt]
#ious = maskUtils.iou(d,g,iscrowd)
def iou_seq(d_seq, g_seq):
i = .0
u = .0
for d, g in zip(d_seq, g_seq):
if d and g:
i += maskUtils.area(maskUtils.merge([d, g], True))
u += maskUtils.area(maskUtils.merge([d, g], False))
elif not d and g:
u += maskUtils.area(g)
elif d and not g:
u += maskUtils.area(d)
if not u > .0:
print("Mask sizes in video {} and category {} may not match!".format(vidId, catId))
iou = i / u if u > .0 else .0
return iou
ious = np.zeros([len(d), len(g)])
for i, j in np.ndindex(ious.shape):
ious[i, j] = iou_seq(d[i], g[j])
#print(vidId, catId, ious.shape, ious)
return ious