Created
May 21, 2019 16:08
-
-
Save makeyourownalgorithmicart/27fd5f3575050b1b8829028323a4c3f2 to your computer and use it in GitHub Desktop.
coverts celebaA zip file of images to h5py dataset
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
# (c) Tariq Rashid 2019 | |
# GPL v2 | |
import h5py | |
import zipfile | |
import imageio | |
import os | |
with h5py.File('celeba_dataset/celeba_aligned_small.h5py', 'w') as hf: | |
count = 1 | |
with zipfile.ZipFile('celeba_dataset/img_align_celeba.zip', 'r') as zf: | |
for i in zf.namelist(): | |
if (i[-4:] == '.jpg'): | |
ofile = zf.extract(i) | |
img = imageio.imread(ofile) | |
#img_list.append(img) | |
os.remove(ofile) | |
count = count + 1 | |
if (count%10000 == 0): | |
print(count, img.shape) | |
pass | |
hf.create_dataset(i, data=img, compression="gzip", compression_opts=9) | |
if (count == 20000): | |
break | |
pass | |
pass | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment