解压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 直接跳转

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值