1212import shutil
1313import random
1414import xml .etree .ElementTree as ET
15+ from dataset_tools .jade_voc_datasets import GetXmlClassesNames
1516
1617def CreateSavePath (save_path ):
1718 if os .path .exists (save_path ):
@@ -143,9 +144,13 @@ def CreateVOCDataset(dir, datasetname,save_path=None,rate=0.95):
143144 if len (f2 .read ()) == 0 :
144145 pass
145146 else :
146- shutil .copy (os .path .join (dir , JPEGImages , train_image_file ), save_image_path )
147- shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ), save_xml_path )
148- f .write (filename + "\n " )
147+ class_name_list = GetXmlClassesNames (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ))
148+ if len (class_name_list ) > 0 :
149+ shutil .copy (os .path .join (dir , JPEGImages , train_image_file ), save_image_path )
150+ shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ), save_xml_path )
151+ f .write (filename + "\n " )
152+ else :
153+ print (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ))
149154 # f.write(image_file + " " + xml_file + "\n")
150155
151156 for test_image_file in test_image_files :
@@ -160,10 +165,14 @@ def CreateVOCDataset(dir, datasetname,save_path=None,rate=0.95):
160165 if len (f2 .read ()) == 0 :
161166 pass
162167 else :
163- shutil .copy (os .path .join (dir , JPEGImages , train_image_file ), save_image_path )
164- shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ), save_xml_path )
165- f .write (filename + "\n " )
166- # f.write(image_file + " " + xml_file + "\n")
168+ class_name_list = GetXmlClassesNames (
169+ os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ))
170+ if len (class_name_list ) > 0 :
171+ shutil .copy (os .path .join (dir , JPEGImages , test_image_file ), save_image_path )
172+ shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ), save_xml_path )
173+ f .write (filename + "\n " )
174+ else :
175+ print (os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ))
167176
168177 for train_image_file in train_image_files :
169178 with open (os .path .join (Main_path , "train.txt" ), "a" ) as f :
@@ -175,7 +184,15 @@ def CreateVOCDataset(dir, datasetname,save_path=None,rate=0.95):
175184 if len (f2 .read ()) == 0 :
176185 pass
177186 else :
178- f .write (image_file + " " + xml_file + "\n " )
187+ class_name_list = GetXmlClassesNames (
188+ os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ))
189+ if len (class_name_list ) > 0 :
190+ shutil .copy (os .path .join (dir , JPEGImages , train_image_file ), save_image_path )
191+ shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ), save_xml_path )
192+ f .write (image_file + " " + xml_file + "\n " )
193+ else :
194+ print (os .path .join (dir , DIRECTORY_ANNOTATIONS , train_image_file [:- 4 ] + ".xml" ))
195+
179196 # f.write(filename + "\n")
180197
181198
@@ -189,7 +206,16 @@ def CreateVOCDataset(dir, datasetname,save_path=None,rate=0.95):
189206 if len (f2 .read ()) == 0 :
190207 pass
191208 else :
192- f .write (image_file + " " + xml_file + "\n " )
209+ class_name_list = GetXmlClassesNames (
210+ os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ))
211+ if len (class_name_list ) > 0 :
212+ shutil .copy (os .path .join (dir , JPEGImages , test_image_file ), save_image_path )
213+ shutil .copy (os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ),
214+ save_xml_path )
215+ f .write (image_file + " " + xml_file + "\n " )
216+ else :
217+ print (os .path .join (dir , DIRECTORY_ANNOTATIONS , test_image_file [:- 4 ] + ".xml" ))
218+
193219 # f.write(filename + "\n")
194220
195221def CreateLabelList (dir ):
0 commit comments