借鉴:python遍历整个文件夹中的所有.txt文件并将绝对路径保存在指定的txt文档中的 >>> 程序
import os
sets=['train','test','val']
for image_set in sets:
image_path=os.path.join('..\\Visdrone2019\\JPEGImages\\%s') %(image_set)
txt=open("..\\coco\\"+"%s"%(image_set)+".txt",'w')
for (dirpath,dirnames,filenames) in os.walk(image_path):
for filename in filenames:
if os.path.splitext(filename)[1]=='.jpg':
txt.write('..\\Visdrone2019\\JPEGImages\\%s\\'+filename+'\n')
记录一下%s的正确位置