Skip to content

Commit 47f183a

Browse files
committed
Convet private _validate methods to public validate method
1 parent 92b96fd commit 47f183a

File tree

7 files changed

+171
-171
lines changed

7 files changed

+171
-171
lines changed

src/anomalib/data/dataclasses/generic.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,28 @@ class _InputFields(Generic[T, ImageT, MaskT, PathT], ABC):
128128
methods.
129129
"""
130130

131-
image: FieldDescriptor[ImageT] = FieldDescriptor(validator_name="_validate_image")
132-
gt_label: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_gt_label")
133-
gt_mask: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="_validate_gt_mask")
134-
mask_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="_validate_mask_path")
131+
image: FieldDescriptor[ImageT] = FieldDescriptor(validator_name="validate_image")
132+
gt_label: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_gt_label")
133+
gt_mask: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="validate_gt_mask")
134+
mask_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="validate_mask_path")
135135

136136
@abstractmethod
137-
def _validate_image(self, image: ImageT) -> ImageT:
137+
def validate_image(self, image: ImageT) -> ImageT:
138138
"""Validate the image."""
139139
raise NotImplementedError
140140

141141
@abstractmethod
142-
def _validate_gt_mask(self, gt_mask: MaskT) -> MaskT | None:
142+
def validate_gt_mask(self, gt_mask: MaskT) -> MaskT | None:
143143
"""Validate the ground truth mask."""
144144
raise NotImplementedError
145145

146146
@abstractmethod
147-
def _validate_mask_path(self, mask_path: PathT) -> PathT | None:
147+
def validate_mask_path(self, mask_path: PathT) -> PathT | None:
148148
"""Validate the mask path."""
149149
raise NotImplementedError
150150

151151
@abstractmethod
152-
def _validate_gt_label(self, gt_label: T) -> T | None:
152+
def validate_gt_label(self, gt_label: T) -> T | None:
153153
"""Validate the ground truth label."""
154154
raise NotImplementedError
155155

@@ -163,7 +163,7 @@ class _ImageInputFields(Generic[PathT], ABC):
163163
with disk-stored image datasets, facilitating custom data loading strategies.
164164
165165
The ``image_path`` field uses a ``FieldDescriptor`` with a validation method.
166-
Subclasses must implement ``_validate_image_path`` to ensure path validity
166+
Subclasses must implement ``validate_image_path`` to ensure path validity
167167
according to specific Anomalib model or dataset requirements.
168168
169169
This class is designed to complement ``_InputFields`` for comprehensive
@@ -172,7 +172,7 @@ class _ImageInputFields(Generic[PathT], ABC):
172172
Examples:
173173
Assuming a concrete implementation ``DummyImageInput``:
174174
>>> class DummyImageInput(_ImageInputFields):
175-
... def _validate_image_path(self, image_path):
175+
... def validate_image_path(self, image_path):
176176
... return image_path # Implement actual validation
177177
... # Implement other required methods
178178
@@ -190,10 +190,10 @@ class _ImageInputFields(Generic[PathT], ABC):
190190
methods.
191191
"""
192192

193-
image_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="_validate_image_path")
193+
image_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="validate_image_path")
194194

195195
@abstractmethod
196-
def _validate_image_path(self, image_path: PathT) -> PathT | None:
196+
def validate_image_path(self, image_path: PathT) -> PathT | None:
197197
"""Validate the image path."""
198198
raise NotImplementedError
199199

