# conding:utf-8
import base64
import csv
import os,sys
csv.field_size_limit(10000000000)
for i in range(0,8):
filename = 'MsCelebV1-ImageThumbnails.part.0'+str(i)+'.tsv'
outputDir = 'MS_Celeb_1M_0'+str(i)+'/'
with open(filename, 'r') as tsvF:
reader = csv.reader(tsvF, delimiter='\t')
i = 0
for row in reader:
MID, imgSearchRank, faceID, data = row[0], row[1], row[2], base64.b64decode(row[-1])
saveDir = os.path.join(outputDir, MID.replace(' ','-').replace('/','-'))
if not os.path.exists(saveDir):
os.makedirs(saveDir)
savePath = os.path.join(saveDir, "{}-{}.jpg".format(imgSearchRank.replace(' ','-').replace('/','-'), faceID))
with open(savePath, 'wb') as f:
f.write(data)
i += 1
if i % 10000 == 0:
print("Extracted {} images.".format(i),filename)
print i ## keep error point