-
Notifications
You must be signed in to change notification settings - Fork 443
/
test_detection.py
345 lines (300 loc) · 15.6 KB
/
test_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
"""Tests for Class-Incremental Learning for object detection with OTX CLI"""
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import copy
import os
import pytest
import torch
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
get_template_dir,
nncf_eval_openvino_testing,
nncf_eval_testing,
nncf_export_testing,
nncf_optimize_testing,
nncf_validate_fq_testing,
otx_demo_deployment_testing,
otx_demo_openvino_testing,
otx_demo_testing,
otx_deploy_openvino_testing,
otx_eval_deployment_testing,
otx_eval_openvino_testing,
otx_eval_testing,
otx_explain_all_classes_openvino_testing,
otx_explain_openvino_testing,
otx_explain_process_saliency_maps_openvino_testing,
otx_explain_testing,
otx_explain_testing_all_classes,
otx_explain_testing_process_saliency_maps,
otx_export_testing,
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
pot_eval_testing,
pot_optimize_testing,
pot_validate_fq_testing,
)
# Pre-train w/ 'person' class
args0 = {
"--train-data-roots": "tests/assets/car_tree_bug",
"--val-data-roots": "tests/assets/car_tree_bug",
"--test-data-roots": "tests/assets/car_tree_bug",
"--input": "tests/assets/car_tree_bug/images/train",
"train_params": ["params", "--learning_parameters.num_iters", "20", "--learning_parameters.batch_size", "4"],
}
# Class-Incremental learning w/ 'vehicle', 'person', 'non-vehicle' classes
args = {
"--train-data-roots": "tests/assets/car_tree_bug",
"--val-data-roots": "tests/assets/car_tree_bug",
"--test-data-roots": "tests/assets/car_tree_bug",
"--input": "tests/assets/car_tree_bug/images/train",
"train_params": ["params", "--learning_parameters.num_iters", "5", "--learning_parameters.batch_size", "4"],
}
args_semisl = {
"--train-data-roots": "tests/assets/car_tree_bug",
"--val-data-roots": "tests/assets/car_tree_bug",
"--test-data-roots": "tests/assets/car_tree_bug",
"--unlabeled-data-roots": "tests/assets/car_tree_bug",
"--input": "tests/assets/car_tree_bug/images/train",
"train_params": [
"params",
"--learning_parameters.num_iters",
"2",
"--learning_parameters.batch_size",
"4",
"--algo_backend.train_type",
"Semisupervised",
],
}
# Training params for resume, num_iters*2
resume_params = [
"params",
"--learning_parameters.num_iters",
"8",
"--learning_parameters.batch_size",
"4",
]
otx_dir = os.getcwd()
MULTI_GPU_UNAVAILABLE = torch.cuda.device_count() <= 1
TT_STABILITY_TESTS = os.environ.get("TT_STABILITY_TESTS", False)
if TT_STABILITY_TESTS:
default_template = parse_model_template(
os.path.join("otx/algorithms/detection/configs", "detection", "mobilenetv2_atss", "template.yaml")
)
templates = [default_template] * 100
templates_ids = [template.model_template_id + f"-{i+1}" for i, template in enumerate(templates)]
else:
templates = Registry("otx/algorithms/detection").filter(task_type="DETECTION").templates
templates_ids = [template.model_template_id for template in templates]
class TestToolsMPADetection:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_train_testing(template, tmp_dir_path, otx_dir, args0)
template_work_dir = get_template_dir(template, tmp_dir_path)
args1 = copy.deepcopy(args)
args1["--load-weights"] = f"{template_work_dir}/trained_{template.model_template_id}/models/weights.pth"
otx_train_testing(template, tmp_dir_path, otx_dir, args1)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_resume(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_resume"
otx_resume_testing(template, tmp_dir_path, otx_dir, args)
template_work_dir = get_template_dir(template, tmp_dir_path)
args1 = copy.deepcopy(args)
args1["train_params"] = resume_params
args1[
"--resume-from"
] = f"{template_work_dir}/trained_for_resume_{template.model_template_id}/models/weights.pth"
otx_resume_testing(template, tmp_dir_path, otx_dir, args1)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("dump_features", [True, False])
def test_otx_export(self, template, tmp_dir_path, dump_features):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, dump_features)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_export_fp16(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, half_precision=True)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("half_precision", [True, False])
def test_otx_eval_openvino(self, template, tmp_dir_path, half_precision):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_openvino_testing(template, tmp_dir_path, otx_dir, args, threshold=0.05, half_precision=half_precision)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_testing(template, tmp_dir_path, otx_dir, args, trained=True)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain_all_classes(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_testing_all_classes(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain_process_saliency_maps(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_testing_process_saliency_maps(template, tmp_dir_path, otx_dir, args, trained=True)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_openvino_testing(template, tmp_dir_path, otx_dir, args, trained=True)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain_all_classes_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_all_classes_openvino_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_explain_process_saliency_maps_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_explain_process_saliency_maps_openvino_testing(template, tmp_dir_path, otx_dir, args, trained=True)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_demo(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_demo_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_openvino_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_deploy_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_deploy_openvino_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_eval_deployment(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_deployment_testing(template, tmp_dir_path, otx_dir, args, threshold=0.0)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_demo_deployment(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_deployment_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_hpo(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_hpo"
otx_hpo_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_nncf_optimize(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")
nncf_optimize_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_nncf_export(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")
nncf_export_testing(template, tmp_dir_path)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_nncf_validate_fq(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")
nncf_validate_fq_testing(template, tmp_dir_path, otx_dir, "detection", type(self).__name__)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_nncf_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")
nncf_eval_testing(template, tmp_dir_path, otx_dir, args, threshold=0.01)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_nncf_eval_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")
nncf_eval_openvino_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_pot_optimize(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
pot_optimize_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_pot_validate_fq(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
pot_validate_fq_testing(template, tmp_dir_path, otx_dir, "detection", type(self).__name__)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_pot_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
pot_eval_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_multi_gpu_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_multi_gpu"
args1 = copy.deepcopy(args)
args1["--gpus"] = "0,1"
otx_train_testing(template, tmp_dir_path, otx_dir, args1)
class TestToolsMPASemiSLDetection:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_semisl"
otx_train_testing(template, tmp_dir_path, otx_dir, args_semisl)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_semisl"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)
@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_multi_gpu_train_semisl(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_multi_gpu_semisl"
args_semisl_multigpu = copy.deepcopy(args_semisl)
args_semisl_multigpu["--gpus"] = "0,1"
otx_train_testing(template, tmp_dir_path, otx_dir, args_semisl_multigpu)