Skip to content

Instantly share code, notes, and snippets.

@makeyourownalgorithmicart
Created June 22, 2019 00:24
Show Gist options
  • Save makeyourownalgorithmicart/2e866501ed861af2bccfb756b6879f23 to your computer and use it in GitHub Desktop.
Save makeyourownalgorithmicart/2e866501ed861af2bccfb756b6879f23 to your computer and use it in GitHub Desktop.
ferg_db to hdf5
# (c) Tariq Rashid 2019
# GPL v2
import h5py
import imageio
import os
import PIL.Image
import numpy
#
with h5py.File('fergdb/fergdb_64.h5py', 'w') as hf:
count = 1
for emotion in emotions:
for name in names:
dirname = 'fergdb/' + name+ '/' + name + '_' + emotion
with os.scandir(dirname) as entries:
for entry in entries:
if entry.name.endswith("png"):
#print(entry.path)
img = imageio.imread(entry.path)
# resize
img = PIL.Image.fromarray(img).resize((64,64), resample=PIL.Image.BILINEAR)
# remove alpha and use white background
img2 = PIL.Image.new("RGB", img.size, "WHITE")
img2.paste(img, (0, 0), img)
img2 = numpy.array(img2)
hf.create_dataset(entry.name, data=img2, compression="gzip", compression_opts=9)
if (count%1000 == 0):
print(count, img2.shape)
count += 1
pass
pass
pass
@makeyourownalgorithmicart
Copy link
Author

converts images to hdf5, includes image resizing too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment