Skip to content

Commit

Permalink
New Version
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelinelala committed Oct 10, 2018
1 parent 42a60d3 commit d097bef
Show file tree
Hide file tree
Showing 207 changed files with 863 additions and 12,350 deletions.
Binary file modified .DS_Store
Binary file not shown.
51 changes: 20 additions & 31 deletions datasets/dataset_hf5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import torch.utils.data as data
import torch
from PIL import Image
from skimage.io import imread, imsave
import numpy as np
import random
Expand All @@ -9,10 +8,7 @@
import h5py
import sys
import os
sys.path.append('..')
from os.path import join
from skimage.transform import rotate
from skimage import img_as_float

#=================== Utils ===================#
def is_image_file(filename):
Expand All @@ -24,26 +20,21 @@ def is_image_file(filename):

class DataValSet(data.Dataset):
def __init__(self, root_dir):
# input_dir = join(root_val_dir, 'LR_Blur') #---------------Input path
#one input & two ground truths
#one input & ground truth
self.input_dir = join(root_dir, 'LR_Blur')
self.lr_deblur_dir = join(root_dir, 'LR')
self.sr_dir = join(root_dir, 'HR')

#Online Loading
self.input_names = [x for x in sorted(os.listdir(self.input_dir)) if is_image_file(x)]
self.lr_deblur_names = [x for x in sorted(os.listdir(self.lr_deblur_dir)) if is_image_file(x)]
self.hr_names = [x for x in sorted(os.listdir(self.sr_dir)) if is_image_file(x)]

def __len__(self):
return len(self.hr_names)

def __getitem__(self, index):
input = np.asarray(imread(join(self.input_dir, self.input_names[index])).transpose((2, 0, 1)), np.float32).copy() / 255
target_lr = np.asarray(imread(join(self.lr_deblur_dir, self.lr_deblur_names[index])).transpose((2, 0, 1)), np.float32).copy() /255
target = np.asarray(imread(join(self.sr_dir, self.hr_names[index])).transpose((2, 0, 1)), np.float32).copy() / 255

return input, target_lr, target, self.hr_names[index]
input = np.asarray(imread(join(self.input_dir, self.input_names[index])).transpose((2, 0, 1)), np.float32).copy() / 255
target = np.asarray(imread(join(self.sr_dir, self.hr_names[index])).transpose((2, 0, 1)), np.float32).copy() / 255
return input, target

#=================== Training ===================#

Expand All @@ -52,37 +43,35 @@ def __init__(self, h5py_file_path):
super(DataSet, self).__init__()
self.hdf5_file = h5py_file_path

self.file = h5py.File(self.hdf5_file, 'r')
self.file.keys()
self.inputs = np.array(self.file.get("data"))
self.deblurs = np.array(self.file.get("label_db"))
self.hrs = np.array(self.file.get("label"))
self.file = h5py.File(self.hdf5_file, 'r')
#self.file.keys()
self.inputs = self.file.get("data")
self.deblurs = self.file.get("label_db")
self.hrs = self.file.get("label")

def __len__(self):
return self.inputs.shape[0]

def __getitem__(self, index):
input_patch = self.inputs[index, :, :, :]
deblur_patch = self.deblurs[index, :, :, :]
hr_patch = self.hrs[index, :, :, :]
#print(index)
# numpy
input_patch = np.asarray(self.inputs[index, :, :, :], np.float32)
deblur_patch = np.asarray(self.deblurs[index, :, :, :], np.float32)
hr_patch = np.asarray(self.hrs[index, :, :, :], np.float32)
# randomly flip
if random.randint(0, 1) == 0:
input_patch = np.flip(input_patch, 1)
deblur_patch = np.flip(deblur_patch, 1)
hr_patch = np.flip(hr_patch, 1)
else:
input_patch = np.flip(input_patch, 2)
deblur_patch = np.flip(deblur_patch, 2)
hr_patch = np.flip(hr_patch, 2)
# randomly rotation
rotation_times = random.randint(0, 3)
input_patch = np.rot90(input_patch, rotation_times, (1, 2))
deblur_patch = np.rot90(deblur_patch, rotation_times, (1, 2))
hr_patch = np.rot90(hr_patch, rotation_times, (1, 2))
input_patch = np.rot90(input_patch, rotation_times, (1, 2))
deblur_patch = np.rot90(deblur_patch, rotation_times, (1, 2))
hr_patch = np.rot90(hr_patch, rotation_times, (1, 2))

return torch.from_numpy(np.asarray(input_patch, np.float32).copy()),\
torch.from_numpy(np.asarray(deblur_patch, np.float32).copy()),\
torch.from_numpy(np.asarray(hr_patch, np.float32).copy())
return input_patch.copy(),\
deblur_patch.copy(),\
hr_patch.copy()



Binary file modified evaluation/.DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion evaluation/delete_image.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
% http://xinyizhang.tech/bmvc2018
% https://github.com/jacquelinelala/GFN
%% deleting
path = '/4TB/datasets/LR-GOPRO/Validation_4x/Results';
function delete_image(folder)
path = fullfile(folder, 'Validation_4x/Results');
%path = fullfile(folder, 'Validation_4x/HR');
result_dir = dir(fullfile(path, '*GFN_4x.png'));
len = length(result_dir);