@@ -217,7 +217,7 @@ class _VideoInputFields(Generic[T, ImageT, MaskT, PathT], ABC):
217217
Assuming a concrete implementation ``DummyVideoInput``:
218218
219219
>>> class DummyVideoInput(_VideoInputFields):
220-
... def _validate_original_image(self, original_image):
220+
... def validate_original_image(self, original_image):
221221
... return original_image # Implement actual validation
222222
... # Implement other required methods
223223
@@ -243,34 +243,34 @@ class _VideoInputFields(Generic[T, ImageT, MaskT, PathT], ABC):
243243
methods.
244244
"""
245245

246-
original_image: FieldDescriptor[ImageT | None] = FieldDescriptor(validator_name="_validate_original_image")
247-
video_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="_validate_video_path")
248-
target_frame: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_target_frame")
249-
frames: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_frames")
250-
last_frame: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_last_frame")
246+
original_image: FieldDescriptor[ImageT | None] = FieldDescriptor(validator_name="validate_original_image")
247+
video_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="validate_video_path")
248+
target_frame: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_target_frame")
249+
frames: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_frames")
250+
last_frame: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_last_frame")
251251

252252
@abstractmethod
253-
def _validate_original_image(self, original_image: ImageT) -> ImageT | None:
253+
def validate_original_image(self, original_image: ImageT) -> ImageT | None:
254254
"""Validate the original image."""
255255
raise NotImplementedError
256256

257257
@abstractmethod
258-
def _validate_video_path(self, video_path: PathT) -> PathT | None:
258+
def validate_video_path(self, video_path: PathT) -> PathT | None:
259259
"""Validate the video path."""
260260
raise NotImplementedError
261261

262262
@abstractmethod
263-
def _validate_target_frame(self, target_frame: T) -> T | None:
263+
def validate_target_frame(self, target_frame: T) -> T | None:
264264
"""Validate the target frame."""
265265
raise NotImplementedError
266266

267267
@abstractmethod
268-
def _validate_frames(self, frames: T) -> T | None:
268+
def validate_frames(self, frames: T) -> T | None:
269269
"""Validate the frames."""
270270
raise NotImplementedError
271271

272272
@abstractmethod
273-
def _validate_last_frame(self, last_frame: T) -> T | None:
273+
def validate_last_frame(self, last_frame: T) -> T | None:
274274
"""Validate the last frame."""
275275
raise NotImplementedError
276276

@@ -293,9 +293,9 @@ class _DepthInputFields(Generic[T, PathT], _ImageInputFields[PathT], ABC):
293293
Assuming a concrete implementation ``DummyDepthInput``:
294294
295295
>>> class DummyDepthInput(_DepthInputFields):
296-
... def _validate_depth_map(self, depth_map):
296+
... def validate_depth_map(self, depth_map):
297297
... return depth_map # Implement actual validation
298-
... def _validate_depth_path(self, depth_path):
298+
... def validate_depth_path(self, depth_path):
299299
... return depth_path # Implement actual validation
300300
... # Implement other required methods
301301
@@ -316,16 +316,16 @@ class _DepthInputFields(Generic[T, PathT], _ImageInputFields[PathT], ABC):
316316
methods.
317317
"""
318318

319-
depth_map: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_depth_map")
320-
depth_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="_validate_depth_path")
319+
depth_map: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_depth_map")
320+
depth_path: FieldDescriptor[PathT | None] = FieldDescriptor(validator_name="validate_depth_path")
321321

322322
@abstractmethod
323-
def _validate_depth_map(self, depth_map: ImageT) -> ImageT | None:
323+
def validate_depth_map(self, depth_map: ImageT) -> ImageT | None:
324324
"""Validate the depth map."""
325325
raise NotImplementedError
326326

327327
@abstractmethod
328-
def _validate_depth_path(self, depth_path: PathT) -> PathT | None:
328+
def validate_depth_path(self, depth_path: PathT) -> PathT | None:
329329
"""Validate the depth path."""
330330
raise NotImplementedError
331331

@@ -345,13 +345,13 @@ class _OutputFields(Generic[T, MaskT], ABC):
345345
Assuming a concrete implementation ``DummyOutput``:
346346
347347
>>> class DummyOutput(_OutputFields):
348-
... def _validate_anomaly_map(self, anomaly_map):
348+
... def validate_anomaly_map(self, anomaly_map):
349349
... return anomaly_map # Implement actual validation
350-
... def _validate_pred_score(self, pred_score):
350+
... def validate_pred_score(self, pred_score):
351351
... return pred_score # Implement actual validation
352-
... def _validate_pred_mask(self, pred_mask):
352+
... def validate_pred_mask(self, pred_mask):
353353
... return pred_mask # Implement actual validation
354-
... def _validate_pred_label(self, pred_label):
354+
... def validate_pred_label(self, pred_label):
355355
... return pred_label # Implement actual validation
356356
357357
>>> # Create an output instance with predictions
@@ -374,28 +374,28 @@ class _OutputFields(Generic[T, MaskT], ABC):
374374
methods.
375375
"""
376376

377-
anomaly_map: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="_validate_anomaly_map")
378-
pred_score: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_pred_score")
379-
pred_mask: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="_validate_pred_mask")
380-
pred_label: FieldDescriptor[T | None] = FieldDescriptor(validator_name="_validate_pred_label")
377+
anomaly_map: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="validate_anomaly_map")
378+
pred_score: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_pred_score")
379+
pred_mask: FieldDescriptor[MaskT | None] = FieldDescriptor(validator_name="validate_pred_mask")
380+
pred_label: FieldDescriptor[T | None] = FieldDescriptor(validator_name="validate_pred_label")
381381

382382
@abstractmethod
383-
def _validate_anomaly_map(self, anomaly_map: MaskT) -> MaskT | None:
383+
def validate_anomaly_map(self, anomaly_map: MaskT) -> MaskT | None:
384384
"""Validate the anomaly map."""
385385
raise NotImplementedError
386386

387387
@abstractmethod
388-
def _validate_pred_score(self, pred_score: T) -> T | None:
388+
def validate_pred_score(self, pred_score: T) -> T | None:
389389
"""Validate the predicted score."""
390390
raise NotImplementedError
391391

392392
@abstractmethod
393-
def _validate_pred_mask(self, pred_mask: MaskT) -> MaskT | None:
393+
def validate_pred_mask(self, pred_mask: MaskT) -> MaskT | None:
394394
"""Validate the predicted mask."""
395395
raise NotImplementedError
396396

397397
@abstractmethod
398-
def _validate_pred_label(self, pred_label: T) -> T | None:
398+
def validate_pred_label(self, pred_label: T) -> T | None:
399399
"""Validate the predicted label."""
400400
raise NotImplementedError
401401

@@ -477,7 +477,7 @@ class _GenericItem(
477477
Assuming a concrete implementation ``DummyItem``:
478478
479479
>>> class DummyItem(_GenericItem):
480-
... def _validate_image(self, image):
480+
... def validate_image(self, image):
481481
... return image # Implement actual validation
482482
... # Implement other required methods
483483
@@ -522,7 +522,7 @@ class _GenericBatch(
522522
Assuming a concrete implementation ``DummyBatch``:
523523
524524
>>> class DummyBatch(_GenericBatch):
525-
... def _validate_image(self, image):
525+
... def validate_image(self, image):
526526
... return image # Implement actual validation
527527
... # Implement other required methods
528528

src/anomalib/data/dataclasses/numpy/depth.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,57 @@ class NumpyDepthItem(_DepthInputFields[np.ndarray, str], NumpyItem):
2222
"""
2323

