Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COCOeval.summarize: allow arbitrary maxDets param #559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions PythonAPI/pycocotools/cocoeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def computeIoU(self, imgId, catId):
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]:
if p.maxDets[-1] and len(dt) > p.maxDets[-1]:
dt=dt[0:p.maxDets[-1]]

if p.iouType == 'segm':
Expand All @@ -196,7 +196,7 @@ def computeOks(self, imgId, catId):
dts = self._dts[imgId, catId]
inds = np.argsort([-d['score'] for d in dts], kind='mergesort')
dts = [dts[i] for i in inds]
if len(dts) > p.maxDets[-1]:
if p.maxDets[-1] and len(dts) > p.maxDets[-1]:
dts = dts[0:p.maxDets[-1]]
# if len(gts) == 0 and len(dts) == 0:
if len(gts) == 0 or len(dts) == 0:
Expand Down Expand Up @@ -424,13 +424,14 @@ def summarize(self):
Compute and display summary metrics for evaluation results.
Note this functin can *only* be applied on the default parameter setting
'''
def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ):
def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=None ):
p = self.params
iStr = ' {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] = {:0.3f}'
iStr = ' {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3} ] = {:0.3f}'
titleStr = 'Average Precision' if ap == 1 else 'Average Recall'
typeStr = '(AP)' if ap==1 else '(AR)'
iouStr = '{:0.2f}:{:0.2f}'.format(p.iouThrs[0], p.iouThrs[-1]) \
if iouThr is None else '{:0.2f}'.format(iouThr)
detStr = '{:d}'.format(maxDets) if maxDets else 'all'

aind = [i for i, aRng in enumerate(p.areaRngLbl) if aRng == areaRng]
mind = [i for i, mDet in enumerate(p.maxDets) if mDet == maxDets]
Expand All @@ -453,22 +454,22 @@ def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ):
mean_s = -1
else:
mean_s = np.mean(s[s>-1])
print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s))
print(iStr.format(titleStr, typeStr, iouStr, areaRng, detStr, mean_s))
return mean_s
def _summarizeDets():
stats = np.zeros((12,))
stats[0] = _summarize(1)
stats[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[2])
stats[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[2])
stats[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[2])
stats[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[2])
stats[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[2])
stats[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[-1])
stats[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[-1])
stats[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[-1])
stats[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[-1])
stats[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[-1])
stats[6] = _summarize(0, maxDets=self.params.maxDets[0])
stats[7] = _summarize(0, maxDets=self.params.maxDets[1])
stats[8] = _summarize(0, maxDets=self.params.maxDets[2])
stats[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[2])
stats[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[2])
stats[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[2])
stats[7] = _summarize(0, maxDets=self.params.maxDets[1]) if len(self.params.maxDets) > 1 else -1
stats[8] = _summarize(0, maxDets=self.params.maxDets[2]) if len(self.params.maxDets) > 2 else -1
stats[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[-1])
stats[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[-1])
stats[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[-1])
return stats
def _summarizeKps():
stats = np.zeros((10,))
Expand Down