5
5
from typing import Dict , List , Tuple
6
6
7
7
import cv2
8
+ import numpy as np
8
9
import openvino as ov
9
10
import pytest
10
11
@@ -53,35 +54,34 @@ def load_gt_bboxes(json_coco_path: str) -> List[Dict[str, List[Tuple[int, int, i
53
54
return list (result .values ())
54
55
55
56
56
- class TestDummyRegression :
57
+ class TestAccuracyMetrics :
57
58
image = cv2 .imread (IMAGE_PATH )
58
59
gt_bboxes = load_gt_bboxes (COCO_ANN_PATH )
59
60
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
-
68
61
@pytest .fixture (autouse = True )
69
62
def setup (self , fxt_data_root ):
70
63
data_dir = fxt_data_root
71
64
retrieve_otx_model (data_dir , MODEL_NAME )
72
65
model_path = data_dir / "otx_models" / (MODEL_NAME + ".xml" )
73
66
model = ov .Core ().read_model (model_path )
74
67
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
+
75
75
self .explainer = Explainer (
76
76
model = model ,
77
77
task = Task .CLASSIFICATION ,
78
- preprocess_fn = self . preprocess_fn ,
78
+ preprocess_fn = preprocess_fn ,
79
79
explain_mode = ExplainMode .WHITEBOX ,
80
80
)
81
81
82
82
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 )
85
85
86
86
def test_explainer_image (self ):
87
87
explanation = self .explainer (self .image , targets = ["person" ], label_names = VOC_NAMES , colormap = False )
@@ -92,12 +92,12 @@ def test_explainer_image(self):
92
92
93
93
auc_score = self .auc .evaluate ([explanation ], [self .image ], steps = 10 ).values ()
94
94
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
98
98
99
99
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
101
101
102
102
def test_explainer_image_2_classes (self ):
103
103
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):
108
108
109
109
auc_score = self .auc .evaluate ([explanation ], [self .image ], steps = 10 ).values ()
110
110
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
114
114
115
115
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
117
117
118
118
def test_explainer_images (self ):
119
119
images = [self .image , self .image ]
@@ -128,9 +128,9 @@ def test_explainer_images(self):
128
128
129
129
auc_score = self .auc .evaluate (explanations , images , steps = 10 ).values ()
130
130
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
134
134
135
135
adcc_score = self .adcc .evaluate (explanations , images )["adcc" ]
136
- assert adcc_score > 0.9
136
+ assert np . abs ( adcc_score - 0.96 ) <= 0.01
0 commit comments