刪除沒有標註的圖像或多餘的標籤

import os

rootimgs = 'D:\paper\\2fully_convolutial_adaption\setting1\JPEGImages'
rootxmls = 'D:\paper\\2fully_convolutial_adaption\setting1\Annotations\\'
allusedxmls = []
file_imgs = os.listdir(rootimgs)
file_xmls = os.listdir(rootxmls)
for file_name in file_imgs:
    file_name = file_name[:-4] + '.xml'
    # print(file_name)
    allusedxmls.append(file_name)

for file_name in file_xmls:
    # print(file_name)
    if file_name not in allusedxmls:
       path = rootxmls + file_name
       os.remove(path)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章