@@ -75,26 +75,26 @@ def __init__(
7575
7676 def preprocess (self , inputs : np .ndarray ) -> list [dict ]:
7777 """Data preprocess method for Anomalib models.
78-
78+
7979 Anomalib models typically expect inputs in [0,1] range as float32.
8080 """
8181 original_shape = inputs .shape
82-
82+
8383 if self ._is_dynamic :
8484 h , w , c = inputs .shape
8585 resized_shape = (w , h , c )
86-
86+
8787 # For anomalib models, convert to float32 and normalize to [0,1] if needed
8888 if inputs .dtype == np .uint8 :
8989 processed_image = inputs .astype (np .float32 ) / 255.0
9090 else :
9191 processed_image = inputs .astype (np .float32 )
92-
92+
9393 # Apply layout change but skip InputTransform (which might apply wrong normalization)
9494 processed_image = self ._change_layout (processed_image )
9595 else :
9696 resized_shape = (self .w , self .h , self .c )
97- # For fixed models, use standard preprocessing
97+ # For fixed models, use standard preprocessing
9898 if self .embedded_processing :
9999 processed_image = inputs [None ]
100100 else :
@@ -104,15 +104,15 @@ def preprocess(self, inputs: np.ndarray) -> list[dict]:
104104 else :
105105 processed_image = inputs .astype (np .float32 )
106106 processed_image = self ._change_layout (processed_image )
107-
107+
108108 return [
109109 {self .image_blob_name : processed_image },
110110 {
111111 "original_shape" : original_shape ,
112112 "resized_shape" : resized_shape ,
113113 },
114114 ]
115-
115+
116116 def postprocess (self , outputs : dict [str , np .ndarray ], meta : dict [str , Any ]) -> AnomalyResult :
117117 """Post-processes the outputs and returns the results.
118118
@@ -128,7 +128,7 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]) -> A
128128 pred_mask : np .ndarray | None = None
129129 pred_boxes : np .ndarray | None = None
130130
131- anomalib_keys = [' pred_score' , ' pred_label' , ' pred_mask' , ' anomaly_map' ]
131+ anomalib_keys = [" pred_score" , " pred_label" , " pred_mask" , " anomaly_map" ]
132132 if not all (key in outputs for key in anomalib_keys ):
133133 predictions = outputs [next (iter (self .outputs ))]
134134
@@ -149,12 +149,12 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]) -> A
149149
150150 if pred_label == self .labels [0 ]: # normal
151151 npred_score = 1 - npred_score # Score of normal is 1 - score of anomaly
152- pred_score = npred_score .item ()
152+ pred_score = npred_score .item ()
153153 else :
154- pred_score = outputs [' pred_score' ].item ()
155- pred_label = str (outputs [' pred_label' ].item ())
156- anomaly_map = outputs [' anomaly_map' ].squeeze ()
157- pred_mask = outputs [' pred_mask' ].squeeze ().astype (np .uint8 )
154+ pred_score = outputs [" pred_score" ].item ()
155+ pred_label = str (outputs [" pred_label" ].item ())
156+ anomaly_map = outputs [" anomaly_map" ].squeeze ()
157+ pred_mask = outputs [" pred_mask" ].squeeze ().astype (np .uint8 )
158158
159159 anomaly_map *= 255
160160 anomaly_map = np .round (anomaly_map ).astype (np .uint8 )
@@ -173,7 +173,6 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]) -> A
173173 if self .task == "detection" :
174174 pred_boxes = self ._get_boxes (pred_mask )
175175
176-
177176 return AnomalyResult (
178177 anomaly_map = anomaly_map ,
179178 pred_boxes = pred_boxes ,
0 commit comments