import os
def generate(dir):
files = os.listdir(dir)
files.sort()
print('****************')
print('input :', dir)
print('start...')
label = int(dir.split('/s')[1])
listText = open('all_list_train.txt', 'a')
for file in files:
fileType = os.path.split(file)
if fileType[1] == '.txt':
continue
name = dir +'/'+ file + ' ' + str(int(label)) + '\n'
listText.write(name)
listText.close()
print('down!')
print('****************')
outer_path = '../dataset/training/' # 这里是你的图片的目录
if __name__ == '__main__':
folderlist = os.listdir(outer_path) # 列举文件夹
for folder in folderlist:
print(folder)
generate(os.path.join(outer_path, folder))
生成带标签的text文档
最新推荐文章于 2021-10-26 11:43:14 发布