24
24
from anomalib .data .utils .path import _prepare_files_labels , validate_and_resolve_path
25
25
26
26
27
- def make_folder3d_dataset ( # noqa: C901
27
+ def make_folder3d_dataset (
28
28
normal_dir : str | Path ,
29
29
root : str | Path | None = None ,
30
30
abnormal_dir : str | Path | None = None ,
@@ -78,37 +78,28 @@ def make_folder3d_dataset( # noqa: C901
78
78
msg = "A folder location must be provided in normal_dir."
79
79
raise ValueError (msg )
80
80
81
- filenames = []
82
- labels = []
83
- dirs = {DirType .NORMAL : normal_dir }
84
-
85
- if abnormal_dir :
86
- dirs [DirType .ABNORMAL ] = abnormal_dir
87
-
88
- if normal_test_dir :
89
- dirs [DirType .NORMAL_TEST ] = normal_test_dir
90
-
91
- if normal_depth_dir :
92
- dirs [DirType .NORMAL_DEPTH ] = normal_depth_dir
93
-
94
- if abnormal_depth_dir :
95
- dirs [DirType .ABNORMAL_DEPTH ] = abnormal_depth_dir
96
-
97
- if normal_test_depth_dir :
98
- dirs [DirType .NORMAL_TEST_DEPTH ] = normal_test_depth_dir
99
-
100
- if mask_dir :
101
- dirs [DirType .MASK ] = mask_dir
102
-
103
- for dir_type , path in dirs .items ():
104
- filename , label = _prepare_files_labels (path , dir_type , extensions )
105
- filenames += filename
106
- labels += label
81
+ dirs = {
82
+ DirType .NORMAL : normal_dir ,
83
+ DirType .ABNORMAL : abnormal_dir ,
84
+ DirType .NORMAL_TEST : normal_test_dir ,
85
+ DirType .NORMAL_DEPTH : normal_depth_dir ,
86
+ DirType .ABNORMAL_DEPTH : abnormal_depth_dir ,
87
+ DirType .NORMAL_TEST_DEPTH : normal_test_depth_dir ,
88
+ DirType .MASK : mask_dir ,
89
+ }
90
+
91
+ filenames : list [Path ] = []
92
+ labels : list [str ] = []
93
+
94
+ for dir_type , dir_path in dirs .items ():
95
+ if dir_path is not None :
96
+ filename , label = _prepare_files_labels (dir_path , dir_type , extensions )
97
+ filenames += filename
98
+ labels += label
107
99
108
100
samples = DataFrame ({"image_path" : filenames , "label" : labels })
109
101
samples = samples .sort_values (by = "image_path" , ignore_index = True )
110
102
111
- # Create label index for normal (0) and abnormal (1) images.
112
103
samples .loc [
113
104
(samples .label == DirType .NORMAL ) | (samples .label == DirType .NORMAL_TEST ),
114
105
"label_index" ,
@@ -137,9 +128,12 @@ def make_folder3d_dataset( # noqa: C901
137
128
.all ()
138
129
)
139
130
if not mismatch :
140
- msg = """Mismatch between anomalous images and depth images. Make sure the mask files
141
- in 'xyz' folder follow the same naming convention as the anomalous images in the dataset
142
- (e.g. image: '000.png', depth: '000.tiff')."""
131
+ msg = (
132
+ "Mismatch between anomalous images and depth images. "
133
+ "Make sure the mask files in 'xyz' folder follow the same naming "
134
+ "convention as the anomalous images in the dataset"
135
+ "(e.g. image: '000.png', depth: '000.tiff')."
136
+ )
143
137
raise MisMatchError (msg )
144
138
145
139
missing_depth_files = samples .depth_path .apply (
@@ -159,7 +153,7 @@ def make_folder3d_dataset( # noqa: C901
159
153
samples ["mask_path" ] = samples ["mask_path" ].fillna ("" )
160
154
samples = samples .astype ({"mask_path" : "str" })
161
155
162
- # make sure all the files exist
156
+ # Make sure all the files exist
163
157
if not samples .mask_path .apply (
164
158
lambda x : Path (x ).exists () if x != "" else True ,
165
159
).all ():
@@ -168,7 +162,7 @@ def make_folder3d_dataset( # noqa: C901
168
162
else :
169
163
samples ["mask_path" ] = ""
170
164
171
- # remove all the rows with temporal image samples that have already been assigned
165
+ # Remove all the rows with temporal image samples that have already been assigned
172
166
samples = samples .loc [
173
167
(samples .label == DirType .NORMAL ) | (samples .label == DirType .ABNORMAL ) | (samples .label == DirType .NORMAL_TEST )
174
168
]
0 commit comments