提取图片标签

import os
def generate(dir, label):
    files = os.listdir(dir)
    files.sort()
    print('****************')
    print('input :', dir)
    print('start...')
    listText = open('all_list.txt', 'a')
    for file in files:
        fileType = os.path.split(file)
        if fileType[1] == '.txt':
            continue
        name = file + ' ' + str(int(label)) + '\n'
        listText.write(name)
    listText.close()
    print('down!')
    print('****************')
outer_path = '/Users/Administrator/code/top/top33'  # 这里是你的图片的目录
if __name__ == '__main__':
    i = 0
    folderlist = os.listdir(outer_path)  # 列举文件夹
    for folder in folderlist:
        generate(os.path.join(outer_path, folder), i)
        i += 1

  

posted @ 2018-11-30 16:46  Element_01  阅读(342)  评论(0编辑  收藏  举报