@@ -205,12 +205,29 @@ def removeNolabelDatasets(root_path):
205205 os .remove (image_path )
206206 progressBar .update ()
207207
208+
209+ def get_no_exists_index (arr1 ,arr2 ):
210+ for (i ,arr_1 ) in enumerate (arr1 ):
211+ if arr_1 not in arr2 :
212+ return 0 ,i
213+ for (i ,arr_2 ) in enumerate (arr2 ):
214+ if arr_2 not in arr1 :
215+ return 1 ,i
216+ else :
217+ return None ,None
218+
208219def removeNolabelVocDatasets (root_path ):
209220 for day in os .listdir (root_path ):
210221 if os .path .isdir (os .path .join (root_path ,day )):
211222 image_path_list = GetAllImagesPath (os .path .join (root_path , day , DIRECTORY_IMAGES ))
212223 progressBar = ProgressBar (len (image_path_list ))
224+ xml_path_list = GetFilesWithLastNamePath (os .path .join (root_path ,day ,DIRECTORY_ANNOTATIONS ),".xml" )
225+ xml_name_list = []
226+ for xml_path in xml_path_list :
227+ xml_name_list .append (GetLastDir (xml_path ).split ("." )[0 ])
228+ image_name_list = []
213229 for image_path in image_path_list :
230+ image_name_list .append (GetLastDir (image_path .split ("." )[0 ]))
214231 if os .path .exists (
215232 os .path .join (root_path , day , DIRECTORY_ANNOTATIONS , GetLastDir (image_path )[:- 4 ] + ".xml" )):
216233 imagename , shape , bboxes , labels_text , labels , difficult , truncated = ProcessXml (
@@ -226,8 +243,13 @@ def removeNolabelVocDatasets(root_path):
226243 os .remove (image_path )
227244 progressBar .update ()
228245
229-
230-
246+ list_index ,index = get_no_exists_index (image_name_list ,xml_name_list )
247+ if list_index == 0 :
248+ print ("需要删除图片,{}" .format (image_path_list [index ]))
249+ os .remove (image_path_list [index ])
250+ elif list_index == 1 :
251+ print ("需要标注文件,{}" .format (xml_path_list [index ]))
252+ os .remove (xml_path_list [index ])
231253def GetContaNumberPath (image_path_list ):
232254 ContaNumber_list = []
233255 for file in image_path_list :
0 commit comments