Skip to content

Commit 32d851b

Browse files
author
Evgeny Tsykunov
committed
reply to comments
1 parent 76a93f5 commit 32d851b

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

otx/algorithms/detection/adapters/mmdet/hooks/det_class_probability_map_hook.py

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# pylint: disable=too-many-locals
2525

2626

27-
2827
class DetClassProbabilityMapHook(BaseRecordingForwardHook):
2928
"""Saliency map hook for object detection models."""
3029

otx/cli/tools/explain.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ def get_args():
7777
"--explain-all-classes",
7878
action="store_true",
7979
help="Provides explanations for all classes. Otherwise, explains only predicted classes."
80-
"This feature supported by algorithms that can generate explanations per class.",
80+
"This feature is supported by algorithms that can generate explanations per each class.",
8181
)
8282
parser.add_argument(
8383
"--overlay-weight",
8484
type=float,
8585
default=0.5,
86-
help="Weight of the saliency map when overlaying the input image with saliency map",
86+
help="Weight of the saliency map when overlaying the input image with saliency map.",
8787
)
8888
add_hyper_parameters_sub_parser(parser, hyper_parameters, modes=("INFERENCE",))
8989
override_param = [f"params.{param[2:].split('=')[0]}" for param in params if param.startswith("--")]

tests/e2e/cli/detection/test_detection.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
otx_eval_deployment_testing,
2626
otx_eval_openvino_testing,
2727
otx_eval_testing,
28+
otx_explain_all_classes_openvino_testing,
2829
otx_explain_openvino_testing,
30+
otx_explain_process_saliency_maps_openvino_testing,
2931
otx_explain_testing,
32+
otx_explain_testing_all_classes,
33+
otx_explain_testing_process_saliency_maps,
3034
otx_export_testing,
3135
otx_export_testing_w_features,
3236
otx_hpo_testing,
@@ -43,7 +47,7 @@
4347
"--val-data-roots": "tests/assets/car_tree_bug",
4448
"--test-data-roots": "tests/assets/car_tree_bug",
4549
"--input": "tests/assets/car_tree_bug/images/train",
46-
"train_params": ["params", "--learning_parameters.num_iters", "5", "--learning_parameters.batch_size", "4"],
50+
"train_params": ["params", "--learning_parameters.num_iters", "10", "--learning_parameters.batch_size", "4"],
4751
}
4852

4953
# Class-Incremental learning w/ 'vehicle', 'person', 'non-vehicle' classes
@@ -152,14 +156,42 @@ def test_otx_eval_openvino(self, template, tmp_dir_path):
152156
@pytest.mark.parametrize("template", templates, ids=templates_ids)
153157
def test_otx_explain(self, template, tmp_dir_path):
154158
tmp_dir_path = tmp_dir_path / "detection"
155-
otx_explain_testing(template, tmp_dir_path, otx_dir, args)
159+
otx_explain_testing(template, tmp_dir_path, otx_dir, args, trained=True)
160+
161+
@e2e_pytest_component
162+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
163+
@pytest.mark.parametrize("template", templates, ids=templates_ids)
164+
def test_otx_explain_all_classes(self, template, tmp_dir_path):
165+
tmp_dir_path = tmp_dir_path / "detection"
166+
otx_explain_testing_all_classes(template, tmp_dir_path, otx_dir, args)
167+
168+
@e2e_pytest_component
169+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
170+
@pytest.mark.parametrize("template", templates, ids=templates_ids)
171+
def test_otx_explain_process_saliency_maps(self, template, tmp_dir_path):
172+
tmp_dir_path = tmp_dir_path / "detection"
173+
otx_explain_testing_process_saliency_maps(template, tmp_dir_path, otx_dir, args, trained=True)
156174

157175
@e2e_pytest_component
158176
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
159177
@pytest.mark.parametrize("template", templates, ids=templates_ids)
160178
def test_otx_explain_openvino(self, template, tmp_dir_path):
161179
tmp_dir_path = tmp_dir_path / "detection"
162-
otx_explain_openvino_testing(template, tmp_dir_path, otx_dir, args)
180+
otx_explain_openvino_testing(template, tmp_dir_path, otx_dir, args, trained=True)
181+
182+
@e2e_pytest_component
183+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
184+
@pytest.mark.parametrize("template", templates, ids=templates_ids)
185+
def test_otx_explain_all_classes_openvino(self, template, tmp_dir_path):
186+
tmp_dir_path = tmp_dir_path / "detection"
187+
otx_explain_all_classes_openvino_testing(template, tmp_dir_path, otx_dir, args)
188+
189+
@e2e_pytest_component
190+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
191+
@pytest.mark.parametrize("template", templates, ids=templates_ids)
192+
def test_otx_explain_process_saliency_maps_openvino(self, template, tmp_dir_path):
193+
tmp_dir_path = tmp_dir_path / "detection"
194+
otx_explain_process_saliency_maps_openvino_testing(template, tmp_dir_path, otx_dir, args, trained=True)
163195

