Skip to content

Commit 9a78128

Browse files
authored
Merge pull request #898 from openvinotoolkit/pf/adding_anomaly_training_tests
[Anomaly] Added real-life training tests
2 parents 4b58c23 + 52feb1c commit 9a78128

File tree

5 files changed

+521
-0
lines changed

5 files changed

+521
-0
lines changed

external/anomaly/ote_anomalib/nncf_task.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from ote_sdk.entities.datasets import DatasetEntity
3737
from ote_sdk.entities.model import (
3838
ModelEntity,
39+
ModelFormat,
3940
ModelOptimizationType,
4041
ModelPrecision,
4142
OptimizationMethod,
@@ -183,6 +184,8 @@ def optimize(
183184
self.trainer = Trainer(**self.config.trainer, logger=False, callbacks=callbacks)
184185
self.trainer.fit(model=self.model, datamodule=datamodule)
185186
self.compression_ctrl = nncf_callback.nncf_ctrl
187+
output_model.model_format = ModelFormat.BASE_FRAMEWORK
188+
output_model.optimization_type = ModelOptimizationType.NNCF
186189
self.save_model(output_model)
187190

188191
logger.info("Training completed.")

external/anomaly/ote_tests_pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
python_files = test_ote_api.py test_ote_inference.py test_ote_training.py

external/anomaly/tests/conftest.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
15+
import pytest
16+
from ote_sdk.test_suite.pytest_insertions import (
17+
get_pytest_plugins_from_ote,
18+
ote_conftest_insertion,
19+
ote_pytest_generate_tests_insertion,
20+
ote_pytest_addoption_insertion,
21+
)
22+
from ote_sdk.test_suite.training_tests_common import REALLIFE_USECASE_CONSTANT
23+
24+
pytest_plugins = get_pytest_plugins_from_ote()
25+
26+
ote_conftest_insertion(default_repository_name="ote/training_extensions/external/anomaly")
27+
28+
29+
@pytest.fixture
30+
def ote_test_domain_fx():
31+
return "custom-anomaly-classification"
32+
33+
34+
@pytest.fixture
35+
def ote_test_scenario_fx(current_test_parameters_fx):
36+
assert isinstance(current_test_parameters_fx, dict)
37+
if current_test_parameters_fx.get("usecase") == REALLIFE_USECASE_CONSTANT:
38+
return "performance"
39+
else:
40+
return "integration"
41+
42+
43+
@pytest.fixture(scope="session")
44+
def ote_templates_root_dir_fx():
45+
import os.path as osp
46+
import logging
47+
48+
logger = logging.getLogger(__name__)
49+
root = osp.dirname(osp.dirname(osp.realpath(__file__)))
50+
root = f"{root}/anomaly_classification/"
51+
logger.debug(f"overloaded ote_templates_root_dir_fx: return {root}")
52+
return root
53+
54+
55+
@pytest.fixture(scope="session")
56+
def ote_reference_root_dir_fx():
57+
import os.path as osp
58+
import logging
59+
60+
logger = logging.getLogger(__name__)
61+
root = osp.dirname(osp.dirname(osp.realpath(__file__)))
62+
root = f"{root}/tests/reference/"
63+
logger.debug(f"overloaded ote_reference_root_dir_fx: return {root}")
64+
return root
65+
66+
67+
# pytest magic
68+
def pytest_generate_tests(metafunc):
69+
ote_pytest_generate_tests_insertion(metafunc)
70+
71+
72+
def pytest_addoption(parser):
73+
ote_pytest_addoption_insertion(parser)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
? "ACTION-training_evaluation,model-ote_anomaly_classification_padim,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
2+
: "metrics.accuracy.f-measure":
3+
"target_value": 0.73
4+
"max_diff_if_less_threshold": 0.01
5+
"max_diff_if_greater_threshold": 0.04
6+
? "ACTION-export_evaluation,model-ote_anomaly_classification_padim,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
7+
: "metrics.accuracy.f-measure":
8+
"base": "training_evaluation.metrics.accuracy.f-measure"
9+
"max_diff": 0.01
10+
? "ACTION-pot_evaluation,model-ote_anomaly_classification_padim,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
11+
: "metrics.accuracy.f-measure":
12+
"base": "export_evaluation.metrics.accuracy.f-measure"
13+
"max_diff": 0.03
14+
? "ACTION-nncf_evaluation,model-ote_anomaly_classification_padim,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
15+
: "metrics.accuracy.f-measure":
16+
"base": "training_evaluation.metrics.accuracy.f-measure"
17+
"max_diff_if_less_threshold": 0.01
18+
? "ACTION-nncf_export_evaluation,model-ote_anomaly_classification_padim,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
19+
: "metrics.accuracy.f-measure":
20+
"base": "nncf_evaluation.metrics.accuracy.f-measure"
21+
"max_diff": 0.01
22+
23+
? "ACTION-training_evaluation,model-ote_anomaly_classification_stfpm,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
24+
: "metrics.accuracy.f-measure":
25+
"target_value": 0.74
26+
"max_diff_if_less_threshold": 0.01
27+
"max_diff_if_greater_threshold": 0.04
28+
? "ACTION-export_evaluation,model-ote_anomaly_classification_stfpm,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
29+
: "metrics.accuracy.f-measure":
30+
"base": "training_evaluation.metrics.accuracy.f-measure"
31+
"max_diff": 0.01
32+
? "ACTION-pot_evaluation,model-ote_anomaly_classification_stfpm,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
33+
: "metrics.accuracy.f-measure":
34+
"base": "export_evaluation.metrics.accuracy.f-measure"
35+
"max_diff": 0.03
36+
? "ACTION-nncf_evaluation,model-ote_anomaly_classification_stfpm,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
37+
: "metrics.accuracy.f-measure":
38+
"base": "training_evaluation.metrics.accuracy.f-measure"
39+
"max_diff_if_less_threshold": 0.01
40+
? "ACTION-nncf_export_evaluation,model-ote_anomaly_classification_stfpm,dataset-mvtec,patience-CONFIG,batch-CONFIG,usecase-reallife"
41+
: "metrics.accuracy.f-measure":
42+
"base": "nncf_evaluation.metrics.accuracy.f-measure"
43+
"max_diff": 0.01

0 commit comments

Comments
 (0)