比对imagenet中Data和Annotation
在实验时会遇到data和annotation中文件不匹配的情况,这个时候可以将两个文件夹中的文件作比较
首先读取文件然后读取文件名字作比较
import os
path1 = r'E:\1'
def file_name(file_dir):
jpg_list = []
xml_list = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.JPEG':
jpg_list.append(os.path.splitext(file)[0])
elif os.path.splitext(file)[1] == '.xml':
xml_list.append(os.path.splitext(file)[0])
diff = set(xml_list).difference(set(jpg_list))
print(len(diff))
for name in diff:
print("no JPEG", name + ".xml")
diff2 = set(jpg_list).difference(set(xml_list))
print(len(diff2))
for name in diff2:
print("no xml", name + ".JPEG")
return jpg_list,xml_list
if __name__ == '__main__':
file_name(path1)