faster-coco-eval 1.3.0__tar.gz → 1.3.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 (29) hide show
  1. {faster-coco-eval-1.3.0/faster_coco_eval.egg-info → faster-coco-eval-1.3.1}/PKG-INFO +8 -2
  2. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/README.md +7 -1
  3. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/core/cocoeval.py +17 -12
  4. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/core/faster_eval_api.py +10 -6
  5. faster-coco-eval-1.3.1/faster_coco_eval/core/mask.py +98 -0
  6. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/version.py +1 -1
  7. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1/faster_coco_eval.egg-info}/PKG-INFO +8 -2
  8. faster-coco-eval-1.3.0/faster_coco_eval/core/mask.py +0 -107
  9. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/LICENSE +0 -0
  10. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/MANIFEST.in +0 -0
  11. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +0 -0
  12. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/faster_eval_api/coco_eval/cocoeval.h +0 -0
  13. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/faster_eval_api/faster_eval_api.cpp +0 -0
  14. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/mask/common/maskApi.c +0 -0
  15. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/mask/common/maskApi.h +0 -0
  16. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/mask/pycocotools/_mask.c +0 -0
  17. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/csrc/mask/pycocotools/_mask.pyx +0 -0
  18. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/__init__.py +0 -0
  19. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/core/__init__.py +0 -0
  20. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/core/coco.py +0 -0
  21. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/extra/__init__.py +0 -0
  22. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval/extra/curves.py +0 -0
  23. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval.egg-info/SOURCES.txt +0 -0
  24. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
  25. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval.egg-info/requires.txt +0 -0
  26. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/faster_coco_eval.egg-info/top_level.txt +0 -0
  27. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/pyproject.toml +0 -0
  28. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/setup.cfg +0 -0
  29. {faster-coco-eval-1.3.0 → faster-coco-eval-1.3.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: faster-coco-eval
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Faster interpretation of the original COCOEval
5
5
  Home-page: https://github.com/MiXaiLL76/faster_coco_eval
6
6
  Author: MiXaiLL76
@@ -61,7 +61,8 @@ For usage, look at the original `COCOEval` [class documentation.](https://github
61
61
  ## Usage plot curves
62
62
 
63
63
  ````python
64
- from faster_coco_eval.extra import Curves, COCO
64
+ from faster_coco_eval import COCO
65
+ from faster_coco_eval.extra import Curves
65
66
 
66
67
  cocoGt = COCO(....)
67
68
  cocoDt = cocoGt.loadRes(....)
@@ -77,6 +78,11 @@ cur.plot_pre_rec(plotly_backend=False)
77
78
 
78
79
  ## history
79
80
 
81
+ ### v1.3.1
82
+
83
+ - [x] rework mask code
84
+ - [x] change np.float to float ([numpy deprecations](https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations))
85
+
80
86
  ### v1.3.0
81
87
 
82
88
  - [x] remove pycocotools dependencies
@@ -41,7 +41,8 @@ For usage, look at the original `COCOEval` [class documentation.](https://github
41
41
  ## Usage plot curves
42
42
 
43
43
  ````python
44
- from faster_coco_eval.extra import Curves, COCO
44
+ from faster_coco_eval import COCO
45
+ from faster_coco_eval.extra import Curves
45
46
 
46
47
  cocoGt = COCO(....)
47
48
  cocoDt = cocoGt.loadRes(....)
@@ -57,6 +58,11 @@ cur.plot_pre_rec(plotly_backend=False)
57
58
 
58
59
  ## history
59
60
 
61
+ ### v1.3.1
62
+
63
+ - [x] rework mask code
64
+ - [x] change np.float to float ([numpy deprecations](https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations))
65
+
60
66
  ### v1.3.0
61
67
 
62
68
  - [x] remove pycocotools dependencies
@@ -61,7 +61,7 @@ class COCOeval:
61
61
  # Data, paper, and tutorials available at: http://mscoco.org/
62
62
  # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
63
63
  # Licensed under the Simplified BSD License [see coco/license.txt]
64
- def __init__(self, cocoGt=None, cocoDt=None, iouType='segm'):
64
+ def __init__(self, cocoGt=None, cocoDt=None, iouType='segm', print_function=logger.debug):
65
65
  '''
66
66
  Initialize CocoEval using coco APIs for gt and dt
67
67
  :param cocoGt: coco object with ground truth annotations
@@ -69,7 +69,8 @@ class COCOeval:
69
69
  :return: None
70
70
  '''
71
71
  if not iouType:
72
- logger.debug('iouType not specified. use default iouType segm')
72
+ logger.warning('iouType not specified. use default iouType segm')
73
+
73
74
  self.cocoGt = cocoGt # ground truth COCO API
74
75
  self.cocoDt = cocoDt # detections COCO API
75
76
  # per-image per-category evaluation results [KxAxI] elements
@@ -81,10 +82,13 @@ class COCOeval:
81
82
  self._paramsEval = {} # parameters for evaluation
82
83
  self.stats = [] # result summarization
83
84
  self.ious = {} # ious between all gts and dts
85
+
84
86
  if not cocoGt is None:
85
87
  self.params.imgIds = sorted(cocoGt.getImgIds())
86
88
  self.params.catIds = sorted(cocoGt.getCatIds())
87
89
 
90
+ self.print_function = print_function # output print function
91
+
88
92
  def _prepare(self):
89
93
  '''
90
94
  Prepare ._gts and ._dts for evaluation based on params
@@ -131,14 +135,14 @@ class COCOeval:
131
135
  :return: None
132
136
  '''
133
137
  tic = time.time()
134
- logger.debug('Running per image evaluation...')
138
+ self.print_function('Running per image evaluation...')
135
139
  p = self.params
136
140
  # add backward compatibility if useSegm is specified in params
137
141
  if not p.useSegm is None:
138
142
  p.iouType = 'segm' if p.useSegm == 1 else 'bbox'
139
143
  logger.warning(
140
144
  'useSegm (deprecated) is not None. Running {} evaluation'.format(p.iouType))
141
- logger.debug('Evaluate annotation type *{}*'.format(p.iouType))
145
+ self.print_function('Evaluate annotation type *{}*'.format(p.iouType))
142
146
  p.imgIds = list(np.unique(p.imgIds))
143
147
  if p.useCats:
144
148
  p.catIds = list(np.unique(p.catIds))
@@ -166,7 +170,7 @@ class COCOeval:
166
170
  ]
167
171
  self._paramsEval = copy.deepcopy(self.params)
168
172
  toc = time.time()
169
- logger.debug('DONE (t={:0.2f}s).'.format(toc-tic))
173
+ self.print_function('DONE (t={:0.2f}s).'.format(toc-tic))
170
174
 
171
175
  def computeIoU(self, imgId, catId):
172
176
  p = self.params
@@ -334,10 +338,10 @@ class COCOeval:
334
338
  :param p: input params for evaluation
335
339
  :return: None
336
340
  '''
337
- logger.debug('Accumulating evaluation results...')
341
+ self.print_function('Accumulating evaluation results...')
338
342
  tic = time.time()
339
343
  if not self.evalImgs:
340
- logger.debug('Please run evaluate() first')
344
+ self.print_function('Please run evaluate() first')
341
345
  # allows input customized parameters
342
346
  if p is None:
343
347
  p = self.params
@@ -412,8 +416,9 @@ class COCOeval:
412
416
  _matches.append(
413
417
  np.vstack([gtm_ids, dtm_ids, tps]).astype(np.int32).T)
414
418
 
415
- tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
416
- fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
419
+ tp_sum = np.cumsum(tps, axis=1).astype(dtype=float)
420
+ fp_sum = np.cumsum(fps, axis=1).astype(dtype=float)
421
+
417
422
  for t, (tp, fp) in enumerate(zip(tp_sum, fp_sum)):
418
423
  tp = np.array(tp)
419
424
  fp = np.array(fp)
@@ -460,7 +465,7 @@ class COCOeval:
460
465
  }
461
466
 
462
467
  toc = time.time()
463
- logger.debug('DONE (t={:0.2f}s).'.format(toc-tic))
468
+ self.print_function('DONE (t={:0.2f}s).'.format(toc-tic))
464
469
 
465
470
  def summarize(self):
466
471
  '''
@@ -497,8 +502,8 @@ class COCOeval:
497
502
  mean_s = -1
498
503
  else:
499
504
  mean_s = np.mean(s[s > -1])
500
- logger.debug(iStr.format(titleStr, typeStr,
501
- iouStr, areaRng, maxDets, mean_s))
505
+ self.print_function(iStr.format(titleStr, typeStr,
506
+ iouStr, areaRng, maxDets, mean_s))
502
507
  return mean_s
503
508
 
504
509
  def _summarizeDets():
@@ -33,7 +33,7 @@ class COCOeval_faster(COCOeval):
33
33
  if p.useSegm is not None:
34
34
  p.iouType = "segm" if p.useSegm == 1 else "bbox"
35
35
 
36
- logger.debug("Evaluate annotation type *{}*".format(p.iouType))
36
+ self.print_function("Evaluate annotation type *{}*".format(p.iouType))
37
37
 
38
38
  p.imgIds = list(np.unique(p.imgIds))
39
39
  if p.useCats:
@@ -101,16 +101,18 @@ class COCOeval_faster(COCOeval):
101
101
  self._evalImgs = None
102
102
 
103
103
  self._paramsEval = copy.deepcopy(self.params)
104
+
104
105
  toc = time.time()
105
- logger.debug(
106
- "COCOeval_opt.evaluate() finished in {:0.2f} seconds.".format(toc - tic))
106
+
107
+ self.print_function('COCOeval_opt.evaluate() finished...')
108
+ self.print_function('DONE (t={:0.2f}s).'.format(toc-tic))
107
109
 
108
110
  def accumulate(self):
109
111
  """
110
112
  Accumulate per image evaluation results and store the result in self.eval. Does not
111
113
  support changing parameter settings from those used by self.evaluate()
112
114
  """
113
- logger.debug("Accumulating evaluation results...")
115
+ self.print_function("Accumulating evaluation results...")
114
116
  tic = time.time()
115
117
  assert hasattr(
116
118
  self, "_evalImgs_cpp"
@@ -129,6 +131,8 @@ class COCOeval_faster(COCOeval):
129
131
  self.eval["precision"]).reshape(self.eval["counts"])
130
132
  self.eval["scores"] = np.array(
131
133
  self.eval["scores"]).reshape(self.eval["counts"])
134
+
132
135
  toc = time.time()
133
- logger.debug(
134
- "COCOeval_opt.accumulate() finished in {:0.2f} seconds.".format(toc - tic))
136
+
137
+ self.print_function('COCOeval_opt.accumulate() finished...')
138
+ self.print_function('DONE (t={:0.2f}s).'.format(toc-tic))
@@ -0,0 +1,98 @@
1
+ """The following API functions are defined
2
+ ----------
3
+ encode : Encode binary masks using RLE.
4
+ decode : Decode binary masks encoded via RLE.
5
+ merge : Compute union or intersection of encoded masks.
6
+ iou : Compute intersection over union between masks.
7
+ area : Compute area of encoded masks.
8
+ toBbox : Get bounding boxes surrounding encoded masks.
9
+ frPyObjects : Convert polygon, bbox, and uncompressed RLE to encoded RLE mask.
10
+
11
+ Usage
12
+ ----------
13
+ Rs : encode( masks )
14
+ masks : decode( Rs )
15
+ R : merge( Rs, intersect=false )
16
+ o : iou( dt, gt, iscrowd )
17
+ a : area( Rs )
18
+ bbs : toBbox( Rs )
19
+ Rs : frPyObjects( [pyObjects], h, w )
20
+
21
+ In the API the following formats are used
22
+ ----------
23
+ Rs : [dict] Run-length encoding of binary masks
24
+ R : dict Run-length encoding of binary mask
25
+ masks : [hxwxn] Binary mask(s) (must have type np.ndarray(dtype=uint8) in column:major order)
26
+ iscrowd : [nx1] list of np.ndarray. 1 indicates corresponding gt image has crowd region to ignore
27
+ bbs : [nx4] Bounding box(es) stored as [x y w h]
28
+ poly : Polygon stored as [[x1 y1 x2 y2...],[x1 y1 ...],...] (2D list)
29
+ dt,gt : May be either bounding boxes or encoded masks
30
+
31
+ Both poly and bbs are 0-indexed (bbox=[0 0 1 1] encloses first pixel).
32
+ """
33
+
34
+ import faster_coco_eval.mask_api_cpp as _mask
35
+ import numpy as np
36
+
37
+
38
+ def merge(rleObjs):
39
+ """Compute union or intersection of encoded masks."""
40
+ return _mask.merge(rleObjs)
41
+
42
+
43
+ def frPyObjects(segm: list, h: int, w: int):
44
+ """Convert polygon, bbox, and uncompressed RLE to encoded RLE mask."""
45
+ return _mask.frPyObjects(segm, h, w)
46
+
47
+
48
+ def iou(d: list, g: list, iscrowd: list):
49
+ """Compute intersection over union between masks.
50
+
51
+ Parameters
52
+ ----------
53
+ d : array_like
54
+ Detected (dt). May be either bounding boxes or encoded masks.
55
+ g : array_like
56
+ Ground truth (gt). May be either bounding boxes or encoded masks.
57
+ iscrowd : [nx1] list of np.ndarray
58
+ 1 indicates corresponding gt image has crowd region to ignore.
59
+
60
+ Returns
61
+ -------
62
+ iou_array : np.ndarray
63
+ Intersection over union between masks or bbox.
64
+ """
65
+ return _mask.iou(d, g, iscrowd)
66
+
67
+
68
+ def encode(bimask: np.ndarray):
69
+ """Encode binary masks using RLE."""
70
+ if len(bimask.shape) == 3:
71
+ return _mask.encode(bimask)
72
+ elif len(bimask.shape) == 2:
73
+ h, w = bimask.shape
74
+ return _mask.encode(bimask.reshape((h, w, 1), order='F'))[0]
75
+
76
+
77
+ def decode(rleObjs):
78
+ """Decode binary masks encoded via RLE."""
79
+ if type(rleObjs) == list:
80
+ return _mask.decode(rleObjs)
81
+ else:
82
+ return _mask.decode([rleObjs])[:, :, 0]
83
+
84
+
85
+ def area(rleObjs):
86
+ """Compute area of encoded masks."""
87
+ if type(rleObjs) == list:
88
+ return _mask.area(rleObjs)
89
+ else:
90
+ return _mask.area([rleObjs])[0]
91
+
92
+
93
+ def toBbox(rleObjs):
94
+ """Get bounding boxes surrounding encoded masks."""
95
+ if type(rleObjs) == list:
96
+ return _mask.toBbox(rleObjs)
97
+ else:
98
+ return _mask.toBbox([rleObjs])[0]
@@ -1,2 +1,2 @@
1
- __version__ = '1.3.0'
1
+ __version__ = '1.3.1'
2
2
  __author__ = 'MiXaiLL76'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: faster-coco-eval
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Faster interpretation of the original COCOEval
5
5
  Home-page: https://github.com/MiXaiLL76/faster_coco_eval
6
6
  Author: MiXaiLL76
@@ -61,7 +61,8 @@ For usage, look at the original `COCOEval` [class documentation.](https://github
61
61
  ## Usage plot curves
62
62
 
63
63
  ````python
64
- from faster_coco_eval.extra import Curves, COCO
64
+ from faster_coco_eval import COCO
65
+ from faster_coco_eval.extra import Curves
65
66
 
66
67
  cocoGt = COCO(....)
67
68
  cocoDt = cocoGt.loadRes(....)
@@ -77,6 +78,11 @@ cur.plot_pre_rec(plotly_backend=False)
77
78
 
78
79
  ## history
79
80
 
81
+ ### v1.3.1
82
+
83
+ - [x] rework mask code
84
+ - [x] change np.float to float ([numpy deprecations](https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations))
85
+
80
86
  ### v1.3.0
81
87
 
82
88
  - [x] remove pycocotools dependencies
@@ -1,107 +0,0 @@
1
- __author__ = 'tsungyi'
2
-
3
- import faster_coco_eval.mask_api_cpp as _mask
4
-
5
- # Interface for manipulating masks stored in RLE format.
6
- #
7
- # RLE is a simple yet efficient format for storing binary masks. RLE
8
- # first divides a vector (or vectorized image) into a series of piecewise
9
- # constant regions and then for each piece simply stores the length of
10
- # that piece. For example, given M=[0 0 1 1 1 0 1] the RLE counts would
11
- # be [2 3 1 1], or for M=[1 1 1 1 1 1 0] the counts would be [0 6 1]
12
- # (note that the odd counts are always the numbers of zeros). Instead of
13
- # storing the counts directly, additional compression is achieved with a
14
- # variable bitrate representation based on a common scheme called LEB128.
15
- #
16
- # Compression is greatest given large piecewise constant regions.
17
- # Specifically, the size of the RLE is proportional to the number of
18
- # *boundaries* in M (or for an image the number of boundaries in the y
19
- # direction). Assuming fairly simple shapes, the RLE representation is
20
- # O(sqrt(n)) where n is number of pixels in the object. Hence space usage
21
- # is substantially lower, especially for large simple objects (large n).
22
- #
23
- # Many common operations on masks can be computed directly using the RLE
24
- # (without need for decoding). This includes computations such as area,
25
- # union, intersection, etc. All of these operations are linear in the
26
- # size of the RLE, in other words they are O(sqrt(n)) where n is the area
27
- # of the object. Computing these operations on the original mask is O(n).
28
- # Thus, using the RLE can result in substantial computational savings.
29
- #
30
- # The following API functions are defined:
31
- # encode - Encode binary masks using RLE.
32
- # decode - Decode binary masks encoded via RLE.
33
- # merge - Compute union or intersection of encoded masks.
34
- # iou - Compute intersection over union between masks.
35
- # area - Compute area of encoded masks.
36
- # toBbox - Get bounding boxes surrounding encoded masks.
37
- # frPyObjects - Convert polygon, bbox, and uncompressed RLE to encoded RLE mask.
38
- #
39
- # Usage:
40
- # Rs = encode( masks )
41
- # masks = decode( Rs )
42
- # R = merge( Rs, intersect=false )
43
- # o = iou( dt, gt, iscrowd )
44
- # a = area( Rs )
45
- # bbs = toBbox( Rs )
46
- # Rs = frPyObjects( [pyObjects], h, w )
47
- #
48
- # In the API the following formats are used:
49
- # Rs - [dict] Run-length encoding of binary masks
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
53
- # bbs - [nx4] Bounding box(es) stored as [x y w h]
54
- # poly - Polygon stored as [[x1 y1 x2 y2...],[x1 y1 ...],...] (2D list)
55
- # dt,gt - May be either bounding boxes or encoded masks
56
- # Both poly and bbs are 0-indexed (bbox=[0 0 1 1] encloses first pixel).
57
- #
58
- # Finally, a note about the intersection over union (iou) computation.
59
- # The standard iou of a ground truth (gt) and detected (dt) object is
60
- # iou(gt,dt) = area(intersect(gt,dt)) / area(union(gt,dt))
61
- # For "crowd" regions, we use a modified criteria. If a gt object is
62
- # marked as "iscrowd", we allow a dt to match any subregion of the gt.
63
- # Choosing gt' in the crowd gt that best matches the dt can be done using
64
- # gt'=intersect(dt,gt). Since by definition union(gt',dt)=dt, computing
65
- # iou(gt,dt,iscrowd) = iou(gt',dt) = area(intersect(gt,dt)) / area(dt)
66
- # For crowd gt regions we use this modified criteria above for the iou.
67
- #
68
- # To compile run "python setup.py build_ext --inplace"
69
- # Please do not contact us for help with compiling.
70
- #
71
- # Microsoft COCO Toolbox. version 2.0
72
- # Data, paper, and tutorials available at: http://mscoco.org/
73
- # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
74
- # Licensed under the Simplified BSD License [see coco/license.txt]
75
-
76
- iou = _mask.iou
77
- merge = _mask.merge
78
- frPyObjects = _mask.frPyObjects
79
-
80
-
81
- def encode(bimask):
82
- if len(bimask.shape) == 3:
83
- return _mask.encode(bimask)
84
- elif len(bimask.shape) == 2:
85
- h, w = bimask.shape
86
- return _mask.encode(bimask.reshape((h, w, 1), order='F'))[0]
87
-
88
-
89
- def decode(rleObjs):
90
- if type(rleObjs) == list:
91
- return _mask.decode(rleObjs)
92
- else:
93
- return _mask.decode([rleObjs])[:, :, 0]
94
-
95
-
96
- def area(rleObjs):
97
- if type(rleObjs) == list:
98
- return _mask.area(rleObjs)
99
- else:
100
- return _mask.area([rleObjs])[0]
101
-
102
-
103
- def toBbox(rleObjs):
104
- if type(rleObjs) == list:
105
- return _mask.toBbox(rleObjs)
106
- else:
107
- return _mask.toBbox([rleObjs])[0]