7a4b4adc3e5dd7c59d50ea0fd346805d6e4b0227
[ealt-edge.git] / example-apps / PDD / pcb-defect-detection / data / lib_coco / PythonAPI / pycocotools / cocoeval.py
1 __author__ = 'tsungyi'
2
3 import numpy as np
4 import datetime
5 import time
6 from collections import defaultdict
7 from . import mask as maskUtils
8 import copy
9
10 class COCOeval:
11     # Interface for evaluating detection on the Microsoft COCO dataset.
12     #
13     # The usage for CocoEval is as follows:
14     #  cocoGt=..., cocoDt=...       # load dataset and results
15     #  E = CocoEval(cocoGt,cocoDt); # initialize CocoEval object
16     #  E.params.recThrs = ...;      # set parameters as desired
17     #  E.evaluate();                # run per image evaluation
18     #  E.accumulate();              # accumulate per image results
19     #  E.summarize();               # display summary metrics of results
20     # For example usage see evalDemo.m and http://mscoco.org/.
21     #
22     # The evaluation parameters are as follows (defaults in brackets):
23     #  imgIds     - [all] N img ids to use for evaluation
24     #  catIds     - [all] K cat ids to use for evaluation
25     #  iouThrs    - [.5:.05:.95] T=10 IoU thresholds for evaluation
26     #  recThrs    - [0:.01:1] R=101 recall thresholds for evaluation
27     #  areaRng    - [...] A=4 object area ranges for evaluation
28     #  maxDets    - [1 10 100] M=3 thresholds on max detections per image
29     #  iouType    - ['segm'] set iouType to 'segm', 'bbox' or 'keypoints'
30     #  iouType replaced the now DEPRECATED useSegm parameter.
31     #  useCats    - [1] if true use category labels for evaluation
32     # Note: if useCats=0 category labels are ignored as in proposal scoring.
33     # Note: multiple areaRngs [Ax2] and maxDets [Mx1] can be specified.
34     #
35     # evaluate(): evaluates detections on every image and every category and
36     # concats the results into the "evalImgs" with fields:
37     #  dtIds      - [1xD] id for each of the D detections (dt)
38     #  gtIds      - [1xG] id for each of the G ground truths (gt)
39     #  dtMatches  - [TxD] matching gt id at each IoU or 0
40     #  gtMatches  - [TxG] matching dt id at each IoU or 0
41     #  dtScores   - [1xD] confidence of each dt
42     #  gtIgnore   - [1xG] ignore flag for each gt
43     #  dtIgnore   - [TxD] ignore flag for each dt at each IoU
44     #
45     # accumulate(): accumulates the per-image, per-category evaluation
46     # results in "evalImgs" into the dictionary "eval" with fields:
47     #  params     - parameters used for evaluation
48     #  date       - date evaluation was performed
49     #  counts     - [T,R,K,A,M] parameter dimensions (see above)
50     #  precision  - [TxRxKxAxM] precision for every evaluation setting
51     #  recall     - [TxKxAxM] max recall for every evaluation setting
52     # Note: precision and recall==-1 for settings with no gt objects.
53     #
54     # See also coco, mask, pycocoDemo, pycocoEvalDemo
55     #
56     # Microsoft COCO Toolbox.      version 2.0
57     # Data, paper, and tutorials available at:  http://mscoco.org/
58     # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
59     # Licensed under the Simplified BSD License [see coco/license.txt]
60     def __init__(self, cocoGt=None, cocoDt=None, iouType='segm'):
61         '''
62         Initialize CocoEval using coco APIs for gt and dt
63         :param cocoGt: coco object with ground truth annotations
64         :param cocoDt: coco object with detection results
65         :return: None
66         '''
67         if not iouType:
68             print('iouType not specified. use default iouType segm')
69         self.cocoGt   = cocoGt              # ground truth COCO API
70         self.cocoDt   = cocoDt              # detections COCO API
71         self.params   = {}                  # evaluation parameters
72         self.evalImgs = defaultdict(list)   # per-image per-category evaluation results [KxAxI] elements
73         self.eval     = {}                  # accumulated evaluation results
74         self._gts = defaultdict(list)       # gt for evaluation
75         self._dts = defaultdict(list)       # dt for evaluation
76         self.params = Params(iouType=iouType) # parameters
77         self._paramsEval = {}               # parameters for evaluation
78         self.stats = []                     # result summarization
79         self.ious = {}                      # ious between all gts and dts
80         if not cocoGt is None:
81             self.params.imgIds = sorted(cocoGt.getImgIds())
82             self.params.catIds = sorted(cocoGt.getCatIds())
83
84
85     def _prepare(self):
86         '''
87         Prepare ._gts and ._dts for evaluation based on params
88         :return: None
89         '''
90         def _toMask(anns, coco):
91             # modify ann['segmentation'] by reference
92             for ann in anns:
93                 rle = coco.annToRLE(ann)
94                 ann['segmentation'] = rle
95         p = self.params
96         if p.useCats:
97             gts=self.cocoGt.loadAnns(self.cocoGt.getAnnIds(imgIds=p.imgIds, catIds=p.catIds))
98             dts=self.cocoDt.loadAnns(self.cocoDt.getAnnIds(imgIds=p.imgIds, catIds=p.catIds))
99         else:
100             gts=self.cocoGt.loadAnns(self.cocoGt.getAnnIds(imgIds=p.imgIds))
101             dts=self.cocoDt.loadAnns(self.cocoDt.getAnnIds(imgIds=p.imgIds))
102
103         # convert ground truth to mask if iouType == 'segm'
104         if p.iouType == 'segm':
105             _toMask(gts, self.cocoGt)
106             _toMask(dts, self.cocoDt)
107         # set ignore flag
108         for gt in gts:
109             gt['ignore'] = gt['ignore'] if 'ignore' in gt else 0
110             gt['ignore'] = 'iscrowd' in gt and gt['iscrowd']
111             if p.iouType == 'keypoints':
112                 gt['ignore'] = (gt['num_keypoints'] == 0) or gt['ignore']
113         self._gts = defaultdict(list)       # gt for evaluation
114         self._dts = defaultdict(list)       # dt for evaluation
115         for gt in gts:
116             self._gts[gt['image_id'], gt['category_id']].append(gt)
117         for dt in dts:
118             self._dts[dt['image_id'], dt['category_id']].append(dt)
119         self.evalImgs = defaultdict(list)   # per-image per-category evaluation results
120         self.eval     = {}                  # accumulated evaluation results
121
122     def evaluate(self):
123         '''
124         Run per image evaluation on given images and store results (a list of dict) in self.evalImgs
125         :return: None
126         '''
127         tic = time.time()
128         print('Running per image evaluation...')
129         p = self.params
130         # add backward compatibility if useSegm is specified in params
131         if not p.useSegm is None:
132             p.iouType = 'segm' if p.useSegm == 1 else 'bbox'
133             print('useSegm (deprecated) is not None. Running {} evaluation'.format(p.iouType))
134         print('Evaluate annotation type *{}*'.format(p.iouType))
135         p.imgIds = list(np.unique(p.imgIds))
136         if p.useCats:
137             p.catIds = list(np.unique(p.catIds))
138         p.maxDets = sorted(p.maxDets)
139         self.params=p
140
141         self._prepare()
142         # loop through images, area range, max detection number
143         catIds = p.catIds if p.useCats else [-1]
144
145         if p.iouType == 'segm' or p.iouType == 'bbox':
146             computeIoU = self.computeIoU
147         elif p.iouType == 'keypoints':
148             computeIoU = self.computeOks
149         self.ious = {(imgId, catId): computeIoU(imgId, catId) \
150                         for imgId in p.imgIds
151                         for catId in catIds}
152
153         evaluateImg = self.evaluateImg
154         maxDet = p.maxDets[-1]
155         self.evalImgs = [evaluateImg(imgId, catId, areaRng, maxDet)
156                  for catId in catIds
157                  for areaRng in p.areaRng
158                  for imgId in p.imgIds
159              ]
160         self._paramsEval = copy.deepcopy(self.params)
161         toc = time.time()
162         print('DONE (t={:0.2f}s).'.format(toc-tic))
163
164     def computeIoU(self, imgId, catId):
165         p = self.params
166         if p.useCats:
167             gt = self._gts[imgId,catId]
168             dt = self._dts[imgId,catId]
169         else:
170             gt = [_ for cId in p.catIds for _ in self._gts[imgId,cId]]
171             dt = [_ for cId in p.catIds for _ in self._dts[imgId,cId]]
172         if len(gt) == 0 and len(dt) ==0:
173             return []
174         inds = np.argsort([-d['score'] for d in dt], kind='mergesort')
175         dt = [dt[i] for i in inds]
176         if len(dt) > p.maxDets[-1]:
177             dt=dt[0:p.maxDets[-1]]
178
179         if p.iouType == 'segm':
180             g = [g['segmentation'] for g in gt]
181             d = [d['segmentation'] for d in dt]
182         elif p.iouType == 'bbox':
183             g = [g['bbox'] for g in gt]
184             d = [d['bbox'] for d in dt]
185         else:
186             raise Exception('unknown iouType for iou computation')
187
188         # compute iou between each dt and gt region
189         iscrowd = [int(o['iscrowd']) for o in gt]
190         ious = maskUtils.iou(d,g,iscrowd)
191         return ious
192
193     def computeOks(self, imgId, catId):
194         p = self.params
195         # dimention here should be Nxm
196         gts = self._gts[imgId, catId]
197         dts = self._dts[imgId, catId]
198         inds = np.argsort([-d['score'] for d in dts], kind='mergesort')
199         dts = [dts[i] for i in inds]
200         if len(dts) > p.maxDets[-1]:
201             dts = dts[0:p.maxDets[-1]]
202         # if len(gts) == 0 and len(dts) == 0:
203         if len(gts) == 0 or len(dts) == 0:
204             return []
205         ious = np.zeros((len(dts), len(gts)))
206         sigmas = np.array([.26, .25, .25, .35, .35, .79, .79, .72, .72, .62,.62, 1.07, 1.07, .87, .87, .89, .89])/10.0
207         vars = (sigmas * 2)**2
208         k = len(sigmas)
209         # compute oks between each detection and ground truth object
210         for j, gt in enumerate(gts):
211             # create bounds for ignore regions(double the gt bbox)
212             g = np.array(gt['keypoints'])
213             xg = g[0::3]; yg = g[1::3]; vg = g[2::3]
214             k1 = np.count_nonzero(vg > 0)
215             bb = gt['bbox']
216             x0 = bb[0] - bb[2]; x1 = bb[0] + bb[2] * 2
217             y0 = bb[1] - bb[3]; y1 = bb[1] + bb[3] * 2
218             for i, dt in enumerate(dts):
219                 d = np.array(dt['keypoints'])
220                 xd = d[0::3]; yd = d[1::3]
221                 if k1>0:
222                     # measure the per-keypoint distance if keypoints visible
223                     dx = xd - xg
224                     dy = yd - yg
225                 else:
226                     # measure minimum distance to keypoints in (x0,y0) & (x1,y1)
227                     z = np.zeros((k))
228                     dx = np.max((z, x0-xd),axis=0)+np.max((z, xd-x1),axis=0)
229                     dy = np.max((z, y0-yd),axis=0)+np.max((z, yd-y1),axis=0)
230                 e = (dx**2 + dy**2) / vars / (gt['area']+np.spacing(1)) / 2
231                 if k1 > 0:
232                     e=e[vg > 0]
233                 ious[i, j] = np.sum(np.exp(-e)) / e.shape[0]
234         return ious
235
236     def evaluateImg(self, imgId, catId, aRng, maxDet):
237         '''
238         perform evaluation for single category and image
239         :return: dict (single image results)
240         '''
241         p = self.params
242         if p.useCats:
243             gt = self._gts[imgId,catId]
244             dt = self._dts[imgId,catId]
245         else:
246             gt = [_ for cId in p.catIds for _ in self._gts[imgId,cId]]
247             dt = [_ for cId in p.catIds for _ in self._dts[imgId,cId]]
248         if len(gt) == 0 and len(dt) ==0:
249             return None
250
251         for g in gt:
252             if g['ignore'] or (g['area']<aRng[0] or g['area']>aRng[1]):
253                 g['_ignore'] = 1
254             else:
255                 g['_ignore'] = 0
256
257         # sort dt highest score first, sort gt ignore last
258         gtind = np.argsort([g['_ignore'] for g in gt], kind='mergesort')
259         gt = [gt[i] for i in gtind]
260         dtind = np.argsort([-d['score'] for d in dt], kind='mergesort')
261         dt = [dt[i] for i in dtind[0:maxDet]]
262         iscrowd = [int(o['iscrowd']) for o in gt]
263         # load computed ious
264         ious = self.ious[imgId, catId][:, gtind] if len(self.ious[imgId, catId]) > 0 else self.ious[imgId, catId]
265
266         T = len(p.iouThrs)
267         G = len(gt)
268         D = len(dt)
269         gtm  = np.zeros((T,G))
270         dtm  = np.zeros((T,D))
271         gtIg = np.array([g['_ignore'] for g in gt])
272         dtIg = np.zeros((T,D))
273         if not len(ious)==0:
274             for tind, t in enumerate(p.iouThrs):
275                 for dind, d in enumerate(dt):
276                     # information about best match so far (m=-1 -> unmatched)
277                     iou = min([t,1-1e-10])
278                     m   = -1
279                     for gind, g in enumerate(gt):
280                         # if this gt already matched, and not a crowd, continue
281                         if gtm[tind,gind]>0 and not iscrowd[gind]:
282                             continue
283                         # if dt matched to reg gt, and on ignore gt, stop
284                         if m>-1 and gtIg[m]==0 and gtIg[gind]==1:
285                             break
286                         # continue to next gt unless better match made
287                         if ious[dind,gind] < iou:
288                             continue
289                         # if match successful and best so far, store appropriately
290                         iou=ious[dind,gind]
291                         m=gind
292                     # if match made store id of match for both dt and gt
293                     if m ==-1:
294                         continue
295                     dtIg[tind,dind] = gtIg[m]
296                     dtm[tind,dind]  = gt[m]['id']
297                     gtm[tind,m]     = d['id']
298         # set unmatched detections outside of area range to ignore
299         a = np.array([d['area']<aRng[0] or d['area']>aRng[1] for d in dt]).reshape((1, len(dt)))
300         dtIg = np.logical_or(dtIg, np.logical_and(dtm==0, np.repeat(a,T,0)))
301         # store results for given image and category
302         return {
303                 'image_id':     imgId,
304                 'category_id':  catId,
305                 'aRng':         aRng,
306                 'maxDet':       maxDet,
307                 'dtIds':        [d['id'] for d in dt],
308                 'gtIds':        [g['id'] for g in gt],
309                 'dtMatches':    dtm,
310                 'gtMatches':    gtm,
311                 'dtScores':     [d['score'] for d in dt],
312                 'gtIgnore':     gtIg,
313                 'dtIgnore':     dtIg,
314             }
315
316     def accumulate(self, p = None):
317         '''
318         Accumulate per image evaluation results and store the result in self.eval
319         :param p: input params for evaluation
320         :return: None
321         '''
322         print('Accumulating evaluation results...')
323         tic = time.time()
324         if not self.evalImgs:
325             print('Please run evaluate() first')
326         # allows input customized parameters
327         if p is None:
328             p = self.params
329         p.catIds = p.catIds if p.useCats == 1 else [-1]
330         T           = len(p.iouThrs)
331         R           = len(p.recThrs)
332         K           = len(p.catIds) if p.useCats else 1
333         A           = len(p.areaRng)
334         M           = len(p.maxDets)
335         precision   = -np.ones((T,R,K,A,M)) # -1 for the precision of absent categories
336         recall      = -np.ones((T,K,A,M))
337         scores      = -np.ones((T,R,K,A,M))
338
339         # create dictionary for future indexing
340         _pe = self._paramsEval
341         catIds = _pe.catIds if _pe.useCats else [-1]
342         setK = set(catIds)
343         setA = set(map(tuple, _pe.areaRng))
344         setM = set(_pe.maxDets)
345         setI = set(_pe.imgIds)
346         # get inds to evaluate
347         k_list = [n for n, k in enumerate(p.catIds)  if k in setK]
348         m_list = [m for n, m in enumerate(p.maxDets) if m in setM]
349         a_list = [n for n, a in enumerate(map(lambda x: tuple(x), p.areaRng)) if a in setA]
350         i_list = [n for n, i in enumerate(p.imgIds)  if i in setI]
351         I0 = len(_pe.imgIds)
352         A0 = len(_pe.areaRng)
353         # retrieve E at each category, area range, and max number of detections
354         for k, k0 in enumerate(k_list):
355             Nk = k0*A0*I0
356             for a, a0 in enumerate(a_list):
357                 Na = a0*I0
358                 for m, maxDet in enumerate(m_list):
359                     E = [self.evalImgs[Nk + Na + i] for i in i_list]
360                     E = [e for e in E if not e is None]
361                     if len(E) == 0:
362                         continue
363                     dtScores = np.concatenate([e['dtScores'][0:maxDet] for e in E])
364
365                     # different sorting method generates slightly different results.
366                     # mergesort is used to be consistent as Matlab implementation.
367                     inds = np.argsort(-dtScores, kind='mergesort')
368                     dtScoresSorted = dtScores[inds]
369
370                     dtm  = np.concatenate([e['dtMatches'][:,0:maxDet] for e in E], axis=1)[:,inds]
371                     dtIg = np.concatenate([e['dtIgnore'][:,0:maxDet]  for e in E], axis=1)[:,inds]
372                     gtIg = np.concatenate([e['gtIgnore'] for e in E])
373                     npig = np.count_nonzero(gtIg==0 )
374                     if npig == 0:
375                         continue
376                     tps = np.logical_and(               dtm,  np.logical_not(dtIg) )
377                     fps = np.logical_and(np.logical_not(dtm), np.logical_not(dtIg) )
378
379                     tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
380                     fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
381                     for t, (tp, fp) in enumerate(zip(tp_sum, fp_sum)):
382                         tp = np.array(tp)
383                         fp = np.array(fp)
384                         nd = len(tp)
385                         rc = tp / npig
386                         pr = tp / (fp+tp+np.spacing(1))
387                         q  = np.zeros((R,))
388                         ss = np.zeros((R,))
389
390                         if nd:
391                             recall[t,k,a,m] = rc[-1]
392                         else:
393                             recall[t,k,a,m] = 0
394
395                         # numpy is slow without cython optimization for accessing elements
396                         # use python array gets significant speed improvement
397                         pr = pr.tolist(); q = q.tolist()
398
399                         for i in range(nd-1, 0, -1):
400                             if pr[i] > pr[i-1]:
401                                 pr[i-1] = pr[i]
402
403                         inds = np.searchsorted(rc, p.recThrs, side='left')
404                         try:
405                             for ri, pi in enumerate(inds):
406                                 q[ri] = pr[pi]
407                                 ss[ri] = dtScoresSorted[pi]
408                         except:
409                             pass
410                         precision[t,:,k,a,m] = np.array(q)
411                         scores[t,:,k,a,m] = np.array(ss)
412         self.eval = {
413             'params': p,
414             'counts': [T, R, K, A, M],
415             'date': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
416             'precision': precision,
417             'recall':   recall,
418             'scores': scores,
419         }
420         toc = time.time()
421         print('DONE (t={:0.2f}s).'.format( toc-tic))
422
423     def summarize(self):
424         '''
425         Compute and display summary metrics for evaluation results.
426         Note this functin can *only* be applied on the default parameter setting
427         '''
428         def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ):
429             p = self.params
430             iStr = ' {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] = {:0.3f}'
431             titleStr = 'Average Precision' if ap == 1 else 'Average Recall'
432             typeStr = '(AP)' if ap==1 else '(AR)'
433             iouStr = '{:0.2f}:{:0.2f}'.format(p.iouThrs[0], p.iouThrs[-1]) \
434                 if iouThr is None else '{:0.2f}'.format(iouThr)
435
436             aind = [i for i, aRng in enumerate(p.areaRngLbl) if aRng == areaRng]
437             mind = [i for i, mDet in enumerate(p.maxDets) if mDet == maxDets]
438             if ap == 1:
439                 # dimension of precision: [TxRxKxAxM]
440                 s = self.eval['precision']
441                 # IoU
442                 if iouThr is not None:
443                     t = np.where(iouThr == p.iouThrs)[0]
444                     s = s[t]
445                 s = s[:,:,:,aind,mind]
446             else:
447                 # dimension of recall: [TxKxAxM]
448                 s = self.eval['recall']
449                 if iouThr is not None:
450                     t = np.where(iouThr == p.iouThrs)[0]
451                     s = s[t]
452                 s = s[:,:,aind,mind]
453             if len(s[s>-1])==0:
454                 mean_s = -1
455             else:
456                 mean_s = np.mean(s[s>-1])
457             print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s))
458             return mean_s
459         def _summarizeDets():
460             stats = np.zeros((12,))
461             stats[0] = _summarize(1)
462             stats[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[2])
463             stats[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[2])
464             stats[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[2])
465             stats[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[2])
466             stats[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[2])
467             stats[6] = _summarize(0, maxDets=self.params.maxDets[0])
468             stats[7] = _summarize(0, maxDets=self.params.maxDets[1])
469             stats[8] = _summarize(0, maxDets=self.params.maxDets[2])
470             stats[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[2])
471             stats[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[2])
472             stats[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[2])
473             return stats
474         def _summarizeKps():
475             stats = np.zeros((10,))
476             stats[0] = _summarize(1, maxDets=20)
477             stats[1] = _summarize(1, maxDets=20, iouThr=.5)
478             stats[2] = _summarize(1, maxDets=20, iouThr=.75)
479             stats[3] = _summarize(1, maxDets=20, areaRng='medium')
480             stats[4] = _summarize(1, maxDets=20, areaRng='large')
481             stats[5] = _summarize(0, maxDets=20)
482             stats[6] = _summarize(0, maxDets=20, iouThr=.5)
483             stats[7] = _summarize(0, maxDets=20, iouThr=.75)
484             stats[8] = _summarize(0, maxDets=20, areaRng='medium')
485             stats[9] = _summarize(0, maxDets=20, areaRng='large')
486             return stats
487         if not self.eval:
488             raise Exception('Please run accumulate() first')
489         iouType = self.params.iouType
490         if iouType == 'segm' or iouType == 'bbox':
491             summarize = _summarizeDets
492         elif iouType == 'keypoints':
493             summarize = _summarizeKps
494         self.stats = summarize()
495
496     def __str__(self):
497         self.summarize()
498
499 class Params:
500     '''
501     Params for coco evaluation api
502     '''
503     def setDetParams(self):
504         self.imgIds = []
505         self.catIds = []
506         # np.arange causes trouble.  the data point on arange is slightly larger than the true value
507         self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
508         self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
509         self.maxDets = [1, 10, 100]
510         self.areaRng = [[0 ** 2, 1e5 ** 2], [0 ** 2, 32 ** 2], [32 ** 2, 96 ** 2], [96 ** 2, 1e5 ** 2]]
511         self.areaRngLbl = ['all', 'small', 'medium', 'large']
512         self.useCats = 1
513
514     def setKpParams(self):
515         self.imgIds = []
516         self.catIds = []
517         # np.arange causes trouble.  the data point on arange is slightly larger than the true value
518         self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
519         self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
520         self.maxDets = [20]
521         self.areaRng = [[0 ** 2, 1e5 ** 2], [32 ** 2, 96 ** 2], [96 ** 2, 1e5 ** 2]]
522         self.areaRngLbl = ['all', 'medium', 'large']
523         self.useCats = 1
524
525     def __init__(self, iouType='segm'):
526         if iouType == 'segm' or iouType == 'bbox':
527             self.setDetParams()
528         elif iouType == 'keypoints':
529             self.setKpParams()
530         else:
531             raise Exception('iouType not supported')
532         self.iouType = iouType
533         # useSegm is deprecated
534         self.useSegm = None