get_all_labels.py 764 B

123456789101112131415161718192021222324
  1. import argparse
  2. import os
  3. def get_all_labels(img_fold):
  4. # 获取字体文件夹列表
  5. img_fold_list = os.listdir(img_fold)
  6. # label_list.txt文件
  7. fp_label = open(str(img_fold) + '/label_list.txt', 'w')
  8. cnt = 0
  9. for img_fold_in in img_fold_list:
  10. if img_fold_in.endswith('.txt'):
  11. continue
  12. # 字体名以及对应id写入label_list.txt
  13. fp_label.write(str(cnt) + ' ' + str(img_fold_in) + '\n')
  14. cnt += 1
  15. fp_label.close()
  16. if __name__ == '__main__':
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument('--save_dir', type=str, default=r'C:\Users\KDAN\Desktop\workspace\字体分类数据集\windows_1\font_test_dataset')
  19. args = parser.parse_args()
  20. get_all_labels(args.save_dir)