深度学习训练过程中路径文件生成
import os
import codecs # 读取文件夹中的文件名
# folder = '/path/to/folder'
folder = '自己的文件夹路径,原图'
dir_path = '文件所在文件夹,自己调整'
# dir_path1 = 'train_lab'
filenames = os.listdir(folder)
# filenames = [os.path.join(dir_path, file) for file in filenames]
folder = '自己的文件夹路径,标签'
dir_path = '文件所在文件夹,自己调整'
filenames1 = os.listdir(folder1)
filenames1 = [os.path.join(dir_path1, file) for file in filenames1]
i=0
# 将文件名写入 txt 文件
txt_file = '生成的文件路径和名称.txt'
with codecs.open(txt_file, 'w', 'utf-8') as f:
for filename in filenames:
# for i in range (300):
f.write(os.path.join(dir_path, filename) + ' ' + os.path.join(filenames1[i]) + '\n')
i+1
# f.write(filename + '\n')