1. 程式人生 > >python下載vgg_face_dataset資料集

python下載vgg_face_dataset資料集

import threading
import urllib
import os


def download_and_save(url, savename):
    try:
        urlopen = urllib.URLopener()
        fp = urlopen.open(url)
        data = fp.read()
        fp.close()
        fid = open(savename, 'w+b')
        fid.write(data)
        #print "下載成功:" + url
        fid.close()
    
except IOError: print "下載失敗:" + url def get_all_iamge(filename): fid = open('files/'+filename) lines = fid.readlines() for line in lines: line_split = line.split(' ') name = filename[:-4] image_id = line_split[0] image_url = line_split[1] if
False == os.path.exists('image/'+name): os.mkdir('image/'+name) savefile ='image/'+ name + '/' + image_id + '.jpg' while True: if (len(threading.enumerate()) < 10): break t = threading.Thread(target=download_and_save, args=(image_url, savefile,)) t.start()
if __name__ == "__main__": file_list = os.listdir('files') for file in file_list: get_all_iamge(file)

圖片人名列表:

image

下載的圖片:

image