@@ -181,21 +181,21 @@ def as_pascal_voc(
181181 in the range [0, 1). Argument is used only for segmentation datasets.
182182 """
183183 if images_directory_path :
184- images_path = Path ( images_directory_path )
185- images_path . mkdir ( parents = True , exist_ok = True )
186-
184+ save_dataset_images (
185+ images_directory_path = images_directory_path , images = self . images
186+ )
187187 if annotations_directory_path :
188- annotations_path = Path (annotations_directory_path )
189- annotations_path .mkdir (parents = True , exist_ok = True )
188+ Path (annotations_directory_path ).mkdir (parents = True , exist_ok = True )
190189
191- for image_name , image in self .images .items ():
192- detections = self .annotations [image_name ]
193-
194- if images_directory_path :
195- cv2 .imwrite (str (images_path / image_name ), image )
190+ for image_path , image in self .images .items ():
191+ detections = self .annotations [image_path ]
196192
197193 if annotations_directory_path :
198- annotation_name = Path (image_name ).stem
194+ annotation_name = Path (image_path ).stem
195+ annotations_path = os .path .join (
196+ annotations_directory_path , f"{ annotation_name } .xml"
197+ )
198+ image_name = Path (image_path ).name
199199 pascal_voc_xml = detections_to_pascal_voc (
200200 detections = detections ,
201201 classes = self .classes ,
@@ -206,7 +206,7 @@ def as_pascal_voc(
206206 approximation_percentage = approximation_percentage ,
207207 )
208208
209- with open (annotations_path / f" { annotation_name } .xml" , "w" ) as f :
209+ with open (annotations_path , "w" ) as f :
210210 f .write (pascal_voc_xml )
211211
212212 @classmethod
@@ -615,9 +615,10 @@ def as_folder_structure(self, root_directory_path: str) -> None:
615615 for class_name in self .classes :
616616 os .makedirs (os .path .join (root_directory_path , class_name ), exist_ok = True )
617617
618- for image_name in self .images :
619- classification = self .annotations [image_name ]
620- image = self .images [image_name ]
618+ for image_path in self .images :
619+ classification = self .annotations [image_path ]
620+ image = self .images [image_path ]
621+ image_name = Path (image_path ).name
621622 class_id = (
622623 classification .class_id [0 ]
623624 if classification .confidence is None
@@ -666,9 +667,9 @@ def from_folder_structure(cls, root_directory_path: str) -> ClassificationDatase
666667 class_id = classes .index (class_name )
667668
668669 for image in os .listdir (os .path .join (root_directory_path , class_name )):
669- image_dir = os .path .join (root_directory_path , class_name , image )
670- images [image ] = cv2 .imread (image_dir )
671- annotations [image ] = Classifications (
670+ image_path = str ( os .path .join (root_directory_path , class_name , image ) )
671+ images [image_path ] = cv2 .imread (image_path )
672+ annotations [image_path ] = Classifications (
672673 class_id = np .array ([class_id ]),
673674 )
674675
0 commit comments