splitdata.py 616 B

12345678910111213141516
  1. import os
  2. sourcepath = '/home/xiongweixp/data/handwriting/train/'
  3. with open(sourcepath+'val_list.txt') as f:
  4. all_lines = f.readlines()
  5. for line in all_lines:
  6. # print(line)
  7. elements = line.split(' ')
  8. dir_name = elements[1].strip()
  9. file_name = elements[0]
  10. pic_name = file_name.split('/')[1]
  11. targetPath = '/home/xiongweixp/data/handwriting/pytorch_data/validate/'+dir_name
  12. if not os.path.exists(targetPath):
  13. os.makedirs(targetPath)
  14. cmd = 'cp '+sourcepath+file_name+' '+targetPath+'/'+pic_name
  15. print(cmd)
  16. os.system(cmd)