I am trying to create a h5 file for storing a dataset for training a super resolution GAN. Where each training pair would be a Low resolution and a High resolution image. The dataset will contain the data in the following manner: [[LR1,HR1],[LR2,HR2],...[LRn,HRn]]. I have 256x256 RGB images for HR and 128x128 RGB for LR. I am a bit skeptical about the best way to store this in a h5 file and shall I scale the images by 255 before storing them in the h5 file?
I have wrote the following code to do so. Any help/suggestions would be highly appreciated.
import h5py
import numpy as np
import os
import cv2
import glob
def store_super_resolution_dataset_in_h5_file(path_to_LR,path_to_HR):
'''This function takes the files with the same name from LR and HR folders and stores the new dataset in h5 format'''
#create LR and HR image lists
LR_images = glob.glob(path_to_LR+'*.jpg')
HR_images = glob.glob(path_to_HR+'*.jpg')
#sort the lists
LR_images.sort()
HR_images.sort()
print('LR_images: ',LR_images)
print('HR_images: ',HR_images)
#create a h5 file
h5_file = h5py.File('super_resolution_dataset.h5','w')
#create a dataset in the h5 file
dataset = h5_file.create_dataset('super_resolution_dataset',(len(LR_images),2,256,256),dtype='f')
#store the images in the dataset
for i in range(len(LR_images)):
LR_image = cv2.imread(LR_images[i])
HR_image = cv2.imread(HR_images[i])
dataset[i,0,:,:] = LR_image
dataset[i,1,:,:] = HR_image
#close the h5 file
h5_file.close()