Created
February 9, 2021 14:04
-
-
Save rrryan2016/a005126b70d59c3689f188b653bf6685 to your computer and use it in GitHub Desktop.
Decompress feret dataset, decompress .bz2 file in batch by python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment