faster-coco-eval 1.4.2__tar.gz → 1.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. faster_coco_eval-1.5.1/PKG-INFO +97 -0
  2. faster_coco_eval-1.5.1/README.md +72 -0
  3. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/core/coco.py +91 -37
  4. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/core/cocoeval.py +40 -37
  5. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/core/faster_eval_api.py +45 -35
  6. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/core/mask.py +3 -3
  7. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/extra/curves.py +9 -44
  8. faster_coco_eval-1.5.1/faster_coco_eval/extra/display.py +126 -0
  9. faster_coco_eval-1.5.1/faster_coco_eval/extra/draw.py +376 -0
  10. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/extra/extra.py +1 -0
  11. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/version.py +1 -1
  12. faster_coco_eval-1.5.1/faster_coco_eval.egg-info/PKG-INFO +97 -0
  13. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval.egg-info/SOURCES.txt +1 -2
  14. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/pyproject.toml +2 -6
  15. faster_coco_eval-1.5.1/setup.cfg +4 -0
  16. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/setup.py +19 -15
  17. faster-coco-eval-1.4.2/PKG-INFO +0 -203
  18. faster-coco-eval-1.4.2/README.md +0 -178
  19. faster-coco-eval-1.4.2/csrc/mask/pycocotools/_mask.c +0 -21168
  20. faster-coco-eval-1.4.2/faster_coco_eval/extra/display.py +0 -330
  21. faster-coco-eval-1.4.2/faster_coco_eval.egg-info/PKG-INFO +0 -203
  22. faster-coco-eval-1.4.2/setup.cfg +0 -13
  23. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/LICENSE +0 -0
  24. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/MANIFEST.in +0 -0
  25. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +0 -0
  26. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/faster_eval_api/coco_eval/cocoeval.h +0 -0
  27. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/faster_eval_api/faster_eval_api.cpp +0 -0
  28. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/mask/common/maskApi.c +0 -0
  29. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/mask/common/maskApi.h +0 -0
  30. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/csrc/mask/pycocotools/_mask.pyx +0 -0
  31. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/__init__.py +0 -0
  32. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/core/__init__.py +0 -0
  33. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval/extra/__init__.py +0 -0
  34. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
  35. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval.egg-info/requires.txt +0 -0
  36. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/faster_coco_eval.egg-info/top_level.txt +0 -0
  37. {faster-coco-eval-1.4.2 → faster_coco_eval-1.5.1}/requirements/runtime.txt +0 -0
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.1
2
+ Name: faster-coco-eval
3
+ Version: 1.5.1
4
+ Summary: Faster interpretation of the original COCOEval
5
+ Home-page: https://github.com/MiXaiLL76/faster_coco_eval
6
+ Author: MiXaiLL76
7
+ Author-email: mike.milos@yandex.ru
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.6
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.6
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy
22
+ Requires-Dist: plotly
23
+ Requires-Dist: pandas
24
+ Requires-Dist: Pillow
25
+
26
+ # Faster-COCO-Eval
27
+
28
+ [![PyPI](https://img.shields.io/pypi/v/faster-coco-eval)](https://pypi.org/project/faster-coco-eval)
29
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/faster-coco-eval.svg?label=PyPI%20downloads)](
30
+ https://pypi.org/project/faster-coco-eval/)
31
+
32
+ [![docs](https://img.shields.io/badge/docs-latest-blue)](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
33
+ [![license](https://img.shields.io/github/license/MiXaiLL76/faster_coco_eval.svg)](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/LICENSE)
34
+
35
+ ## Disclaimer
36
+
37
+ I often use this project, but I saw it abandoned and without a public repository on github.
38
+ Also, part of the project remained unfinished for a long time. I implemented some of the author's ideas and decided to make the results publicly available.
39
+
40
+ ## Faster-COCO-Eval base
41
+
42
+ This package wraps a facebook C++ implementation of COCO-eval operations found in the
43
+ [pycocotools](https://github.com/cocodataset/cocoapi/tree/master/PythonAPI/pycocotools) package.
44
+ This implementation greatly speeds up the evaluation time
45
+ for coco's AP metrics, especially when dealing with a high number of instances in an image.
46
+
47
+ ## Comparison
48
+
49
+ For our use case with a test dataset of 5000 images from the coco val dataset.
50
+ Testing was carried out using the mmdetection framework and the eval_metric.py script. The indicators are presented below.
51
+
52
+ Visualization of testing **comparison.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/mmdet/comparison.ipynb)
53
+ Tested with yolo3 model (bbox eval) and yoloact model (segm eval)
54
+
55
+ ### Summary for 5000 imgs
56
+
57
+ | Type | COCOeval | COCOeval_faster | Profit |
58
+ | ---- | ----------- | --------------- | ------------ |
59
+ | bbox | 18.477 sec. | 7.345 sec. | ~2.5x faster |
60
+ | segm | 29.819 sec. | 15.840 sec. | ~1.7x faster |
61
+
62
+ ## Summary for 500 imgs
63
+
64
+ | Type | COCOeval | COCOeval_faster | Profit |
65
+ | ---- | --------- | --------------- | ------------ |
66
+ | bbox | 3.57 sec. | 2.03 sec. | ~1.7x faster |
67
+ | segm | 4.16 sec. | 2.41 sec. | ~1.7x faster |
68
+
69
+ ## Feautures
70
+
71
+ This library provides not only validation functions, but also error visualization functions. Including visualization of errors in the image.
72
+ You can study in more detail in the [examples](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples) and [Wiki](https://github.com/MiXaiLL76/faster_coco_eval/wiki).
73
+
74
+ ## Usage
75
+
76
+ Code examples for using the library are available on the [Wiki](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
77
+
78
+ ## Update history
79
+
80
+ Available via link [history.md](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/history.md)
81
+
82
+ ## License
83
+
84
+ The original module was licensed with apache 2, I will continue with the same license.
85
+ Distributed under the apache version 2.0 license, see [license](LICENSE) for more information.
86
+
87
+ ## Citation
88
+
89
+ If you use this benchmark in your research, please cite this project.
90
+
91
+ ```
92
+ @article{faster-coco-eval,
93
+ title = {{Faster-COCO-Eval}: Faster interpretation of the original COCOEval},
94
+ author = {MiXaiLL76},
95
+ year = {2024}
96
+ }
97
+ ```
@@ -0,0 +1,72 @@
1
+ # Faster-COCO-Eval
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/faster-coco-eval)](https://pypi.org/project/faster-coco-eval)
4
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/faster-coco-eval.svg?label=PyPI%20downloads)](
5
+ https://pypi.org/project/faster-coco-eval/)
6
+
7
+ [![docs](https://img.shields.io/badge/docs-latest-blue)](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
8
+ [![license](https://img.shields.io/github/license/MiXaiLL76/faster_coco_eval.svg)](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/LICENSE)
9
+
10
+ ## Disclaimer
11
+
12
+ I often use this project, but I saw it abandoned and without a public repository on github.
13
+ Also, part of the project remained unfinished for a long time. I implemented some of the author's ideas and decided to make the results publicly available.
14
+
15
+ ## Faster-COCO-Eval base
16
+
17
+ This package wraps a facebook C++ implementation of COCO-eval operations found in the
18
+ [pycocotools](https://github.com/cocodataset/cocoapi/tree/master/PythonAPI/pycocotools) package.
19
+ This implementation greatly speeds up the evaluation time
20
+ for coco's AP metrics, especially when dealing with a high number of instances in an image.
21
+
22
+ ## Comparison
23
+
24
+ For our use case with a test dataset of 5000 images from the coco val dataset.
25
+ Testing was carried out using the mmdetection framework and the eval_metric.py script. The indicators are presented below.
26
+
27
+ Visualization of testing **comparison.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/mmdet/comparison.ipynb)
28
+ Tested with yolo3 model (bbox eval) and yoloact model (segm eval)
29
+
30
+ ### Summary for 5000 imgs
31
+
32
+ | Type | COCOeval | COCOeval_faster | Profit |
33
+ | ---- | ----------- | --------------- | ------------ |
34
+ | bbox | 18.477 sec. | 7.345 sec. | ~2.5x faster |
35
+ | segm | 29.819 sec. | 15.840 sec. | ~1.7x faster |
36
+
37
+ ## Summary for 500 imgs
38
+
39
+ | Type | COCOeval | COCOeval_faster | Profit |
40
+ | ---- | --------- | --------------- | ------------ |
41
+ | bbox | 3.57 sec. | 2.03 sec. | ~1.7x faster |
42
+ | segm | 4.16 sec. | 2.41 sec. | ~1.7x faster |
43
+
44
+ ## Feautures
45
+
46
+ This library provides not only validation functions, but also error visualization functions. Including visualization of errors in the image.
47
+ You can study in more detail in the [examples](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples) and [Wiki](https://github.com/MiXaiLL76/faster_coco_eval/wiki).
48
+
49
+ ## Usage
50
+
51
+ Code examples for using the library are available on the [Wiki](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
52
+
53
+ ## Update history
54
+
55
+ Available via link [history.md](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/history.md)
56
+
57
+ ## License
58
+
59
+ The original module was licensed with apache 2, I will continue with the same license.
60
+ Distributed under the apache version 2.0 license, see [license](LICENSE) for more information.
61
+
62
+ ## Citation
63
+
64
+ If you use this benchmark in your research, please cite this project.
65
+
66
+ ```
67
+ @article{faster-coco-eval,
68
+ title = {{Faster-COCO-Eval}: Faster interpretation of the original COCOEval},
69
+ author = {MiXaiLL76},
70
+ year = {2024}
71
+ }
72
+ ```
@@ -8,7 +8,7 @@ __version__ = "2.0"
8
8
  # Please visit http://mscoco.org/ for more information on COCO, including
9
9
  # for the data, paper, and tutorials. The exact format of the annotations
10
10
  # is also described on the COCO website. For example usage of the pycocotools
11
- # please see pycocotools_demo.ipynb. In addition to this API, please download both
11
+ # please see pycocotools_demo.ipynb. In addition to this API, please download both # noqa: E501
12
12
  # the COCO images and annotations in order to run the demo.
13
13
 
14
14
  # An alternative to using the API is to load the annotations directly
@@ -18,7 +18,7 @@ __version__ = "2.0"
18
18
  # captions not all functions are defined (e.g. categories are undefined).
19
19
 
20
20
  # The following API functions are defined:
21
- # COCO - COCO api class that loads COCO annotation file and prepare data structures.
21
+ # COCO - COCO api class that loads COCO annotation file and prepare data structures. # noqa: E501
22
22
  # decodeMask - Decode binary mask M encoded via run-length encoding.
23
23
  # encodeMask - Encode binary mask M using run-length encoding.
24
24
  # getAnnIds - Get ann ids that satisfy given filter conditions.
@@ -48,11 +48,12 @@ import copy
48
48
  import itertools
49
49
  import json
50
50
  import logging
51
- import numpy as np
52
51
  import time
53
52
  import warnings
54
53
  from collections import defaultdict
55
54
 
55
+ import numpy as np
56
+
56
57
  from . import mask as maskUtils
57
58
 
58
59
  logger = logging.getLogger(__name__)
@@ -64,11 +65,14 @@ def _isArrayLike(obj):
64
65
 
65
66
  class COCO:
66
67
  def __init__(self, annotation_file=None):
67
- """
68
- Constructor of Microsoft COCO helper class for reading and visualizing annotations.
68
+ """Constructor of Microsoft COCO helper class for reading and
69
+ visualizing annotations.
70
+
69
71
  :param annotation_file (str): location of annotation file
70
- :param image_folder (str): location to the folder that hosts images.
72
+ :param image_folder (str): location to the folder that hosts
73
+ images.
71
74
  :return:
75
+
72
76
  """
73
77
  # load dataset
74
78
  self.dataset, self.anns, self.cats, self.imgs = (
@@ -84,8 +88,7 @@ class COCO:
84
88
  logger.debug("loading annotations into memory...")
85
89
  tic = time.time()
86
90
  if type(annotation_file) is str:
87
- with open(annotation_file, "r") as f:
88
- self.dataset = json.load(f)
91
+ self.dataset = self.load_json(annotation_file)
89
92
  elif type(annotation_file) is dict:
90
93
  self.dataset = annotation_file
91
94
  else:
@@ -136,21 +139,26 @@ class COCO:
136
139
  self.cats = cats
137
140
 
138
141
  def info(self):
139
- """
140
- Print information about the annotation file.
142
+ """Print information about the annotation file.
143
+
141
144
  :return:
145
+
142
146
  """
143
147
  for key, value in self.dataset["info"].items():
144
148
  logger.debug("{}: {}".format(key, value))
145
149
 
146
150
  def getAnnIds(self, imgIds=[], catIds=[], areaRng=[], iscrowd=None):
147
- """
148
- Get ann ids that satisfy given filter conditions. default skips that filter
149
- :param imgIds (int array) : get anns for given imgs
150
- catIds (int array) : get anns for given cats
151
- areaRng (float array) : get anns for given area range (e.g. [0 inf])
152
- iscrowd (boolean) : get anns for given crowd label (False or True)
151
+ """Get ann ids that satisfy given filter conditions.
152
+
153
+ default skips that filter
154
+ :param imgIds (int array) : get anns for given imgs :param
155
+ catIds (int array) : get anns for given cats
156
+ :param areaRng (float array) : get anns for given area range
157
+ (e.g. [0 inf])
158
+ :param iscrowd (boolean) : get anns for given crowd label (False
159
+ or True)
153
160
  :return: ids (int array) : integer array of ann ids
161
+
154
162
  """
155
163
  imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
156
164
  catIds = catIds if _isArrayLike(catIds) else [catIds]
@@ -188,12 +196,15 @@ class COCO:
188
196
  return ids
189
197
 
190
198
  def getCatIds(self, catNms=[], supNms=[], catIds=[]):
191
- """
192
- filtering parameters. default skips that filter.
199
+ """Filtering parameters.
200
+
201
+ default skips that filter.
193
202
  :param catNms (str array) : get cats for given cat names
194
- :param supNms (str array) : get cats for given supercategory names
203
+ :param supNms (str array) : get cats for given supercategory
204
+ names
195
205
  :param catIds (int array) : get cats for given cat ids
196
206
  :return: ids (int array) : integer array of cat ids
207
+
197
208
  """
198
209
  catNms = catNms if _isArrayLike(catNms) else [catNms]
199
210
  supNms = supNms if _isArrayLike(supNms) else [supNms]
@@ -222,11 +233,12 @@ class COCO:
222
233
  return ids
223
234
 
224
235
  def getImgIds(self, imgIds=[], catIds=[]):
225
- """
226
- Get img ids that satisfy given filter conditions.
236
+ """Get img ids that satisfy given filter conditions.
237
+
227
238
  :param imgIds (int array) : get imgs for given ids
228
239
  :param catIds (int array) : get imgs with all given cats
229
240
  :return: ids (int array) : integer array of img ids
241
+
230
242
  """
231
243
  imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
232
244
  catIds = catIds if _isArrayLike(catIds) else [catIds]
@@ -243,10 +255,11 @@ class COCO:
243
255
  return list(ids)
244
256
 
245
257
  def loadAnns(self, ids=[]):
246
- """
247
- Load anns with the specified ids.
258
+ """Load anns with the specified ids.
259
+
248
260
  :param ids (int array) : integer ids specifying anns
249
261
  :return: anns (object array) : loaded ann objects
262
+
250
263
  """
251
264
  if _isArrayLike(ids):
252
265
  return [self.anns[id] for id in ids]
@@ -254,10 +267,11 @@ class COCO:
254
267
  return [self.anns[ids]]
255
268
 
256
269
  def loadCats(self, ids=[]):
257
- """
258
- Load cats with the specified ids.
270
+ """Load cats with the specified ids.
271
+
259
272
  :param ids (int array) : integer ids specifying cats
260
273
  :return: cats (object array) : loaded cat objects
274
+
261
275
  """
262
276
  if _isArrayLike(ids):
263
277
  return [self.cats[id] for id in ids]
@@ -265,21 +279,29 @@ class COCO:
265
279
  return [self.cats[ids]]
266
280
 
267
281
  def loadImgs(self, ids=[]):
268
- """
269
- Load anns with the specified ids.
282
+ """Load anns with the specified ids.
283
+
270
284
  :param ids (int array) : integer ids specifying img
271
285
  :return: imgs (object array) : loaded img objects
286
+
272
287
  """
273
288
  if _isArrayLike(ids):
274
289
  return [self.imgs[id] for id in ids]
275
290
  elif type(ids) is int:
276
291
  return [self.imgs[ids]]
277
292
 
293
+ @staticmethod
294
+ def load_json(json_file):
295
+ with open(json_file) as io:
296
+ _data = json.load(io)
297
+ return _data
298
+
278
299
  def loadRes(self, resFile, min_score=0):
279
- """
280
- Load result file and return a result api object.
300
+ """Load result file and return a result api object.
301
+
281
302
  :param resFile (str) : file name of result file
282
303
  :return: res (obj) : result api object
304
+
283
305
  """
284
306
  self.score_tresh = min_score
285
307
  res = COCO()
@@ -288,7 +310,7 @@ class COCO:
288
310
  logger.debug("Loading and preparing results...")
289
311
  tic = time.time()
290
312
  if type(resFile) is str:
291
- anns = json.load(open(resFile))
313
+ anns = self.load_json(resFile)
292
314
  elif type(resFile) is np.ndarray:
293
315
  anns = self.loadNumpyAnnotations(resFile)
294
316
  else:
@@ -361,11 +383,14 @@ class COCO:
361
383
  warnings.warn("download deprecated in 1.3.0", DeprecationWarning)
362
384
 
363
385
  def loadNumpyAnnotations(self, data):
364
- """
365
- Convert result data from a numpy array [Nx7] where each row contains {imageID,x1,y1,w,h,score,class}
366
- :param data (numpy.ndarray)
386
+ """Convert result data from array to anns.
387
+
388
+ :param data (numpy.ndarray): array [Nx7] where each row contains
389
+ [imageID,x1,y1,w,h,score,class]
367
390
  :return: annotations (python nested list)
391
+
368
392
  """
393
+
369
394
  logger.debug("Converting ndarray to lists...")
370
395
  assert type(data) is np.ndarray
371
396
  logger.debug(data.shape)
@@ -386,9 +411,10 @@ class COCO:
386
411
  return ann
387
412
 
388
413
  def annToRLE(self, ann):
389
- """
390
- Convert annotation which can be polygons, uncompressed RLE to RLE.
414
+ """Convert annotation which can be polygons, uncompressed RLE to RLE.
415
+
391
416
  :return: binary mask (numpy 2D array)
417
+
392
418
  """
393
419
  t = self.imgs[ann["image_id"]]
394
420
  h, w = t["height"], t["width"]
@@ -407,10 +433,38 @@ class COCO:
407
433
  return rle
408
434
 
409
435
  def annToMask(self, ann):
410
- """
411
- Convert annotation which can be polygons, uncompressed RLE, or RLE to binary mask.
436
+ """Convert annotation which can be polygons, uncompressed RLE, or RLE
437
+ to binary mask.
438
+
412
439
  :return: binary mask (numpy 2D array)
440
+
413
441
  """
414
442
  rle = self.annToRLE(ann)
415
443
  m = maskUtils.decode(rle)
416
444
  return m
445
+
446
+ def get_ann_ids(self, img_ids=[], cat_ids=[], area_rng=[], iscrowd=None):
447
+ return self.getAnnIds(img_ids, cat_ids, area_rng, iscrowd)
448
+
449
+ def get_cat_ids(self, cat_names=[], sup_names=[], cat_ids=[]):
450
+ return self.getCatIds(cat_names, sup_names, cat_ids)
451
+
452
+ def get_img_ids(self, img_ids=[], cat_ids=[]):
453
+ return self.getImgIds(img_ids, cat_ids)
454
+
455
+ def load_anns(self, ids):
456
+ return self.loadAnns(ids)
457
+
458
+ def load_cats(self, ids):
459
+ return self.loadCats(ids)
460
+
461
+ def load_imgs(self, ids):
462
+ return self.loadImgs(ids)
463
+
464
+ @property
465
+ def img_ann_map(self):
466
+ return self.imgToAnns
467
+
468
+ @property
469
+ def cat_img_map(self):
470
+ return self.catToImgs
@@ -2,10 +2,11 @@ __author__ = "tsungyi"
2
2
 
3
3
  import copy
4
4
  import logging
5
- import numpy as np
6
5
  import time
7
6
  from collections import defaultdict
8
7
 
8
+ import numpy as np
9
+
9
10
  from . import mask as maskUtils
10
11
  from .coco import COCO
11
12
 
@@ -70,11 +71,12 @@ class COCOeval:
70
71
  print_function=logger.debug,
71
72
  extra_calc=False,
72
73
  ):
73
- """
74
- Initialize CocoEval using coco APIs for gt and dt
75
- :param cocoGt: coco object with ground truth annotations
74
+ """Initialize CocoEval using coco APIs for gt and dt :param cocoGt:
75
+
76
+ coco object with ground truth annotations
76
77
  :param cocoDt: coco object with detection results
77
- :return: None
78
+ :return: None.
79
+
78
80
  """
79
81
  if not iouType:
80
82
  logger.warning("iouType not specified. use default iouType segm")
@@ -101,9 +103,10 @@ class COCOeval:
101
103
  self.print_function = print_function # output print function
102
104
 
103
105
  def _prepare(self):
104
- """
105
- Prepare ._gts and ._dts for evaluation based on params
106
+ """Prepare ._gts and ._dts for evaluation based on params.
107
+
106
108
  :return: None
109
+
107
110
  """
108
111
 
109
112
  def _toMask(anns, coco):
@@ -145,9 +148,11 @@ class COCOeval:
145
148
  self.eval = {} # accumulated evaluation results
146
149
 
147
150
  def evaluate(self):
148
- """
149
- Run per image evaluation on given images and store results (a list of dict) in self.evalImgs
151
+ """Run per image evaluation on given images and store results (a list
152
+ of dict) in self.evalImgs.
153
+
150
154
  :return: None
155
+
151
156
  """
152
157
  tic = time.time()
153
158
  self.print_function("Running per image evaluation...")
@@ -156,9 +161,8 @@ class COCOeval:
156
161
  if p.useSegm is not None:
157
162
  p.iouType = "segm" if p.useSegm == 1 else "bbox"
158
163
  logger.warning(
159
- "useSegm (deprecated) is not None. Running {} evaluation".format(
160
- p.iouType
161
- )
164
+ "useSegm (deprecated) is not None. Running {} evaluation"
165
+ .format(p.iouType)
162
166
  )
163
167
  self.print_function("Evaluate annotation type *{}*".format(p.iouType))
164
168
  p.imgIds = list(np.unique(p.imgIds))
@@ -268,21 +272,17 @@ class COCOeval:
268
272
  dy = np.max((z, y0 - yd), axis=0) + np.max(
269
273
  (z, yd - y1), axis=0
270
274
  )
271
- e = (
272
- (dx ** 2 + dy ** 2)
273
- / vars
274
- / (gt["area"] + np.spacing(1))
275
- / 2
276
- )
275
+ e = (dx**2 + dy**2) / vars / (gt["area"] + np.spacing(1)) / 2
277
276
  if k1 > 0:
278
277
  e = e[vg > 0]
279
278
  ious[i, j] = np.sum(np.exp(-e)) / e.shape[0]
280
279
  return ious
281
280
 
282
281
  def evaluateImg(self, imgId, catId, aRng, maxDet):
283
- """
284
- perform evaluation for single category and image
282
+ """Perform evaluation for single category and image.
283
+
285
284
  :return: dict (single image results)
285
+
286
286
  """
287
287
  p = self.params
288
288
  if p.useCats:
@@ -336,7 +336,7 @@ class COCOeval:
336
336
  # continue to next gt unless better match made
337
337
  if ious[dind, gind] < iou:
338
338
  continue
339
- # if match successful and best so far, store appropriately
339
+ # if match successful and best so far, store appropriately # noqa: E501
340
340
  iou = ious[dind, gind]
341
341
  m = gind
342
342
  # if match made store id of match for both dt and gt
@@ -369,14 +369,19 @@ class COCOeval:
369
369
  raise DeprecationWarning("deprecated")
370
370
 
371
371
  def summarize(self):
372
- """
373
- Compute and display summary metrics for evaluation results.
374
- Note this functin can *only* be applied on the default parameter setting
372
+ """Compute and display summary metrics for evaluation results.
373
+
374
+ Note this functin can *only* be applied on the default parameter
375
+ setting
376
+
375
377
  """
376
378
 
377
379
  def _summarize(ap=1, iouThr=None, areaRng="all", maxDets=100):
378
380
  p = self.params
379
- iStr = " {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] = {:0.3f}"
381
+ iStr = (
382
+ " {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] ="
383
+ " {:0.3f}"
384
+ )
380
385
  titleStr = "Average Precision" if ap == 1 else "Average Recall"
381
386
  typeStr = "(AP)" if ap == 1 else "(AR)"
382
387
  iouStr = (
@@ -489,14 +494,12 @@ class COCOeval:
489
494
 
490
495
 
491
496
  class Params:
492
- """
493
- Params for coco evaluation api
494
- """
497
+ """Params for coco evaluation api."""
495
498
 
496
499
  def setDetParams(self):
497
500
  self.imgIds = []
498
501
  self.catIds = []
499
- # np.arange causes trouble. the data point on arange is slightly larger than the true value
502
+ # np.arange causes trouble. the data point on arange is slightly larger than the true value # noqa: E501
500
503
  self.iouThrs = np.linspace(
501
504
  0.5, 0.95, int(np.round((0.95 - 0.5) / 0.05)) + 1, endpoint=True
502
505
  )
@@ -505,10 +508,10 @@ class Params:
505
508
  )
506
509
  self.maxDets = [1, 10, 100]
507
510
  self.areaRng = [
508
- [0 ** 2, 1e5 ** 2],
509
- [0 ** 2, 32 ** 2],
510
- [32 ** 2, 96 ** 2],
511
- [96 ** 2, 1e5 ** 2],
511
+ [0**2, 1e5**2],
512
+ [0**2, 32**2],
513
+ [32**2, 96**2],
514
+ [96**2, 1e5**2],
512
515
  ]
513
516
  self.areaRngLbl = ["all", "small", "medium", "large"]
514
517
  self.useCats = 1
@@ -516,7 +519,7 @@ class Params:
516
519
  def setKpParams(self):
517
520
  self.imgIds = []
518
521
  self.catIds = []
519
- # np.arange causes trouble. the data point on arange is slightly larger than the true value
522
+ # np.arange causes trouble. the data point on arange is slightly larger than the true value # noqa: E501
520
523
  self.iouThrs = np.linspace(
521
524
  0.5, 0.95, int(np.round((0.95 - 0.5) / 0.05)) + 1, endpoint=True
522
525
  )
@@ -525,9 +528,9 @@ class Params:
525
528
  )
526
529
  self.maxDets = [20]
527
530
  self.areaRng = [
528
- [0 ** 2, 1e5 ** 2],
529
- [32 ** 2, 96 ** 2],
530
- [96 ** 2, 1e5 ** 2],
531
+ [0**2, 1e5**2],
532
+ [32**2, 96**2],
533
+ [96**2, 1e5**2],
531
534
  ]
532
535
  self.areaRngLbl = ["all", "medium", "large"]
533
536
  self.useCats = 1