def __getitem__(self, idx):
        #if self.use_npy:
        #    input = self.dsets['low'][idx]
        #    target = self.dsets['high'][idx]

        input = load_img(self.dsets['low'][idx])
        target = load_img(self.dsets['high'][idx])

        if len(input.shape) == 2:
            input = input.reshape(1, input.shape[0], input.shape[1])
            target = target.reshape(1, target.shape[0], target.shape[1])
        else:
            input = np.transpose(input, (2, 0, 1))
            target = np.transpose(target, (2, 0, 1))

        input = torch.from_numpy(input).type(torch.FloatTensor)
        target = torch.from_numpy(target).type(torch.FloatTensor)

        return input, target
Ejemplo n.º 2
0
def prepare_data(args):
    print("Preparing DIV2K dataset ...")
    h5file_path = "{}/DIV2K_np_test_{}.h5".format(args.h5file_dir, args.test_sigma)
    h5 = h5py.File(h5file_path, 'w')
    h_group = h5.create_group('h')
    l_group = h5.create_group('l')

    h_list = sorted(glob.glob(args.test_h + "*.png"))

    with tqdm(total=len(h_list)) as t:
        t.set_description("H & L")
        for i, path in enumerate(h_list):
            img = img2np(load_img(path))
            h_group.create_dataset(str(i), data=img)
            l_group.create_dataset(str(i), data=add_noise(img, float(args.test_sigma), train=False))
            t.update()

    h5.close()
    print("Prepare successfully")