Expand Down
24 changes: 9 additions & 15 deletions evaluation/test_RGB.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
% Description:
% -testting RGB channels PSNR & SSIM
% -testting RGB channels PSNR.
%
% Input:
% - Validation/Results: some specific group images with limited endings.
% - Validation/HR
%
% Output:
% - PSNR Average PSNR
% - SSIM Average SSIM
%
% Citation:
% Gated Fusion Network for Joint Image Deblurring and Super-Resolution
% The British Machine Vision Conference(BMVC2018 oral)
% Xinyi Zhang, Hang Dong, Zhe Hu, Wei-Sheng Lai,?Fei Wang and?Ming-Hsuan Yang
% Xinyi Zhang, Hang Dong, Zhe Hu, Wei-Sheng Lai, Fei Wang and Ming-Hsuan Yang
% Thanks:
% Many thanks to Wei-Sheng Lai al. for LapSRN. In this project we use
% some codes from their project.
Expand All @@ -22,34 +22,28 @@
% https://github.com/jacquelinelala/GFN

%% testing
function test_RGB(folder)
addpath(genpath('utils'));
results_path = '/4TB/datasets/LR-GOPRO/Validation_4x/Results';
hr_path = '/4TB/datasets/LR-GOPRO/Validation_4x/HR';
results_path = fullfile(folder, 'Validation_4x/Results');
hr_path = fullfile(folder, 'Validation_4x/HR');

result_dir = dir(fullfile(results_path, '*GFN_4x.png'));
hr_dir = dir(fullfile(hr_path, '*.png'));
count = length(hr_dir);
PSNR = zeros(count, 1);
SSIM = zeros(count, 1);
IFC = zeros(count, 1);
ifc = 0;
scale = 4;


for i = 1 : count
fprintf("Calculating %s\n", hr_dir(i).name);
HR = imread(fullfile(hr_dir(i).folder, hr_dir(i).name));
Results = imread(fullfile(result_dir(i).folder, result_dir(i).name));
[PSNR(i), SSIM(i), IFC(i)] = evaluate_SR(HR, Results, scale, ifc);
[PSNR(i), IFC(i)] = evaluate_SR(HR, Results, scale, ifc);
end

PSNR(count + 1) = mean(PSNR(:));
SSIM(count + 1) = mean(SSIM(:));

fprintf("Average PSNR is %f\n", PSNR(count + 1));
fprintf("Average SSIM is %f\n", SSIM(count + 1));

PSNR_path = fullfile('/4TB/datasets/LR-GOPRO/Validation_4x', 'PSNR-GFN_4x_HR.txt');
SSIM_path = fullfile('/4TB/datasets/LR-GOPRO/Validation_4x', 'SSIM-GFN_4x_HR.txt');
PSNR_path = fullfile(folder, 'Validation_4x', 'PSNR-GFN_4x_HR.txt');
save_matrix(PSNR, PSNR_path);
save_matrix(SSIM, SSIM_path);

19 changes: 8 additions & 11 deletions evaluation/test_bicubic.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% -------------------------------------------------------------------------
% Description:
% Use bicubic to upscale the input, and evaluate the results in terms
% of PSNR and SSIM (RGB channel)
% of PSNR.
%
% Input:
% - Validation/LR_Blur : Blurry low-resolution input
Expand All @@ -11,7 +11,7 @@
% - Validation/Results: images using bicubic upscaling and formatting
% with 'Bic****.png' in Results directory
% - PSNR: Average PSNR
% - SSIM: Average SSIM
%
% Citation:
% Gated Fusion Network for Joint Image Deblurring and Super-Resolution
% The British Machine Vision Conference(BMVC2018 oral)
Expand All @@ -26,10 +26,11 @@
% https://github.com/jacquelinelala/GFN

%% testing
function test_bicubic(folder)
addpath(genpath('utils'));
lr_blur_path = '/4TB/datasets/LR-GOPRO/Validation_4x/LR_Blur';
hr_path = '/4TB/datasets/LR-GOPRO/Validation_4x/HR';
results_path = '/4TB/datasets/LR-GOPRO/Validation_4x/Results';
lr_blur_path = fullfile(folder, 'Validation_4x/LR_Blur');
hr_path = fullfile(folder, 'Validation_4x/HR');
results_path = fullfile(folder, 'Validation_4x/Results');
lr_blur_dir = dir(fullfile(lr_blur_path, '*.png'));
hr_dir = dir(fullfile(hr_path, '*.png'));
count = length(lr_blur_dir);
Expand All @@ -45,17 +46,13 @@
LR_Blur = im2double(imread(fullfile(lr_blur_dir(i).folder, lr_blur_dir(i).name)));
LR_Blur_Bic = imresize(LR_Blur, 4, 'bicubic');
imwrite(LR_Blur_Bic, fullfile(results_path, strcat(hr_dir(i).name(1:4), 'Bic.png')),'png');
[PSNR(i), SSIM(i), IFC(i)] = evaluate_SR(HR, LR_Blur_Bic, scale, ifc);
[PSNR(i), IFC(i)] = evaluate_SR(HR, LR_Blur_Bic, scale, ifc);
end

PSNR(count + 1) = mean(PSNR(:));
SSIM(count + 1) = mean(SSIM(:));

fprintf("Average PSNR is %f\n", PSNR(count + 1));
fprintf("Average SSIM is %f\n", SSIM(count + 1));

PSNR_path = fullfile('/4TB/datasets/LR-GOPRO/Validation_4x', 'PSNR-LRBlurBic_HR.txt');
SSIM_path = fullfile('/4TB/datasets/LR-GOPRO/Validation_4x', 'SSIM-LRBlurBic_HR.txt');
PSNR_path = fullfile(folder, 'Validation_4x', 'PSNR-LRBlurBic_HR.txt');
save_matrix(PSNR, PSNR_path);
save_matrix(SSIM, SSIM_path);

Binary file modified evaluation/utils/.DS_Store
Binary file not shown.
70 changes: 0 additions & 70 deletions evaluation/utils/IFC/distsub_est_M.m

This file was deleted.

Loading

0 comments on commit d097bef

Please sign in to comment.