解压FERET人脸数据集

批量解压FERET数据集中的.bz2文件

import sys
import os
import bz2
from bz2 import decompress

set = 'dvd1' # switch in ['dvd1','dvd2'] to decompress different dataset

if set == 'dvd1':
    path = '/data/amax/users/liuwenzhe/face/feret/colorferet/dvd1/data/images' # path of dataset in dvd1 to decompress
    un_path = '/data/amax/users/liuwenzhe/face/feret/decompressed_colorferet/dvd1/data' # path of decompressed dvd1 data you intend to store 
elif set == 'dvd2':
    path = '/data/amax/users/liuwenzhe/face/feret/colorferet/dvd2/data/images' # path of dataset in dvd2 to decompress
    un_path = '/data/amax/users/liuwenzhe/face/feret/decompressed_colorferet/dvd2/data' # path of decompressed dvd2 data you intend to store 

for (dirpath, dirnames, files) in os.walk(path):
    for filename in files:
        filepath = os.path.join(dirpath, filename)
        print('Processing {}/{} ...'.format(dirpath[-5:],filename))
        newfilepath = os.path.join(un_path, dirpath[-5:], filename[:-4])
        if not os.path.exists(os.path.join(un_path, dirpath[-5:])):
            os.makedirs(os.path.join(un_path, dirpath[-5:]))
        with open(newfilepath, 'wb') as new_file, bz2.BZ2File(filepath, 'rb') as file:
            for data in iter(lambda : file.read(100 * 1024), b''):  # todo
                new_file.write(data)

代码连接:https://gist.github.com/rrryan2016/a005126b70d59c3689f188b653bf6685 直接跳转

你可能感兴趣的:(数据集,人脸识别,python,神经网络,深度学习,机器学习)