SFM icon indicating copy to clipboard operation
SFM copied to clipboard

About the SR data

Open sibangde opened this issue 4 years ago • 1 comments

Could you please explain how to prepare the datasets for SR? I found you use h5py and the input channel for RCAN is 1 channel but not rgb images

sibangde avatar Nov 06 '20 02:11 sibangde

For the h5f you can check the code from our other project here https://github.com/IVRL/w2s/blob/master/code/generate_h5f.ipynb The code below should help you out for the data preparation, of course you first need to download the DIV2K dataset (or if you are using a different one then modify the imglist definition below).

import cv2
import os
import h5py
import numpy as np

# <use the same HDF5Store class as the one in the IVRL/W2S project>

# parameters for H5 file
patch_size = 64 
channel = 3
h5_file = './dataset/cnn_kh.h5'

if os.path.isfile(h5_file):
    os.remove(h5_file)

patch_shape = (patch_size, patch_size, channel)
hdf5_hr = HDF5Store(datapath=h5_file, dataset='hr', shape=patch_shape)

# get HR images
imglist = glob.glob('./dataset/DIV2K_train_HR/*.png')
num_patches = 0
for img in imglist:
    origin_img = cv2.imread(img)
    i = 0
    (h, w, _) = np.shape(origin_img)
    while ((i + patch_size < h)):
        j = 0
        while(j + patch_size < w):
            patch = origin_img[i:i+patch_size, j:j+patch_size, :]
            j = j + stride
            
            hdf5_hr.append(patch)
            num_patches = num_patches + 1
            if (num_patches % 50000 == 0):
                print('%d patches generated' %(num_patches))
        i = i + stride

print('%d patches generated in %s'%(num_patches, h5_file))

majedelhelou avatar Nov 11 '20 13:11 majedelhelou