faster-coco-eval 1.6.1__tar.gz → 1.6.3__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.
- {faster_coco_eval-1.6.1/faster_coco_eval.egg-info → faster_coco_eval-1.6.3}/PKG-INFO +1 -1
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/mask_api/src/mask.cpp +1 -1
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/mask_api/src/rle.cpp +1 -1
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/core/cocoeval.py +4 -4
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/version.py +1 -1
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3/faster_coco_eval.egg-info}/PKG-INFO +1 -1
- faster_coco_eval-1.6.3/tests/test_torchmetrics.py +305 -0
- faster_coco_eval-1.6.1/tests/test_torchmetrics.py +0 -103
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/LICENSE +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/MANIFEST.in +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/README.md +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/faster_eval_api/coco_eval/cocoeval.h +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/faster_eval_api/faster_eval_api.cpp +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/mask_api/mask_api.cpp +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/mask_api/src/mask.h +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/__init__.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/core/__init__.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/core/coco.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/core/faster_eval_api.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/core/mask.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/__init__.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/curves.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/display.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/draw.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/extra.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval/extra/utils.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval.egg-info/SOURCES.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval.egg-info/requires.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval.egg-info/top_level.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/pyproject.toml +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/requirements/extra.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/requirements/runtime.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/requirements/tests.txt +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/setup.cfg +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/setup.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_basic.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_boundary.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_coco_metric.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_init_pycocotools.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_keypoints.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_lvis_metric.py +0 -0
- {faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/tests/test_mask_api.py +0 -0
|
@@ -143,7 +143,7 @@ namespace mask_api
|
|
|
143
143
|
{
|
|
144
144
|
uint64_t h = (R[0].h), w = (R[0].w);
|
|
145
145
|
|
|
146
|
-
py::array_t<uint8_t> M({h, w, n});
|
|
146
|
+
py::array_t<uint8_t, py::array::f_style> M({(size_t)h, (size_t)w, (size_t)n});
|
|
147
147
|
auto mask = M.mutable_unchecked();
|
|
148
148
|
uint64_t s = h * w * n;
|
|
149
149
|
|
|
@@ -169,15 +169,15 @@ class COCOeval:
|
|
|
169
169
|
|
|
170
170
|
img_sizes = defaultdict(tuple)
|
|
171
171
|
|
|
172
|
-
def get_img_size_by_id(image_id) -> tuple:
|
|
172
|
+
def get_img_size_by_id(image_id, dataset: COCO) -> tuple:
|
|
173
173
|
if img_sizes.get(image_id) is None:
|
|
174
|
-
t =
|
|
174
|
+
t = dataset.imgs[image_id]
|
|
175
175
|
img_sizes[image_id] = t["height"], t["width"]
|
|
176
176
|
return img_sizes[image_id]
|
|
177
177
|
|
|
178
178
|
for gt in gts:
|
|
179
179
|
if p.compute_rle:
|
|
180
|
-
get_img_size_by_id(gt["image_id"])
|
|
180
|
+
get_img_size_by_id(gt["image_id"], self.cocoGt)
|
|
181
181
|
|
|
182
182
|
maskUtils.calculateRleForAllAnnotations(
|
|
183
183
|
gts,
|
|
@@ -206,7 +206,7 @@ class COCOeval:
|
|
|
206
206
|
)
|
|
207
207
|
|
|
208
208
|
if p.compute_rle:
|
|
209
|
-
get_img_size_by_id(dt["image_id"])
|
|
209
|
+
get_img_size_by_id(dt["image_id"], self.cocoDt)
|
|
210
210
|
|
|
211
211
|
maskUtils.calculateRleForAllAnnotations(
|
|
212
212
|
dts,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "1.6.
|
|
1
|
+
__version__ = "1.6.3"
|
|
2
2
|
__author__ = "MiXaiLL76"
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
from unittest import TestCase
|
|
4
|
+
|
|
5
|
+
from parameterized import parameterized
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
import torch
|
|
9
|
+
from lightning_utilities import apply_to_collection
|
|
10
|
+
from torch import BoolTensor, IntTensor, Tensor
|
|
11
|
+
from torchmetrics.detection.mean_ap import MeanAveragePrecision
|
|
12
|
+
except ImportError:
|
|
13
|
+
raise unittest.SkipTest("Skipping all tests for torchmetrics.")
|
|
14
|
+
|
|
15
|
+
# fmt: off
|
|
16
|
+
_inputs = {
|
|
17
|
+
"preds": [
|
|
18
|
+
[
|
|
19
|
+
{
|
|
20
|
+
"boxes": Tensor([[258.15, 41.29, 606.41, 285.07]]),
|
|
21
|
+
"scores": Tensor([0.236]),
|
|
22
|
+
"labels": IntTensor([4]),
|
|
23
|
+
}, # coco image id 42
|
|
24
|
+
{
|
|
25
|
+
"boxes": Tensor([
|
|
26
|
+
[61.00, 22.75, 565.00, 632.42],
|
|
27
|
+
[12.66, 3.32, 281.26, 275.23]]),
|
|
28
|
+
"scores": Tensor([0.318, 0.726]),
|
|
29
|
+
"labels": IntTensor([3, 2]),
|
|
30
|
+
}, # coco image id 73
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
"boxes": Tensor([
|
|
35
|
+
[87.87, 276.25, 384.29, 379.43],
|
|
36
|
+
[0.00, 3.66, 142.15, 316.06],
|
|
37
|
+
[296.55, 93.96, 314.97, 152.79],
|
|
38
|
+
[328.94, 97.05, 342.49, 122.98],
|
|
39
|
+
[356.62, 95.47, 372.33, 147.55],
|
|
40
|
+
[464.08, 105.09, 495.74, 146.99],
|
|
41
|
+
[276.11, 103.84, 291.44, 150.72],
|
|
42
|
+
]),
|
|
43
|
+
"scores": Tensor([0.546, 0.3, 0.407,
|
|
44
|
+
0.611, 0.335, 0.805, 0.953]),
|
|
45
|
+
"labels": IntTensor([4, 1, 0, 0, 0, 0, 0]),
|
|
46
|
+
}, # coco image id 74
|
|
47
|
+
{
|
|
48
|
+
"boxes": Tensor([
|
|
49
|
+
[72.92, 45.96, 91.23, 80.57],
|
|
50
|
+
[45.17, 45.34, 66.28, 79.83],
|
|
51
|
+
[82.28, 47.04, 99.66, 78.50],
|
|
52
|
+
[59.96, 46.17, 80.35, 80.48],
|
|
53
|
+
[75.29, 23.01, 91.85, 50.85],
|
|
54
|
+
[71.14, 1.10, 96.96, 28.33],
|
|
55
|
+
[61.34, 55.23, 77.14, 79.57],
|
|
56
|
+
[41.17, 45.78, 60.99, 78.48],
|
|
57
|
+
[56.18, 44.80, 64.42, 56.25],
|
|
58
|
+
]),
|
|
59
|
+
"scores": Tensor([
|
|
60
|
+
0.532,
|
|
61
|
+
0.204,
|
|
62
|
+
0.782,
|
|
63
|
+
0.202,
|
|
64
|
+
0.883,
|
|
65
|
+
0.271,
|
|
66
|
+
0.561,
|
|
67
|
+
0.204 + 1e-8, # There are some problems with sorting at the moment. When sorting score with the same values, they give different indexes. # noqa: E501
|
|
68
|
+
0.349
|
|
69
|
+
]),
|
|
70
|
+
"labels": IntTensor([
|
|
71
|
+
49,
|
|
72
|
+
49,
|
|
73
|
+
49,
|
|
74
|
+
49,
|
|
75
|
+
49,
|
|
76
|
+
49,
|
|
77
|
+
49,
|
|
78
|
+
49,
|
|
79
|
+
49
|
|
80
|
+
]),
|
|
81
|
+
}, # coco image id 987 category_id 49
|
|
82
|
+
],
|
|
83
|
+
],
|
|
84
|
+
"target": [
|
|
85
|
+
[
|
|
86
|
+
{
|
|
87
|
+
"boxes": Tensor([[214.1500, 41.2900, 562.4100, 285.0700]]),
|
|
88
|
+
"labels": IntTensor([4]),
|
|
89
|
+
}, # coco image id 42
|
|
90
|
+
{
|
|
91
|
+
"boxes": Tensor([
|
|
92
|
+
[13.00, 22.75, 548.98, 632.42],
|
|
93
|
+
[1.66, 3.32, 270.26, 275.23],
|
|
94
|
+
]),
|
|
95
|
+
"labels": IntTensor([2, 2]),
|
|
96
|
+
}, # coco image id 73
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
"boxes": Tensor([
|
|
101
|
+
[61.87, 276.25, 358.29, 379.43],
|
|
102
|
+
[2.75, 3.66, 162.15, 316.06],
|
|
103
|
+
[295.55, 93.96, 313.97, 152.79],
|
|
104
|
+
[326.94, 97.05, 340.49, 122.98],
|
|
105
|
+
[356.62, 95.47, 372.33, 147.55],
|
|
106
|
+
[462.08, 105.09, 493.74, 146.99],
|
|
107
|
+
[277.11, 103.84, 292.44, 150.72],
|
|
108
|
+
]),
|
|
109
|
+
"labels": IntTensor([4, 1, 0, 0, 0, 0, 0]),
|
|
110
|
+
}, # coco image id 74
|
|
111
|
+
{
|
|
112
|
+
"boxes": Tensor([
|
|
113
|
+
[72.92, 45.96, 91.23, 80.57],
|
|
114
|
+
[50.17, 45.34, 71.28, 79.83],
|
|
115
|
+
[81.28, 47.04, 98.66, 78.50],
|
|
116
|
+
[63.96, 46.17, 84.35, 80.48],
|
|
117
|
+
[75.29, 23.01, 91.85, 50.85],
|
|
118
|
+
[56.39, 21.65, 75.66, 45.54],
|
|
119
|
+
[73.14, 1.10, 98.96, 28.33],
|
|
120
|
+
[62.34, 55.23, 78.14, 79.57],
|
|
121
|
+
[44.17, 45.78, 63.99, 78.48],
|
|
122
|
+
[58.18, 44.80, 66.42, 56.25],
|
|
123
|
+
]),
|
|
124
|
+
"labels": IntTensor([
|
|
125
|
+
49,
|
|
126
|
+
49,
|
|
127
|
+
49,
|
|
128
|
+
49,
|
|
129
|
+
49,
|
|
130
|
+
49,
|
|
131
|
+
49,
|
|
132
|
+
49,
|
|
133
|
+
49,
|
|
134
|
+
49
|
|
135
|
+
]),
|
|
136
|
+
}, # coco image id 987 category_id 49
|
|
137
|
+
],
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
# fmt: on
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class TestTorchmetricsLib(TestCase):
|
|
144
|
+
def setUp(self):
|
|
145
|
+
# Preds should be a list of elements, where each element is a dict
|
|
146
|
+
# containing 3 keys: boxes, scores, labels
|
|
147
|
+
mask_pred = [
|
|
148
|
+
[0, 0, 0, 0, 0],
|
|
149
|
+
[0, 0, 1, 1, 0],
|
|
150
|
+
[0, 0, 1, 1, 0],
|
|
151
|
+
[0, 0, 0, 0, 0],
|
|
152
|
+
[0, 0, 0, 0, 0],
|
|
153
|
+
]
|
|
154
|
+
self.preds = [
|
|
155
|
+
{
|
|
156
|
+
# The boxes keyword should contain an [N,4] tensor,
|
|
157
|
+
# where N is the number of detected \
|
|
158
|
+
# boxes with boxes of the format
|
|
159
|
+
# [xmin, ymin, xmax, ymax] in absolute \
|
|
160
|
+
# image coordinates
|
|
161
|
+
"boxes": Tensor([[258.0, 41.0, 606.0, 285.0]]),
|
|
162
|
+
# The scores keyword should contain an [N,] \
|
|
163
|
+
# tensor where
|
|
164
|
+
# each element is confidence score between 0 and 1
|
|
165
|
+
"scores": Tensor([0.536]),
|
|
166
|
+
# The labels keyword should contain an [N,] tensor
|
|
167
|
+
# with integers of the predicted classes
|
|
168
|
+
"labels": IntTensor([0]),
|
|
169
|
+
# The masks keyword should contain an [N,H,W] tensor,
|
|
170
|
+
# where H and W are the image height and width, \
|
|
171
|
+
# respectively,
|
|
172
|
+
# with boolean masks. This is only required \
|
|
173
|
+
# when iou_type is `segm`.
|
|
174
|
+
"masks": BoolTensor([mask_pred]),
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
|
|
178
|
+
# Target should be a list of elements, where each element is a dict
|
|
179
|
+
# containing 2 keys: boxes and labels \
|
|
180
|
+
# (and masks, if iou_type is `segm`).
|
|
181
|
+
# Each keyword should be formatted similar to the preds argument.
|
|
182
|
+
# The number of elements in preds and target need to match
|
|
183
|
+
mask_tgt = [
|
|
184
|
+
[0, 0, 0, 0, 0],
|
|
185
|
+
[0, 0, 1, 0, 0],
|
|
186
|
+
[0, 0, 1, 1, 0],
|
|
187
|
+
[0, 0, 1, 0, 0],
|
|
188
|
+
[0, 0, 0, 0, 0],
|
|
189
|
+
]
|
|
190
|
+
self.target = [
|
|
191
|
+
{
|
|
192
|
+
"boxes": Tensor([[214.0, 41.0, 562.0, 285.0]]),
|
|
193
|
+
"labels": IntTensor([0]),
|
|
194
|
+
"masks": BoolTensor([mask_tgt]),
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
self.valid_result = {
|
|
199
|
+
"map": torch.tensor(0.6000),
|
|
200
|
+
"map_50": torch.tensor(1.0),
|
|
201
|
+
"map_75": torch.tensor(1.0),
|
|
202
|
+
"map_small": torch.tensor(-1.0),
|
|
203
|
+
"map_medium": torch.tensor(-1.0),
|
|
204
|
+
"map_large": torch.tensor(0.6000),
|
|
205
|
+
"mar_1": torch.tensor(0.6000),
|
|
206
|
+
"mar_10": torch.tensor(0.6000),
|
|
207
|
+
"mar_100": torch.tensor(0.6000),
|
|
208
|
+
"mar_small": torch.tensor(-1.0),
|
|
209
|
+
"mar_medium": torch.tensor(-1.0),
|
|
210
|
+
"mar_large": torch.tensor(0.6000),
|
|
211
|
+
"map_per_class": torch.tensor(-1.0),
|
|
212
|
+
"mar_100_per_class": torch.tensor(-1.0),
|
|
213
|
+
"classes": torch.tensor(0, dtype=torch.int32),
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
def test_evaluate(self):
|
|
217
|
+
# Initialize metric
|
|
218
|
+
metric = MeanAveragePrecision(
|
|
219
|
+
iou_type="bbox", backend="faster_coco_eval"
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
# Update metric with predictions and respective ground truth
|
|
223
|
+
metric.update(self.preds, self.target)
|
|
224
|
+
|
|
225
|
+
self.assertEqual(metric.backend, "faster_coco_eval")
|
|
226
|
+
|
|
227
|
+
# Compute the results
|
|
228
|
+
result = metric.compute()
|
|
229
|
+
|
|
230
|
+
self.assertDictEqual(result, self.valid_result)
|
|
231
|
+
|
|
232
|
+
def test_segm_iou_empty_gt_mask(self):
|
|
233
|
+
"""Test empty ground truths."""
|
|
234
|
+
backend = "faster_coco_eval"
|
|
235
|
+
metric = MeanAveragePrecision(iou_type="segm", backend=backend)
|
|
236
|
+
metric.update(
|
|
237
|
+
[
|
|
238
|
+
{
|
|
239
|
+
"masks": torch.randint(0, 1, (1, 10, 10)).bool(),
|
|
240
|
+
"scores": Tensor([0.5]),
|
|
241
|
+
"labels": IntTensor([4]),
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
[{"masks": Tensor([]), "labels": IntTensor([])}],
|
|
245
|
+
)
|
|
246
|
+
metric.compute()
|
|
247
|
+
|
|
248
|
+
@parameterized.expand([False, True])
|
|
249
|
+
def test_average_argument(self, class_metrics):
|
|
250
|
+
"""Test that average argument works.
|
|
251
|
+
|
|
252
|
+
Calculating macro on inputs that only have one label should be
|
|
253
|
+
the same as micro. Calculating class metrics should be the same
|
|
254
|
+
regardless of average argument.
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
backend = "pycocotools"
|
|
258
|
+
backend = "faster_coco_eval"
|
|
259
|
+
|
|
260
|
+
if class_metrics:
|
|
261
|
+
_preds = _inputs["preds"]
|
|
262
|
+
_target = _inputs["target"]
|
|
263
|
+
else:
|
|
264
|
+
_preds = apply_to_collection(
|
|
265
|
+
deepcopy(_inputs["preds"]),
|
|
266
|
+
IntTensor,
|
|
267
|
+
lambda x: torch.ones_like(x),
|
|
268
|
+
)
|
|
269
|
+
_target = apply_to_collection(
|
|
270
|
+
deepcopy(_inputs["target"]),
|
|
271
|
+
IntTensor,
|
|
272
|
+
lambda x: torch.ones_like(x),
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
metric_macro = MeanAveragePrecision(
|
|
276
|
+
average="macro", class_metrics=class_metrics, backend=backend
|
|
277
|
+
)
|
|
278
|
+
metric_macro.update(_preds[0], _target[0])
|
|
279
|
+
metric_macro.update(_preds[1], _target[1])
|
|
280
|
+
result_macro = metric_macro.compute()
|
|
281
|
+
|
|
282
|
+
metric_micro = MeanAveragePrecision(
|
|
283
|
+
average="micro", class_metrics=class_metrics, backend=backend
|
|
284
|
+
)
|
|
285
|
+
metric_micro.update(_inputs["preds"][0], _inputs["target"][0])
|
|
286
|
+
metric_micro.update(_inputs["preds"][1], _inputs["target"][1])
|
|
287
|
+
result_micro = metric_micro.compute()
|
|
288
|
+
|
|
289
|
+
if class_metrics:
|
|
290
|
+
assert torch.allclose(
|
|
291
|
+
result_macro["map_per_class"], result_micro["map_per_class"]
|
|
292
|
+
)
|
|
293
|
+
assert torch.allclose(
|
|
294
|
+
result_macro["mar_100_per_class"],
|
|
295
|
+
result_micro["mar_100_per_class"],
|
|
296
|
+
)
|
|
297
|
+
else:
|
|
298
|
+
for key in result_macro:
|
|
299
|
+
if key == "classes":
|
|
300
|
+
continue
|
|
301
|
+
assert torch.allclose(result_macro[key], result_micro[key])
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
if __name__ == "__main__":
|
|
305
|
+
unittest.main()
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from unittest import TestCase
|
|
3
|
-
|
|
4
|
-
try:
|
|
5
|
-
import torch
|
|
6
|
-
from torch import BoolTensor, IntTensor, Tensor
|
|
7
|
-
from torchmetrics.detection.mean_ap import MeanAveragePrecision
|
|
8
|
-
except ImportError:
|
|
9
|
-
raise unittest.SkipTest("Skipping all tests for torchmetrics.")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class TestTorchmetricsLib(TestCase):
|
|
13
|
-
def setUp(self):
|
|
14
|
-
# Preds should be a list of elements, where each element is a dict
|
|
15
|
-
# containing 3 keys: boxes, scores, labels
|
|
16
|
-
mask_pred = [
|
|
17
|
-
[0, 0, 0, 0, 0],
|
|
18
|
-
[0, 0, 1, 1, 0],
|
|
19
|
-
[0, 0, 1, 1, 0],
|
|
20
|
-
[0, 0, 0, 0, 0],
|
|
21
|
-
[0, 0, 0, 0, 0],
|
|
22
|
-
]
|
|
23
|
-
self.preds = [
|
|
24
|
-
{
|
|
25
|
-
# The boxes keyword should contain an [N,4] tensor,
|
|
26
|
-
# where N is the number of detected \
|
|
27
|
-
# boxes with boxes of the format
|
|
28
|
-
# [xmin, ymin, xmax, ymax] in absolute \
|
|
29
|
-
# image coordinates
|
|
30
|
-
"boxes": Tensor([[258.0, 41.0, 606.0, 285.0]]),
|
|
31
|
-
# The scores keyword should contain an [N,] \
|
|
32
|
-
# tensor where
|
|
33
|
-
# each element is confidence score between 0 and 1
|
|
34
|
-
"scores": Tensor([0.536]),
|
|
35
|
-
# The labels keyword should contain an [N,] tensor
|
|
36
|
-
# with integers of the predicted classes
|
|
37
|
-
"labels": IntTensor([0]),
|
|
38
|
-
# The masks keyword should contain an [N,H,W] tensor,
|
|
39
|
-
# where H and W are the image height and width, \
|
|
40
|
-
# respectively,
|
|
41
|
-
# with boolean masks. This is only required \
|
|
42
|
-
# when iou_type is `segm`.
|
|
43
|
-
"masks": BoolTensor([mask_pred]),
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
# Target should be a list of elements, where each element is a dict
|
|
48
|
-
# containing 2 keys: boxes and labels \
|
|
49
|
-
# (and masks, if iou_type is `segm`).
|
|
50
|
-
# Each keyword should be formatted similar to the preds argument.
|
|
51
|
-
# The number of elements in preds and target need to match
|
|
52
|
-
mask_tgt = [
|
|
53
|
-
[0, 0, 0, 0, 0],
|
|
54
|
-
[0, 0, 1, 0, 0],
|
|
55
|
-
[0, 0, 1, 1, 0],
|
|
56
|
-
[0, 0, 1, 0, 0],
|
|
57
|
-
[0, 0, 0, 0, 0],
|
|
58
|
-
]
|
|
59
|
-
self.target = [
|
|
60
|
-
{
|
|
61
|
-
"boxes": Tensor([[214.0, 41.0, 562.0, 285.0]]),
|
|
62
|
-
"labels": IntTensor([0]),
|
|
63
|
-
"masks": BoolTensor([mask_tgt]),
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
self.valid_result = {
|
|
68
|
-
"map": torch.tensor(0.6000),
|
|
69
|
-
"map_50": torch.tensor(1.0),
|
|
70
|
-
"map_75": torch.tensor(1.0),
|
|
71
|
-
"map_small": torch.tensor(-1.0),
|
|
72
|
-
"map_medium": torch.tensor(-1.0),
|
|
73
|
-
"map_large": torch.tensor(0.6000),
|
|
74
|
-
"mar_1": torch.tensor(0.6000),
|
|
75
|
-
"mar_10": torch.tensor(0.6000),
|
|
76
|
-
"mar_100": torch.tensor(0.6000),
|
|
77
|
-
"mar_small": torch.tensor(-1.0),
|
|
78
|
-
"mar_medium": torch.tensor(-1.0),
|
|
79
|
-
"mar_large": torch.tensor(0.6000),
|
|
80
|
-
"map_per_class": torch.tensor(-1.0),
|
|
81
|
-
"mar_100_per_class": torch.tensor(-1.0),
|
|
82
|
-
"classes": torch.tensor(0, dtype=torch.int32),
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
def test_evaluate(self):
|
|
86
|
-
# Initialize metric
|
|
87
|
-
metric = MeanAveragePrecision(
|
|
88
|
-
iou_type="bbox", backend="faster_coco_eval"
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
# Update metric with predictions and respective ground truth
|
|
92
|
-
metric.update(self.preds, self.target)
|
|
93
|
-
|
|
94
|
-
self.assertEqual(metric.backend, "faster_coco_eval")
|
|
95
|
-
|
|
96
|
-
# Compute the results
|
|
97
|
-
result = metric.compute()
|
|
98
|
-
|
|
99
|
-
self.assertDictEqual(result, self.valid_result)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if __name__ == "__main__":
|
|
103
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/csrc/faster_eval_api/coco_eval/cocoeval.cpp
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{faster_coco_eval-1.6.1 → faster_coco_eval-1.6.3}/faster_coco_eval.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|