1 import shutil 2 f_in = 'D:/wiki_crop' 3 # 读取文件中图片信息根据性别分类图片到对应目录中 4 dirroot = "D:/" 5 f = open(dirroot+"\\lable2.txt","r") 6 s = 0 7 i=1 8 print(f) 9 # line = f.readlines() 10 # print(line[1]) 11 12 for line in f.readlines(): 13 line = line.strip().split(' ') 14 15 s = s + 1 16 # print(type(line)) 17 # print(line[3]) 18 # dir = list(line) 19 20 # imgName = line[i]+line[i+1] 21 22 imgName = line[0] 23 # print(line[0]) 24 print(s) 25 print(f_in+'/'+imgName) 26 num= str(s) 27 if i > 0: 28 if line[3]== "0.0": 29 print("female") 30 try: 31 shutil.copy(f_in+'/'+imgName, "D:/data/female/"+ num+ '.jpg') 32 except: 33 pass 34 # 移动图片到female目录 35 elif line[3]=="1.0": 36 print("male") 37 try: 38 shutil.copy(f_in+'/'+imgName, "D:/data/male/" + num+ '.jpg') 39 except: 40 pass 41 # 移动图片到male目录 42 else: 43 print("N") 44 #未识别男女 45 46 f.close()
附上自己从wiki.mat中提取出来的标签
https://pan.baidu.com/s/1dGT6ghV
再附上wiki的数据集地址
https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/