faster-coco-eval 1.4.3__tar.gz → 1.5.2__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 (35) hide show
  1. {faster-coco-eval-1.4.3/faster_coco_eval.egg-info → faster_coco_eval-1.5.2}/PKG-INFO +29 -7
  2. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/README.md +28 -6
  3. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/core/coco.py +91 -37
  4. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/core/cocoeval.py +32 -24
  5. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/core/faster_eval_api.py +24 -18
  6. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/core/mask.py +3 -3
  7. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/extra/curves.py +9 -44
  8. faster_coco_eval-1.5.2/faster_coco_eval/extra/display.py +126 -0
  9. faster_coco_eval-1.5.2/faster_coco_eval/extra/draw.py +379 -0
  10. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/extra/extra.py +28 -0
  11. faster_coco_eval-1.5.2/faster_coco_eval/extra/utils.py +86 -0
  12. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/version.py +1 -1
  13. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2/faster_coco_eval.egg-info}/PKG-INFO +29 -7
  14. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval.egg-info/SOURCES.txt +3 -1
  15. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/pyproject.toml +1 -5
  16. faster_coco_eval-1.5.2/requirements/extra.txt +1 -0
  17. faster_coco_eval-1.5.2/setup.cfg +4 -0
  18. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/setup.py +7 -5
  19. faster-coco-eval-1.4.3/faster_coco_eval/extra/display.py +0 -330
  20. faster-coco-eval-1.4.3/setup.cfg +0 -13
  21. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/LICENSE +0 -0
  22. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/MANIFEST.in +0 -0
  23. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +0 -0
  24. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/faster_eval_api/coco_eval/cocoeval.h +0 -0
  25. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/faster_eval_api/faster_eval_api.cpp +0 -0
  26. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/mask/common/maskApi.c +0 -0
  27. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/mask/common/maskApi.h +0 -0
  28. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/csrc/mask/pycocotools/_mask.pyx +0 -0
  29. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/__init__.py +0 -0
  30. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/core/__init__.py +0 -0
  31. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval/extra/__init__.py +0 -0
  32. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
  33. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval.egg-info/requires.txt +0 -0
  34. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/faster_coco_eval.egg-info/top_level.txt +0 -0
  35. {faster-coco-eval-1.4.3 → faster_coco_eval-1.5.2}/requirements/runtime.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: faster-coco-eval
3
- Version: 1.4.3
3
+ Version: 1.5.2
4
4
  Summary: Faster interpretation of the original COCOEval
5
5
  Home-page: https://github.com/MiXaiLL76/faster_coco_eval
6
6
  Author: MiXaiLL76
@@ -25,6 +25,13 @@ Requires-Dist: Pillow
25
25
 
26
26
  # Faster-COCO-Eval
27
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
+
28
35
  ## Disclaimer
29
36
 
30
37
  I often use this project, but I saw it abandoned and without a public repository on github.
@@ -42,13 +49,16 @@ for coco's AP metrics, especially when dealing with a high number of instances i
42
49
  For our use case with a test dataset of 5000 images from the coco val dataset.
43
50
  Testing was carried out using the mmdetection framework and the eval_metric.py script. The indicators are presented below.
44
51
 