2424
@staticmethod
25-
def _validate_image(image: np.ndarray) -> np.ndarray:
25+
def validate_image(image: np.ndarray) -> np.ndarray:
2626
"""Validate the image."""
2727
return NumpyDepthValidator.validate_image(image)
2828

2929
@staticmethod
30-
def _validate_gt_label(gt_label: np.ndarray | None) -> np.ndarray | None:
30+
def validate_gt_label(gt_label: np.ndarray | None) -> np.ndarray | None:
3131
"""Validate the ground truth label."""
3232
return NumpyDepthValidator.validate_gt_label(gt_label)
3333

3434
@staticmethod
35-
def _validate_gt_mask(gt_mask: np.ndarray | None) -> np.ndarray | None:
35+
def validate_gt_mask(gt_mask: np.ndarray | None) -> np.ndarray | None:
3636
"""Validate the ground truth mask."""
3737
return NumpyDepthValidator.validate_gt_mask(gt_mask)
3838

3939
@staticmethod
40-
def _validate_mask_path(mask_path: str | None) -> str | None:
40+
def validate_mask_path(mask_path: str | None) -> str | None:
4141
"""Validate the mask path."""
4242
return NumpyDepthValidator.validate_mask_path(mask_path)
4343

4444
@staticmethod
45-
def _validate_anomaly_map(anomaly_map: np.ndarray | None) -> np.ndarray | None:
45+
def validate_anomaly_map(anomaly_map: np.ndarray | None) -> np.ndarray | None:
4646
"""Validate the anomaly map."""
4747
return NumpyDepthValidator.validate_anomaly_map(anomaly_map)
4848

4949
@staticmethod
50-
def _validate_pred_score(pred_score: np.ndarray | None) -> np.ndarray | None:
50+
def validate_pred_score(pred_score: np.ndarray | None) -> np.ndarray | None:
5151
"""Validate the prediction score."""
5252
return NumpyDepthValidator.validate_pred_score(pred_score)
5353

5454
@staticmethod
55-
def _validate_pred_mask(pred_mask: np.ndarray | None) -> np.ndarray | None:
55+
def validate_pred_mask(pred_mask: np.ndarray | None) -> np.ndarray | None:
5656
"""Validate the prediction mask."""
5757
return NumpyDepthValidator.validate_pred_mask(pred_mask)
5858

5959
@staticmethod
60-
def _validate_pred_label(pred_label: np.ndarray | None) -> np.ndarray | None:
60+
def validate_pred_label(pred_label: np.ndarray | None) -> np.ndarray | None:
6161
"""Validate the prediction label."""
6262
return NumpyDepthValidator.validate_pred_label(pred_label)
6363

6464
@staticmethod
65-
def _validate_image_path(image_path: str | None) -> str | None:
65+
def validate_image_path(image_path: str | None) -> str | None:
6666
"""Validate the image path."""
6767
return NumpyDepthValidator.validate_image_path(image_path)
6868

