in evaluation/tiny_benchmark/third/Cityscapes/evaluation/eval_script/eval_MR_multisetup.py [0:0]
def evaluateImg(self, imgId, catId, hRng, vRng, maxDet):
'''
perform evaluation for single category and image
:return: dict (single image results)
'''
p = self.params
if p.useCats:
gt = self._gts[imgId, catId]
dt = self._dts[imgId, catId]
else:
gt = [_ for cId in p.catIds for _ in self._gts[imgId, cId]]
dt = [_ for cId in p.catIds for _ in self._dts[imgId, cId]]
if len(gt) == 0 and len(dt) == 0:
return None
for g in gt:
if g['ignore']:
g['_ignore'] = 1
else:
g['_ignore'] = 0
# sort dt highest score first, sort gt ignore last
gtind = np.argsort([g['_ignore'] for g in gt], kind='mergesort')
gt = [gt[i] for i in gtind]
dtind = np.argsort([-d['score'] for d in dt], kind='mergesort')
dt = [dt[i] for i in dtind[0:maxDet]]
"""
changed code here.
"""
# exclude dt out of height range ----0
#d tind = np.array([int(d['id'] - dt[0]['id']) for d in dt])
_dt, dtind = [], []
for idx, d in enumerate(dt):
# ################################ change by hui ###################################
if self.filter_type == 'size':
dsize = np.sqrt(d['bbox'][2] * d['bbox'][3])
if dsize >= hRng[0] / self.params.expFilter and dsize < hRng[1] * self.params.expFilter:
_dt.append(d)
dtind.append(idx)
else:
if d['height'] >= hRng[0] / self.params.expFilter and d['height'] < hRng[1] * self.params.expFilter:
_dt.append(d)
dtind.append(idx)
###################################
dt = _dt
# load computed ious
if len(dtind) > 0:
ious = self.ious[imgId, catId][dtind, :] if len(self.ious[imgId, catId]) > 0 else self.ious[imgId, catId]
ious = ious[:, gtind]
else:
ious = []
T = len(p.iouThrs)
G = len(gt)
D = len(dt)
gtm = np.zeros((T,G))
dtm = np.zeros((T,D))
gtIg = np.array([g['_ignore'] for g in gt])
dtIg = np.zeros((T,D))
ignore_gts = np.array([g['bbox'] for g in gt if g['_ignore']])
ignore_gts_idx = np.array([i for i, g in enumerate(gt) if g['_ignore']])
# #### ad by G ##############
if len(ignore_gts_idx) > 0 and len(dt) > 0:
ignore_gts_area = np.array([g['area'] for g in gt if g['_ignore']]) # use area
ignore_ious = (ious.T[ignore_gts_idx]).T
# #############################
if not len(ious)==0:
for tind, t in enumerate(p.iouThrs):
for dind, d in enumerate(dt):
# information about best match so far (m=-1 -> unmatched)
iou = min([t, 1-1e-10])
bstOa = iou
bstg = -2
bstm = -2
for gind, g in enumerate(gt):
m = gtm[tind, gind]
# if this gt already matched, and not a crowd, continue
if m > 0:
continue
# if dt matched to reg gt, and on ignore gt, stop
if bstm != -2 and gtIg[gind] == 1:
break
# continue to next gt unless better match made
if ious[dind,gind] < bstOa:
continue
# if match successful and best so far, store appropriately
bstOa = ious[dind,gind]
bstg = gind
if gtIg[gind] == 0:
bstm = 1
else:
bstm = -1
# if match made store id of match for both dt and gt
if bstg == -2:
# #### ad by hui ##############
if self.use_iod_for_ignore and len(ignore_gts) > 0:
# iods = self.IOD(np.array([d['bbox']]), ignore_gts)[0]
iods = self.IOD_by_IOU(np.array([d['bbox']]), None, ignore_gts_area,
ignore_ious[dind:dind+1, :])[0]
idx = np.argmax(iods)
if iods[idx] > 0.5:
# print('inside')
bstg = ignore_gts_idx[idx]
bstm = -1
else: continue
else: continue
######################
dtIg[tind,dind] = gtIg[bstg]
dtm[tind,dind] = gt[bstg]['id']
if bstm == 1:
gtm[tind,bstg] = d['id']
# store results for given image and category
return {
'image_id': imgId,
'category_id': catId,
'hRng': hRng,
'vRng': vRng,
'maxDet': maxDet,
'dtIds': [d['id'] for d in dt],
'gtIds': [g['id'] for g in gt],
'dtMatches': dtm,
'gtMatches': gtm,
'dtScores': [d['score'] for d in dt],
'gtIgnore': gtIg,
'dtIgnore': dtIg,
}