Skip to content

Commit 656345c

Browse files
Move accuracy tests from regression to integration (#59)
Regression tests -> integration tests
1 parent 634caed commit 656345c

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

tests/regression/test_regression.py tests/intg/test_accuracy_metrics.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Dict, List, Tuple
66

77
import cv2
8+
import numpy as np
89
import openvino as ov
910
import pytest
1011

@@ -53,35 +54,34 @@ def load_gt_bboxes(json_coco_path: str) -> List[Dict[str, List[Tuple[int, int, i
5354
return list(result.values())
5455

5556

56-
class TestDummyRegression:
57+
class TestAccuracyMetrics:
5758
image = cv2.imread(IMAGE_PATH)
5859
gt_bboxes = load_gt_bboxes(COCO_ANN_PATH)
5960

60-
preprocess_fn = get_preprocess_fn(
61-
change_channel_order=True,
62-
input_size=(224, 224),
63-
hwc_to_chw=True,
64-
)
65-
66-
postprocess_fn = get_postprocess_fn(activation=ActivationType.SIGMOID)
67-
6861
@pytest.fixture(autouse=True)
6962
def setup(self, fxt_data_root):
7063
data_dir = fxt_data_root
7164
retrieve_otx_model(data_dir, MODEL_NAME)
7265
model_path = data_dir / "otx_models" / (MODEL_NAME + ".xml")
7366
model = ov.Core().read_model(model_path)
7467

68+
preprocess_fn = get_preprocess_fn(
69+
change_channel_order=True,
70+
input_size=(224, 224),
71+
hwc_to_chw=True,
72+
)
73+
postprocess_fn = get_postprocess_fn(activation=ActivationType.SIGMOID)
74+
7575
self.explainer = Explainer(
7676
model=model,
7777
task=Task.CLASSIFICATION,
78-
preprocess_fn=self.preprocess_fn,
78+
preprocess_fn=preprocess_fn,
7979
explain_mode=ExplainMode.WHITEBOX,
8080
)
8181

8282
self.pointing_game = PointingGame()
83-
self.auc = InsertionDeletionAUC(model, self.preprocess_fn, self.postprocess_fn)
84-
self.adcc = ADCC(model, self.preprocess_fn, self.postprocess_fn, self.explainer)
83+
self.auc = InsertionDeletionAUC(model, preprocess_fn, postprocess_fn)
84+
self.adcc = ADCC(model, preprocess_fn, postprocess_fn, self.explainer)
8585

8686
def test_explainer_image(self):
8787
explanation = self.explainer(self.image, targets=["person"], label_names=VOC_NAMES, colormap=False)
@@ -92,12 +92,12 @@ def test_explainer_image(self):
9292

9393
auc_score = self.auc.evaluate([explanation], [self.image], steps=10).values()
9494
insertion_auc_score, deletion_auc_score, delta_auc_score = auc_score
95-
assert insertion_auc_score >= 0.9
96-
assert deletion_auc_score >= 0.2
97-
assert delta_auc_score >= 0.7
95+
assert np.abs(insertion_auc_score - 0.94) <= 0.01
96+
assert np.abs(deletion_auc_score - 0.23) <= 0.01
97+
assert np.abs(delta_auc_score - 0.71) <= 0.01
9898

9999
adcc_score = self.adcc.evaluate([explanation], [self.image])["adcc"]
100-
assert adcc_score > 0.9
100+
assert np.abs(adcc_score - 0.96) <= 0.01
101101

102102
def test_explainer_image_2_classes(self):
103103
explanation = self.explainer(self.image, targets=["person", "cat"], label_names=VOC_NAMES, colormap=False)
@@ -108,12 +108,12 @@ def test_explainer_image_2_classes(self):
108108

109109
auc_score = self.auc.evaluate([explanation], [self.image], steps=10).values()
110110
insertion_auc_score, deletion_auc_score, delta_auc_score = auc_score
111-
assert insertion_auc_score >= 0.5
112-
assert deletion_auc_score >= 0.1
113-
assert delta_auc_score >= 0.35
111+
assert np.abs(insertion_auc_score - 0.53) <= 0.01
112+
assert np.abs(deletion_auc_score - 0.13) <= 0.01
113+
assert np.abs(delta_auc_score - 0.39) <= 0.01
114114

115115
adcc_score = self.adcc.evaluate([explanation], [self.image])["adcc"]
116-
assert adcc_score > 0.5
116+
assert np.abs(adcc_score - 0.55) <= 0.01
117117

118118
def test_explainer_images(self):
119119
images = [self.image, self.image]
@@ -128,9 +128,9 @@ def test_explainer_images(self):
128128

129129
auc_score = self.auc.evaluate(explanations, images, steps=10).values()
130130
insertion_auc_score, deletion_auc_score, delta_auc_score = auc_score
131-
assert insertion_auc_score >= 0.9
132-
assert deletion_auc_score >= 0.2
133-
assert delta_auc_score >= 0.7
131+
assert np.abs(insertion_auc_score - 0.94) <= 0.01
132+
assert np.abs(deletion_auc_score - 0.23) <= 0.01
133+
assert np.abs(delta_auc_score - 0.71) <= 0.01
134134

135135
adcc_score = self.adcc.evaluate(explanations, images)["adcc"]
136-
assert adcc_score > 0.9
136+
assert np.abs(adcc_score - 0.96) <= 0.01

tests/regression/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)