6969
@staticmethod
70-
def _validate_depth_map(depth_map: np.ndarray | None) -> np.ndarray | None:
70+
def validate_depth_map(depth_map: np.ndarray | None) -> np.ndarray | None:
7171
"""Validate the depth map."""
7272
return NumpyDepthValidator.validate_depth_map(depth_map)
7373

7474
@staticmethod
75-
def _validate_depth_path(depth_path: str | None) -> str | None:
75+
def validate_depth_path(depth_path: str | None) -> str | None:
7676
"""Validate the depth path."""
7777
return NumpyDepthValidator.validate_depth_path(depth_path)
7878

@@ -87,50 +87,50 @@ class NumpyDepthBatch(
8787
item_class = NumpyDepthItem
8888

8989
@staticmethod
90-
def _validate_image(image: np.ndarray) -> np.ndarray:
90+
def validate_image(image: np.ndarray) -> np.ndarray:
9191
"""Validate the image."""
9292
return NumpyDepthBatchValidator.validate_image(image)
9393

94-
def _validate_gt_label(self, gt_label: np.ndarray | None) -> np.ndarray | None:
94+
def validate_gt_label(self, gt_label: np.ndarray | None) -> np.ndarray | None:
9595
"""Validate the ground truth label."""
9696
return NumpyDepthBatchValidator.validate_gt_label(gt_label, self.batch_size)
9797

98-
def _validate_gt_mask(self, gt_mask: np.ndarray | None) -> np.ndarray | None:
98+
def validate_gt_mask(self, gt_mask: np.ndarray | None) -> np.ndarray | None:
9999
"""Validate the ground truth mask."""
100100
return NumpyDepthBatchValidator.validate_gt_mask(gt_mask, self.batch_size)
101101

102-
def _validate_mask_path(self, mask_path: list[str] | None) -> list[str] | None:
102+
def validate_mask_path(self, mask_path: list[str] | None) -> list[str] | None:
103103
"""Validate the mask path."""
104104
return NumpyDepthBatchValidator.validate_mask_path(mask_path, self.batch_size)
105105

106-
def _validate_anomaly_map(self, anomaly_map: np.ndarray | None) -> np.ndarray | None:
106+
def validate_anomaly_map(self, anomaly_map: np.ndarray | None) -> np.ndarray | None:
107107
"""Validate the anomaly map."""
108108
return NumpyDepthBatchValidator.validate_anomaly_map(anomaly_map, self.batch_size)
109109

110110
@staticmethod
111-
def _validate_pred_score(pred_score: np.ndarray | None) -> np.ndarray | None:
111+
def validate_pred_score(pred_score: np.ndarray | None) -> np.ndarray | None:
112112
"""Validate the prediction score."""
113113
return NumpyDepthBatchValidator.validate_pred_score(pred_score)
114114

115-
def _validate_pred_mask(self, pred_mask: np.ndarray | None) -> np.ndarray | None:
115+
def validate_pred_mask(self, pred_mask: np.ndarray | None) -> np.ndarray | None:
116116
"""Validate the prediction mask."""
117117
return NumpyDepthBatchValidator.validate_pred_mask(pred_mask, self.batch_size)
118118

119119
@staticmethod
120-
def _validate_pred_label(pred_label: np.ndarray | None) -> np.ndarray | None:
120+
def validate_pred_label(pred_label: np.ndarray | None) -> np.ndarray | None:
121121
"""Validate the prediction label."""
122122
return NumpyDepthBatchValidator.validate_pred_label(pred_label)
123123

124124
@staticmethod
125-
def _validate_image_path(image_path: list[str] | None) -> list[str] | None:
125+
def validate_image_path(image_path: list[str] | None) -> list[str] | None:
126126
"""Validate the image path."""
127127
return NumpyDepthBatchValidator.validate_image_path(image_path)
128128

129-
def _validate_depth_map(self, depth_map: np.ndarray | None) -> np.ndarray | None:
129+
def validate_depth_map(self, depth_map: np.ndarray | None) -> np.ndarray | None:
130130
"""Validate the depth map."""
131131
return NumpyDepthBatchValidator.validate_depth_map(depth_map, self.batch_size)
132132

133133
@staticmethod
134-
def _validate_depth_path(depth_path: list[str] | None) -> list[str] | None:
134+
def validate_depth_path(depth_path: list[str] | None) -> list[str] | None:
135135
"""Validate the depth path."""
136136
return NumpyDepthBatchValidator.validate_depth_path(depth_path)

0 commit comments

Comments
 (0)