164196
@e2e_pytest_component
165197
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")

tests/integration/cli/detection/test_detection.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
"train_params": ["params", "--learning_parameters.num_iters", "1", "--learning_parameters.batch_size", "4"],
4040
}
4141

42-
num_iters_per_model = {
43-
"Custom_Object_Detection_YOLOX": "10",
44-
"Custom_Object_Detection_Gen3_ATSS": "30",
45-
"Custom_Object_Detection_Gen3_SSD": "10",
46-
}
47-
4842
args_semisl = {
4943
"--train-data-roots": "tests/assets/car_tree_bug",
5044
"--val-data-roots": "tests/assets/car_tree_bug",
@@ -89,9 +83,7 @@ class TestDetectionCLI:
8983
@pytest.mark.parametrize("template", templates, ids=templates_ids)
9084
def test_otx_train(self, template, tmp_dir_path):
9185
tmp_dir_path = tmp_dir_path / "detection"
92-
args1 = copy.deepcopy(args)
93-
args1["train_params"][2] = num_iters_per_model[template.model_template_id]
94-
otx_train_testing(template, tmp_dir_path, otx_dir, args1)
86+
otx_train_testing(template, tmp_dir_path, otx_dir, args)
9587

9688
@e2e_pytest_component
9789
@pytest.mark.parametrize("template", default_templates, ids=default_templates_ids)

tests/test_suite/run_test_command.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ def otx_export_testing_w_features(template, root):
241241
with open(path_to_xml, encoding="utf-8") as stream:
242242
xml_model = stream.read()
243243
assert "feature_vector" in xml_model
244-
assert "saliency_map" in xml_model
245244

246245

247246
def otx_eval_testing(template, root, otx_dir, args):
@@ -685,7 +684,7 @@ def otx_explain_testing(template, root, otx_dir, args, trained=False):
685684
assert os.path.exists(output_dir)
686685
if trained:
687686
assert len(os.listdir(output_dir)) > 0
688-
assert all([fname.split(".")[-1] == "tiff" for fname in os.listdir(output_dir)])
687+
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
689688

690689

691690
def otx_explain_testing_all_classes(template, root, otx_dir, args):
@@ -729,7 +728,7 @@ def otx_explain_testing_all_classes(template, root, otx_dir, args):
729728
assert len(os.listdir(output_dir)) == len(os.listdir(output_dir_explain_only_predicted_classes))
730729
else:
731730
assert len(os.listdir(output_dir)) >= len(os.listdir(output_dir_explain_only_predicted_classes))
732-
assert all([fname.split(".")[-1] == "tiff" for fname in os.listdir(output_dir)])
731+
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
733732

734733

735734
def otx_explain_testing_process_saliency_maps(template, root, otx_dir, args, trained=False):
@@ -768,7 +767,7 @@ def otx_explain_testing_process_saliency_maps(template, root, otx_dir, args, tra
768767
assert os.path.exists(output_dir)
769768
if trained:
770769
assert len(os.listdir(output_dir)) > 0
771-
assert all([fname.split(".")[-1] == "png" for fname in os.listdir(output_dir)])
770+
assert all([os.path.splitext(fname)[1] == ".png" for fname in os.listdir(output_dir)])
772771

773772

774773
def otx_explain_openvino_testing(template, root, otx_dir, args, trained=False):
@@ -807,7 +806,7 @@ def otx_explain_openvino_testing(template, root, otx_dir, args, trained=False):
807806
assert os.path.exists(output_dir)
808807
if trained:
809808
assert len(os.listdir(output_dir)) > 0
810-
assert all([fname.split(".")[-1] == "tiff" for fname in os.listdir(output_dir)])
809+
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
811810

812811

813812
def otx_explain_all_classes_openvino_testing(template, root, otx_dir, args):
@@ -852,7 +851,7 @@ def otx_explain_all_classes_openvino_testing(template, root, otx_dir, args):
852851
assert len(os.listdir(output_dir)) == len(os.listdir(output_dir_explain_only_predicted_classes))
853852
else:
854853
assert len(os.listdir(output_dir)) >= len(os.listdir(output_dir_explain_only_predicted_classes))
855-
assert all([fname.split(".")[-1] == "tiff" for fname in os.listdir(output_dir)])
854+
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
856855

857856

858857
def otx_explain_process_saliency_maps_openvino_testing(template, root, otx_dir, args, trained=False):
@@ -892,7 +891,7 @@ def otx_explain_process_saliency_maps_openvino_testing(template, root, otx_dir,
892891
assert os.path.exists(output_dir)
893892
if trained:
894893
assert len(os.listdir(output_dir)) > 0
895-
assert all([fname.split(".")[-1] == "png" for fname in os.listdir(output_dir)])
894+
assert all([os.path.splitext(fname)[1] == ".png" for fname in os.listdir(output_dir)])
896895

897896

898897
def otx_find_testing():

0 commit comments

Comments
 (0)