45
- Visualization of testing **comparison.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/comparison.ipynb)
46
- Tested with yolo3 model (bbox eval) and yoloact model (segm eval)
52
+ Visualization of testing **colab_example.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/mmdet/colab_example.ipynb)
53
+ [colab_example.ipynb in google collab](https://drive.google.com/file/d/13raC0nRsil797ITJSv3FTRvUvfEK9SD-/view?usp=sharing)
54
+ Tested with rtmdet model bbox + segm
55
+
56
+ ### Summary for 5000 imgs
47
57
 
48
- | Type | COCOeval | COCOeval_faster | Profit |
49
- | ---- | ----------- | --------------- | ----------- |
50
- | bbox | 18.477 sec. | 7.345 sec. | 2.5x faster |
51
- | segm | 29.819 sec. | 15.840 sec. | 2x faster |
58
+ | Type | faster-coco-eval | pycocotools | Profit |
59
+ | :--- | ---------------: | ----------: | -----: |
60
+ | bbox | 5.812 | 22.72 | 3.909 |
61
+ | segm | 7.413 | 24.434 | 3.296 |
52
62
 
53
63
  ## Feautures
54
64
 
@@ -67,3 +77,15 @@ Available via link [history.md](https://github.com/MiXaiLL76/faster_coco_eval/bl
67
77
 
68
78
  The original module was licensed with apache 2, I will continue with the same license.
69
79
  Distributed under the apache version 2.0 license, see [license](LICENSE) for more information.
80
+
81
+ ## Citation
82
+
83
+ If you use this benchmark in your research, please cite this project.
84
+
85
+ ```
86
+ @article{faster-coco-eval,
87
+ title = {{Faster-COCO-Eval}: Faster interpretation of the original COCOEval},
88
+ author = {MiXaiLL76},
89
+ year = {2024}
90
+ }
91
+ ```
@@ -1,5 +1,12 @@
1
1
  # Faster-COCO-Eval
2
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
+
3
10
  ## Disclaimer
4
11
 
5
12
  I often use this project, but I saw it abandoned and without a public repository on github.
@@ -17,13 +24,16 @@ for coco's AP metrics, especially when dealing with a high number of instances i
17
24
  For our use case with a test dataset of 5000 images from the coco val dataset.
18
25
  Testing was carried out using the mmdetection framework and the eval_metric.py script. The indicators are presented below.
19
26
 
20
- Visualization of testing **comparison.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/comparison.ipynb)
21
- Tested with yolo3 model (bbox eval) and yoloact model (segm eval)
27
+ Visualization of testing **colab_example.ipynb** available in directory [examples/comparison](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/examples/comparison/mmdet/colab_example.ipynb)
28
+ [colab_example.ipynb in google collab](https://drive.google.com/file/d/13raC0nRsil797ITJSv3FTRvUvfEK9SD-/view?usp=sharing)
29
+ Tested with rtmdet model bbox + segm
30
+
31
+ ### Summary for 5000 imgs
22
32
 
23
- | Type | COCOeval | COCOeval_faster | Profit |
24
- | ---- | ----------- | --------------- | ----------- |
25
- | bbox | 18.477 sec. | 7.345 sec. | 2.5x faster |
26
- | segm | 29.819 sec. | 15.840 sec. | 2x faster |
33
+ | Type | faster-coco-eval | pycocotools | Profit |
34
+ | :--- | ---------------: | ----------: | -----: |
35
+ | bbox | 5.812 | 22.72 | 3.909 |
36
+ | segm | 7.413 | 24.434 | 3.296 |
27
37
 
28
38
  ## Feautures
29
39
 
@@ -42,3 +52,15 @@ Available via link [history.md](https://github.com/MiXaiLL76/faster_coco_eval/bl
42
52
 
43
53
  The original module was licensed with apache 2, I will continue with the same license.
44
54
  Distributed under the apache version 2.0 license, see [license](LICENSE) for more information.
55
+
56
+ ## Citation
57
+
58
+ If you use this benchmark in your research, please cite this project.
59
+
60
+ ```
61
+ @article{faster-coco-eval,
62
+ title = {{Faster-COCO-Eval}: Faster interpretation of the original COCOEval},
63
+ author = {MiXaiLL76},
64
+ year = {2024}
65
+ }
66
+ ```
@@ -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))
@@ -275,9 +279,10 @@ class COCOeval:
275
279
  return ious
276
280
 
277
281
  def evaluateImg(self, imgId, catId, aRng, maxDet):
278
- """
279
- perform evaluation for single category and image
282
+ """Perform evaluation for single category and image.
283
+
280
284
  :return: dict (single image results)
285
+
281
286
  """
282
287
  p = self.params
283
288
  if p.useCats:
@@ -331,7 +336,7 @@ class COCOeval:
331
336
  # continue to next gt unless better match made
332
337
  if ious[dind, gind] < iou:
333
338
  continue
334
- # if match successful and best so far, store appropriately
339
+ # if match successful and best so far, store appropriately # noqa: E501
335
340
  iou = ious[dind, gind]
336
341
  m = gind
337
342
  # if match made store id of match for both dt and gt
@@ -364,14 +369,19 @@ class COCOeval:
364
369
  raise DeprecationWarning("deprecated")
365
370
 
366
371
  def summarize(self):
367
- """
368
- Compute and display summary metrics for evaluation results.
369
- 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
+
370
377
  """
371
378
 
372
379
  def _summarize(ap=1, iouThr=None, areaRng="all", maxDets=100):
373
380
  p = self.params
374
- iStr = " {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] = {:0.3f}"
381
+ iStr = (
382
+ " {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] ="
383
+ " {:0.3f}"
384
+ )
375
385
  titleStr = "Average Precision" if ap == 1 else "Average Recall"
376
386
  typeStr = "(AP)" if ap == 1 else "(AR)"
377
387
  iouStr = (
@@ -484,14 +494,12 @@ class COCOeval:
484
494
 
485
495
 
486
496
  class Params:
487
- """
488
- Params for coco evaluation api
489
- """
497
+ """Params for coco evaluation api."""
490
498
 
491
499
  def setDetParams(self):
492
500
  self.imgIds = []
493
501
  self.catIds = []
494
- # 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
495
503
  self.iouThrs = np.linspace(
496
504
  0.5, 0.95, int(np.round((0.95 - 0.5) / 0.05)) + 1, endpoint=True
497
505
  )
@@ -511,7 +519,7 @@ class Params:
511
519
  def setKpParams(self):
512
520
  self.imgIds = []
513
521
  self.catIds = []
514
- # 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
515
523
  self.iouThrs = np.linspace(
516
524
  0.5, 0.95, int(np.round((0.95 - 0.5) / 0.05)) + 1, endpoint=True
517
525
  )
@@ -3,10 +3,12 @@
3
3
 
4
4
  import copy
5
5
  import logging
6
- import numpy as np
7
6
  import time
8
7
 
8
+ import numpy as np
9
+
9
10
  import faster_coco_eval.faster_eval_api_cpp as _C
11
+
10
12
  from . import mask as maskUtils
11
13
  from .cocoeval import COCOeval
12
14
 
@@ -14,18 +16,20 @@ logger = logging.getLogger(__name__)
14
16
 
15
17
 
16
18
  class COCOeval_faster(COCOeval):
17
- """
18
- This is a slightly modified version of the original COCO API, where the functions evaluateImg()
19
- and accumulate() are implemented in C++ to speedup evaluation
20
- """
19
+ """This is a slightly modified version of the original COCO API, where the
20
+ functions evaluateImg() and accumulate() are implemented in C++ to speedup
21
+ evaluation."""
21
22
 
22
23
  def evaluate(self):
23
- """
24
- Run per image evaluation on given images and store results in self.evalImgs_cpp, a
25
- datastructure that isn't readable from Python but is used by a c++ implementation of
26
- accumulate(). Unlike the original COCO PythonAPI, we don't populate the datastructure
27
- self.evalImgs because this datastructure is a computational bottleneck.
24
+ """Run per image evaluation on given images and store results in
25
+ self.evalImgs_cpp, a datastructure that isn't readable from Python but
26
+ is used by a c++ implementation of accumulate().
27
+
28
+ Unlike the original COCO PythonAPI, we don't populate the
29
+ datastructure self.evalImgs because this datastructure is a
30
+ computational bottleneck.
28
31
  :return: None
32
+
29
33
  """
30
34
  tic = time.time()
31
35
 
@@ -61,7 +65,7 @@ class COCOeval_faster(COCOeval):
61
65
 
62
66
  # <<<< Beginning of code differences with original COCO API
63
67
  def convert_instances_to_cpp(instances, is_det=False):
64
- # Convert annotations for a list of instances in an image to a format that's fast
68
+ # Convert annotations for a list of instances in an image to a format that's fast # noqa: E501
65
69
  # to access in C++
66
70
  instances_cpp = []
67
71
  for instance in instances:
@@ -75,7 +79,7 @@ class COCOeval_faster(COCOeval):
75
79
  instances_cpp.append(instance_cpp)
76
80
  return instances_cpp
77
81
 
78
- # Convert GT annotations, detections, and IOUs to a format that's fast to access in C++
82
+ # Convert GT annotations, detections, and IOUs to a format that's fast to access in C++ # noqa: E501
79
83
  ground_truth_instances = [
80
84
  [
81
85
  convert_instances_to_cpp(self._gts[imgId, catId])
@@ -122,9 +126,12 @@ class COCOeval_faster(COCOeval):
122
126
  self.print_function("DONE (t={:0.2f}s).".format(toc - tic))
123
127
 
124
128
  def accumulate(self):
125
- """
126
- Accumulate per image evaluation results and store the result in self.eval. Does not
127
- support changing parameter settings from those used by self.evaluate()
129
+ """Accumulate per image evaluation results and store the result in
130
+ self.eval.
131
+
132
+ Does not support changing parameter settings from those used by
133
+ self.evaluate()
134
+
128
135
  """
129
136
  self.print_function("Accumulating evaluation results...")
130
137
  tic = time.time()
@@ -134,13 +141,12 @@ class COCOeval_faster(COCOeval):
134
141
 
135
142
  self.eval = _C.COCOevalAccumulate(self._paramsEval, self._evalImgs_cpp)
136
143
 
137
- # recall is num_iou_thresholds X num_categories X num_area_ranges X num_max_detections
144
+ # recall is num_iou_thresholds X num_categories X num_area_ranges X num_max_detections # noqa: E501
138
145
  self.eval["recall"] = np.array(self.eval["recall"]).reshape(
139
146
  self.eval["counts"][:1] + self.eval["counts"][2:]
140
147
  )
141
148
 
142
- # precision and scores are num_iou_thresholds X num_recall_thresholds X num_categories X
143
- # num_area_ranges X num_max_detections
149
+ # precision and scores are num_iou_thresholds X num_recall_thresholds X num_categories X num_area_ranges X num_max_detections # noqa: E501
144
150
  self.eval["precision"] = np.array(self.eval["precision"]).reshape(
145
151
  self.eval["counts"]
146
152
  )
@@ -34,7 +34,7 @@ import faster_coco_eval.mask_api_cpp as _mask
34
34
  # iou - Compute intersection over union between masks.
35
35
  # area - Compute area of encoded masks.
36
36
  # toBbox - Get bounding boxes surrounding encoded masks.
37
- # frPyObjects - Convert polygon, bbox, and uncompressed RLE to encoded RLE mask.
37
+ # frPyObjects - Convert polygon, bbox, and uncompressed RLE to encoded RLE mask. # noqa: E501
38
38
  #
39
39
  # Usage:
40
40
  # Rs = encode( masks )
@@ -48,8 +48,8 @@ import faster_coco_eval.mask_api_cpp as _mask
48
48
  # In the API the following formats are used:
49
49
  # Rs - [dict] Run-length encoding of binary masks
50
50
  # R - dict Run-length encoding of binary mask
51
- # masks - [hxwxn] Binary mask(s) (must have type np.ndarray(dtype=uint8) in column-major order)
52
- # iscrowd - [nx1] list of np.ndarray. 1 indicates corresponding gt image has crowd region to ignore
51
+ # masks - [hxwxn] Binary mask(s) (must have type np.ndarray(dtype=uint8) in column-major order) # noqa: E501
52
+ # iscrowd - [nx1] list of np.ndarray. 1 indicates corresponding gt image has crowd region to ignore # noqa: E501
53
53
  # bbs - [nx4] Bounding box(es) stored as [x y w h]
54
54
  # poly - Polygon stored as [[x1 y1 x2 y2...],[x1 y1 ...],...] (2D list)
55
55
  # dt,gt - May be either bounding boxes or encoded masks