├── FastFourierFiveK ├── create_txt.py ├── data │ ├── SIEN_dataset.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_dataset.cpython-38.pyc │ │ └── __init__.cpython-38.pyc │ ├── groups_test_FiveK.txt │ ├── groups_train_FiveK.txt │ ├── shuffle.py │ └── util.py ├── eval.py ├── eval_test.py ├── metrics │ ├── __pycache__ │ │ └── calculate_PSNR_SSIM.cpython-38.pyc │ ├── calculate_PSNR_SSIM.m │ └── calculate_PSNR_SSIM.py ├── models │ ├── SIEN_model.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_model.cpython-38.pyc │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── base_model.cpython-38.pyc │ │ ├── loss.cpython-38.pyc │ │ ├── loss_new.cpython-38.pyc │ │ ├── lr_scheduler.cpython-38.pyc │ │ └── networks.cpython-38.pyc │ ├── archs │ │ ├── EnhanceN_arch.py │ │ ├── EnhanceN_arch1.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── EDVR_arch.cpython-35.pyc │ │ │ ├── EDVR_arch.cpython-36.pyc │ │ │ ├── EnhanceN_arch.cpython-35.pyc │ │ │ ├── EnhanceN_arch.cpython-38.pyc │ │ │ ├── EnhanceN_arch1.cpython-38.pyc │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── arch_util.cpython-35.pyc │ │ │ ├── arch_util.cpython-36.pyc │ │ │ ├── arch_util.cpython-38.pyc │ │ │ ├── discriminator_vgg_arch.cpython-36.pyc │ │ │ └── discriminator_vgg_arch.cpython-38.pyc │ │ ├── arch_util.py │ │ └── discriminator_vgg_arch.py │ ├── base_model.py │ ├── loss.py │ ├── loss_new.py │ ├── lr_scheduler.py │ └── networks.py ├── options │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── options.cpython-38.pyc │ ├── options.py │ ├── test │ │ ├── test_ESRGAN.yml │ │ ├── test_SRGAN.yml │ │ └── test_SRResNet.yml │ └── train │ │ ├── train_Enhance.yml │ │ └── train_Enhance1.yml ├── pretrain │ └── 0_bestavg.pth ├── test.py ├── train.py ├── train1.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ └── util.cpython-38.pyc │ └── util.py ├── FastFourierLOL ├── create_txt.py ├── data │ ├── SIEN_dataset.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_dataset.cpython-38.pyc │ │ └── __init__.cpython-38.pyc │ ├── groups_test_LOL.txt │ ├── groups_train_LOL.txt │ ├── shuffle.py │ └── util.py ├── eval.py ├── eval_test.py ├── metrics │ ├── __pycache__ │ │ └── calculate_PSNR_SSIM.cpython-38.pyc │ ├── calculate_PSNR_SSIM.m │ └── calculate_PSNR_SSIM.py ├── models │ ├── SIEN_model.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_model.cpython-38.pyc │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── base_model.cpython-38.pyc │ │ ├── loss.cpython-38.pyc │ │ ├── loss_new.cpython-38.pyc │ │ ├── lr_scheduler.cpython-38.pyc │ │ └── networks.cpython-38.pyc │ ├── archs │ │ ├── EnhanceN_arch.py │ │ ├── EnhanceN_arch1.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── EDVR_arch.cpython-35.pyc │ │ │ ├── EDVR_arch.cpython-36.pyc │ │ │ ├── EnhanceN_arch.cpython-35.pyc │ │ │ ├── EnhanceN_arch.cpython-38.pyc │ │ │ ├── EnhanceN_arch1.cpython-38.pyc │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── arch_util.cpython-35.pyc │ │ │ ├── arch_util.cpython-36.pyc │ │ │ ├── arch_util.cpython-38.pyc │ │ │ ├── discriminator_vgg_arch.cpython-36.pyc │ │ │ └── discriminator_vgg_arch.cpython-38.pyc │ │ ├── arch_util.py │ │ └── discriminator_vgg_arch.py │ ├── base_model.py │ ├── loss.py │ ├── loss_new.py │ ├── lr_scheduler.py │ └── networks.py ├── options │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── options.cpython-38.pyc │ ├── options.py │ ├── test │ │ ├── test_ESRGAN.yml │ │ ├── test_SRGAN.yml │ │ └── test_SRResNet.yml │ └── train │ │ ├── train_Enhance.yml │ │ └── train_Enhance1.yml ├── pretrain │ └── 0_bestavg.pth ├── test.py ├── train.py ├── train1.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ └── util.cpython-38.pyc │ └── util.py ├── FastFourierMSEC ├── create_txt.py ├── data │ ├── SIEN_dataset.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_dataset.cpython-38.pyc │ │ └── __init__.cpython-38.pyc │ ├── groups_test_mixexposure.txt │ ├── groups_train_mixexposure.txt │ ├── groups_valid_mixexposure.txt │ ├── shuffle.py │ └── util.py ├── eval.py ├── eval_test.py ├── metrics │ ├── __pycache__ │ │ └── calculate_PSNR_SSIM.cpython-38.pyc │ ├── calculate_PSNR_SSIM.m │ └── calculate_PSNR_SSIM.py ├── models │ ├── SIEN_model.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_model.cpython-38.pyc │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── base_model.cpython-38.pyc │ │ ├── loss.cpython-38.pyc │ │ ├── loss_new.cpython-38.pyc │ │ ├── lr_scheduler.cpython-38.pyc │ │ └── networks.cpython-38.pyc │ ├── archs │ │ ├── EnhanceN_arch.py │ │ ├── EnhanceN_arch1.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── EDVR_arch.cpython-35.pyc │ │ │ ├── EDVR_arch.cpython-36.pyc │ │ │ ├── EnhanceN_arch.cpython-35.pyc │ │ │ ├── EnhanceN_arch.cpython-38.pyc │ │ │ ├── EnhanceN_arch1.cpython-38.pyc │ │ │ ├── EnhanceN_arch2.cpython-38.pyc │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── arch_util.cpython-35.pyc │ │ │ ├── arch_util.cpython-36.pyc │ │ │ ├── arch_util.cpython-38.pyc │ │ │ ├── arch_util1.cpython-35.pyc │ │ │ ├── discriminator_vgg_arch.cpython-36.pyc │ │ │ ├── discriminator_vgg_arch.cpython-38.pyc │ │ │ └── layer.cpython-35.pyc │ │ ├── arch_util.py │ │ ├── arch_util1.py │ │ ├── discriminator_vgg_arch.py │ │ └── layer.py │ ├── base_model.py │ ├── loss.py │ ├── loss_new.py │ ├── lr_scheduler.py │ └── networks.py ├── options │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── options.cpython-38.pyc │ ├── options.py │ ├── test │ │ ├── test_ESRGAN.yml │ │ ├── test_SRGAN.yml │ │ └── test_SRResNet.yml │ └── train │ │ ├── train_Enhance.yml │ │ ├── train_Enhance1.yml │ │ └── train_Enhance2.yml ├── pretrain │ └── 0_bestavg.pth ├── scripts │ └── back_projection │ │ ├── backprojection.m │ │ ├── main_bp.m │ │ └── main_reverse_filter.m ├── test.py ├── train.py ├── train1.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ └── util.cpython-38.pyc │ └── util.py ├── FastFourierSICE ├── create_txt.py ├── data │ ├── SIEN_dataset.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_dataset.cpython-38.pyc │ │ └── __init__.cpython-38.pyc │ ├── groups_test_mixSICEV2.txt │ ├── groups_train_mixSICEV2.txt │ ├── shuffle.py │ └── util.py ├── eval.py ├── eval_test.py ├── metrics │ ├── __pycache__ │ │ └── calculate_PSNR_SSIM.cpython-38.pyc │ ├── calculate_PSNR_SSIM.m │ └── calculate_PSNR_SSIM.py ├── models │ ├── SIEN_model.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── SIEN_model.cpython-38.pyc │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── base_model.cpython-38.pyc │ │ ├── loss.cpython-38.pyc │ │ ├── loss_new.cpython-38.pyc │ │ ├── lr_scheduler.cpython-38.pyc │ │ └── networks.cpython-38.pyc │ ├── archs │ │ ├── EnhanceN_arch.py │ │ ├── EnhanceN_arch1.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── EDVR_arch.cpython-35.pyc │ │ │ ├── EDVR_arch.cpython-36.pyc │ │ │ ├── EnhanceN_arch.cpython-35.pyc │ │ │ ├── EnhanceN_arch.cpython-38.pyc │ │ │ ├── EnhanceN_arch1.cpython-38.pyc │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── arch_util.cpython-35.pyc │ │ │ ├── arch_util.cpython-36.pyc │ │ │ ├── arch_util.cpython-38.pyc │ │ │ ├── discriminator_vgg_arch.cpython-36.pyc │ │ │ └── discriminator_vgg_arch.cpython-38.pyc │ │ ├── arch_util.py │ │ └── discriminator_vgg_arch.py │ ├── base_model.py │ ├── loss.py │ ├── loss_new.py │ ├── lr_scheduler.py │ └── networks.py ├── options │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── options.cpython-38.pyc │ ├── options.py │ ├── test │ │ ├── test_ESRGAN.yml │ │ ├── test_SRGAN.yml │ │ └── test_SRResNet.yml │ └── train │ │ ├── train_Enhance.yml │ │ └── train_Enhance1.yml ├── pretrain │ └── 0_bestavg.pth ├── test.py ├── train.py ├── train1.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ └── util.cpython-38.pyc │ └── util.py └── Readme.md /FastFourierFiveK/create_txt.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | 4 | 5 | def mkdir(path): 6 | if not os.path.exists(path): 7 | os.mkdir(path) 8 | 9 | 10 | def main(): 11 | assert os.path.exists(inputdir), 'Input dir not found' 12 | assert os.path.exists(targetdir), 'target dir not found' 13 | mkdir(outputdir) 14 | imgs = os.listdir(inputdir) 15 | for img in imgs: 16 | groups = '' 17 | 18 | groups += os.path.join(inputdir, img) + '|' 19 | groups += os.path.join(targetdir,img) 20 | 21 | with open(os.path.join(outputdir, 'groups_test_lowReFive.txt'), 'a') as f: 22 | f.write(groups + '\n') 23 | 24 | if __name__ == '__main__': 25 | parser = argparse.ArgumentParser() 26 | parser.add_argument('--input', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Low', metavar='PATH', help='root dir to save low resolution images') 27 | parser.add_argument('--target', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Retouch', metavar='PATH', help='root dir to save high resolution images') 28 | parser.add_argument('--output', type=str, default='/ghome/huangjie/Continous/Baseline/', metavar='PATH', help='output dir to save group txt files') 29 | parser.add_argument('--ext', type=str, default='.png', help='Extension of files') 30 | args = parser.parse_args() 31 | 32 | inputdir = args.input 33 | targetdir = args.target 34 | outputdir = args.output 35 | ext = args.ext 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /FastFourierFiveK/data/__init__.py: -------------------------------------------------------------------------------- 1 | """create dataset and dataloader""" 2 | import logging 3 | import torch 4 | import torch.utils.data 5 | 6 | 7 | def create_dataloader(dataset, dataset_opt, opt=None, sampler=None): 8 | phase = dataset_opt['phase'] 9 | if phase == 'train': 10 | num_workers = dataset_opt['n_workers'] * len(opt['gpu_ids']) 11 | batch_size = dataset_opt['batch_size'] 12 | # shuffle = True 13 | shuffle = dataset_opt['use_shuffle'] 14 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, 15 | num_workers=0, sampler=sampler, 16 | pin_memory=True) 17 | else: 18 | batch_size = dataset_opt['batch_size'] 19 | # shuffle = dataset_opt['use_shuffle'] 20 | shuffle = False 21 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=0, 22 | pin_memory=False) 23 | 24 | 25 | def create_dataset(opt,dataset_opt): 26 | mode = dataset_opt['mode'] 27 | # datasets for image restoration 28 | if mode == 'UEN_train': 29 | from data.SIEN_dataset import DatasetFromFolder as D 30 | 31 | dataset = D(upscale_factor=opt['scale'], data_augmentation=dataset_opt['augment'], 32 | group_file=dataset_opt['filelist'], 33 | patch_size=dataset_opt['IN_size'], black_edges_crop=False, hflip=True, rot=True) 34 | 35 | elif mode == 'UEN_val': 36 | from data.SIEN_dataset import DatasetFromFolder as D 37 | dataset = D(upscale_factor=opt['scale'], data_augmentation=False, 38 | group_file=dataset_opt['filelist'], 39 | patch_size=None, black_edges_crop=False, hflip=False, rot=False) 40 | 41 | else: 42 | raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode)) 43 | 44 | 45 | logger = logging.getLogger('base') 46 | logger.info('Dataset [{:s} - {:s}] is created.'.format(dataset.__class__.__name__, 47 | dataset_opt['name'])) 48 | return dataset 49 | -------------------------------------------------------------------------------- /FastFourierFiveK/data/__pycache__/SIEN_dataset.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/data/__pycache__/SIEN_dataset.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/data/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/data/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/data/shuffle.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | out = open("/ghome/huangjie/Continous/Baseline/groups_train_mixReFive.txt",'w') 4 | lines=[] 5 | with open("/ghome/huangjie/Continous/Baseline/mix.txt", 'r') as infile: 6 | for line in infile: 7 | lines.append(line) 8 | random.shuffle(lines) 9 | for line in lines: 10 | out.write(line) 11 | 12 | infile.close() 13 | out.close() 14 | 15 | -------------------------------------------------------------------------------- /FastFourierFiveK/eval.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test Vid4 (SR) and REDS4 (SR-clean, SR-blur, deblur-clean, deblur-compression) datasets 3 | ''' 4 | import os 5 | import os.path as osp 6 | import glob 7 | import logging 8 | import numpy as np 9 | import cv2 10 | import torch 11 | import argparse 12 | import utils.util as util 13 | import data.util as data_util 14 | import models.archs.EnhanceN_arch as EnhanceN_arch 15 | 16 | def dataload_test(img_path): 17 | img_numpy = cv2.imread(img_path,cv2.IMREAD_UNCHANGED).astype(np.float32)/255.0 18 | # img_numpy = cv2.resize(img_numpy,(512,512)) 19 | img_numpy = img_numpy[:, :, [2, 1, 0]] 20 | img_numpy = torch.from_numpy(np.ascontiguousarray(np.transpose(img_numpy, (2, 0, 1)))).float() 21 | img_numpy = img_numpy.unsqueeze(0) 22 | return img_numpy 23 | 24 | 25 | def forward_eval(model,img): 26 | with torch.no_grad(): 27 | model_output = model(img,torch.cuda.FloatTensor().resize_(1).zero_()+1, 28 | torch.cuda.FloatTensor().resize_(1).zero_()+1) 29 | # if isinstance(model_output, list) or isinstance(model_output, tuple): 30 | output = model_output 31 | # else: 32 | # output = model_output 33 | output = output.data.float().cpu() 34 | 35 | return output 36 | 37 | 38 | def main(root, save_folder, imageLists, modelPath): 39 | ################# 40 | # configurations 41 | ################# 42 | device = torch.device('cuda') 43 | os.environ['CUDA_VISIBLE_DEVICES'] = '0' 44 | ############################################################################ 45 | #### model 46 | model_path = modelPath 47 | model = EnhanceN_arch.Net() 48 | 49 | #### dataset 50 | test_dataset_folder = root 51 | save_imgs = True 52 | util.mkdirs(save_folder) 53 | # util.setup_logger('base', save_folder, 'test', level=logging.INFO, screen=True, tofile=True) 54 | # logger = logging.getLogger('base') 55 | 56 | #### set up the models 57 | model.load_state_dict(torch.load(model_path), strict=True) 58 | print("load model successfully") 59 | model.eval() 60 | model = model.to(device) 61 | 62 | image_filenames = [line.rstrip() for line in open(os.path.join(imageLists))] 63 | 64 | # process each image 65 | j = 0 66 | for img_idx in range(len(image_filenames)): 67 | 68 | img_name = os.path.basename(image_filenames[img_idx]) 69 | img = dataload_test(image_filenames[img_idx]).to(device) 70 | folder = image_filenames[img_idx].split('/')[-2] 71 | util.mkdirs(os.path.join(save_folder,folder)) 72 | # if img_right.shape[3] < 1000: 73 | # continue 74 | # for tx in range(2): 75 | # img_left = img_left_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_left_ori.shape[3])] 76 | # img_right = img_right_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_right_ori.shape[3])] 77 | 78 | output = forward_eval(model,img) 79 | output = util.tensor2img(output.squeeze(0)) 80 | 81 | if save_imgs: 82 | 83 | cv2.imwrite(osp.join(save_folder,folder,img_name), output) 84 | 85 | 86 | j = j + 1 87 | print("process %d th image" % j) 88 | 89 | print('################ Finish Testing ################') 90 | 91 | 92 | 93 | if __name__ == '__main__': 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('--root', type=str, default='/data/1760921465/NTIRE2021/SR/test_input/', metavar='PATH', help='validation dataset root dir') 96 | parser.add_argument('--imageLists', type=str, default='/code/UEN/data/srtest_input.txt', metavar='FILE', help='record video ids') 97 | parser.add_argument('--save_folder', type=str, default='/data/1760921465/NTIRE2021/SR/GFN_test', metavar='PATH', help='save results') 98 | parser.add_argument('--modelPath', type=str, default='/model/1760921465/NTIRE2021/SR/GFN.pth', help='Model path') 99 | 100 | args = parser.parse_args() 101 | 102 | root = args.root 103 | imageLists = args.imageLists 104 | save_folder = args.save_folder 105 | modelPath = args.modelPath 106 | 107 | main(root, save_folder, imageLists, modelPath) 108 | -------------------------------------------------------------------------------- /FastFourierFiveK/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | logger = logging.getLogger('base') 3 | 4 | 5 | def create_model(opt): 6 | # image restoration 7 | model = opt['model'] 8 | if model == 'sr': 9 | from .SIEN_model import SIEN_Model as M 10 | else: 11 | raise NotImplementedError('Model [{:s}] not recognized.'.format(model)) 12 | m = M(opt) 13 | logger.info('Model [{:s}] is created.'.format(m.__class__.__name__)) 14 | return m 15 | 16 | -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/SIEN_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/SIEN_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/base_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/base_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/loss.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/loss.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/loss_new.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/loss_new.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/lr_scheduler.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/lr_scheduler.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/__pycache__/networks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/__pycache__/networks.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__init__.py -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/EDVR_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/EDVR_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/EDVR_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/EDVR_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/arch_util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/arch_util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Adobe Inc. All rights reserved. 2 | # 3 | # This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4 | # 4.0 International Public License. To view a copy of this license, visit 5 | # https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode. 6 | 7 | 8 | 9 | ######## https://github.com/adobe/antialiased-cnns/blob/master/models_lpf/__init__.py 10 | 11 | 12 | 13 | import torch 14 | import torch.nn.parallel 15 | import numpy as np 16 | import torch.nn as nn 17 | import torch.nn.functional as F 18 | 19 | class Downsample(nn.Module): 20 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 21 | super(Downsample, self).__init__() 22 | self.filt_size = filt_size 23 | self.pad_off = pad_off 24 | self.pad_sizes = [int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2)), int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2))] 25 | self.pad_sizes = [pad_size+pad_off for pad_size in self.pad_sizes] 26 | self.stride = stride 27 | self.off = int((self.stride-1)/2.) 28 | self.channels = channels 29 | 30 | # print('Filter size [%i]'%filt_size) 31 | if(self.filt_size==1): 32 | a = np.array([1.,]) 33 | elif(self.filt_size==2): 34 | a = np.array([1., 1.]) 35 | elif(self.filt_size==3): 36 | a = np.array([1., 2., 1.]) 37 | elif(self.filt_size==4): 38 | a = np.array([1., 3., 3., 1.]) 39 | elif(self.filt_size==5): 40 | a = np.array([1., 4., 6., 4., 1.]) 41 | elif(self.filt_size==6): 42 | a = np.array([1., 5., 10., 10., 5., 1.]) 43 | elif(self.filt_size==7): 44 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 45 | 46 | filt = torch.Tensor(a[:,None]*a[None,:]) 47 | filt = filt/torch.sum(filt) 48 | self.register_buffer('filt', filt[None,None,:,:].repeat((self.channels,1,1,1))) 49 | 50 | self.pad = get_pad_layer(pad_type)(self.pad_sizes) 51 | 52 | def forward(self, inp): 53 | if(self.filt_size==1): 54 | if(self.pad_off==0): 55 | return inp[:,:,::self.stride,::self.stride] 56 | else: 57 | return self.pad(inp)[:,:,::self.stride,::self.stride] 58 | else: 59 | return F.conv2d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 60 | 61 | def get_pad_layer(pad_type): 62 | if(pad_type in ['refl','reflect']): 63 | PadLayer = nn.ReflectionPad2d 64 | elif(pad_type in ['repl','replicate']): 65 | PadLayer = nn.ReplicationPad2d 66 | elif(pad_type=='zero'): 67 | PadLayer = nn.ZeroPad2d 68 | else: 69 | print('Pad type [%s] not recognized'%pad_type) 70 | return PadLayer 71 | 72 | 73 | class Downsample1D(nn.Module): 74 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 75 | super(Downsample1D, self).__init__() 76 | self.filt_size = filt_size 77 | self.pad_off = pad_off 78 | self.pad_sizes = [int(1. * (filt_size - 1) / 2), int(np.ceil(1. * (filt_size - 1) / 2))] 79 | self.pad_sizes = [pad_size + pad_off for pad_size in self.pad_sizes] 80 | self.stride = stride 81 | self.off = int((self.stride - 1) / 2.) 82 | self.channels = channels 83 | 84 | # print('Filter size [%i]' % filt_size) 85 | if(self.filt_size == 1): 86 | a = np.array([1., ]) 87 | elif(self.filt_size == 2): 88 | a = np.array([1., 1.]) 89 | elif(self.filt_size == 3): 90 | a = np.array([1., 2., 1.]) 91 | elif(self.filt_size == 4): 92 | a = np.array([1., 3., 3., 1.]) 93 | elif(self.filt_size == 5): 94 | a = np.array([1., 4., 6., 4., 1.]) 95 | elif(self.filt_size == 6): 96 | a = np.array([1., 5., 10., 10., 5., 1.]) 97 | elif(self.filt_size == 7): 98 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 99 | 100 | filt = torch.Tensor(a) 101 | filt = filt / torch.sum(filt) 102 | self.register_buffer('filt', filt[None, None, :].repeat((self.channels, 1, 1))) 103 | 104 | self.pad = get_pad_layer_1d(pad_type)(self.pad_sizes) 105 | 106 | def forward(self, inp): 107 | if(self.filt_size == 1): 108 | if(self.pad_off == 0): 109 | return inp[:, :, ::self.stride] 110 | else: 111 | return self.pad(inp)[:, :, ::self.stride] 112 | else: 113 | return F.conv1d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 114 | 115 | 116 | def get_pad_layer_1d(pad_type): 117 | if(pad_type in ['refl', 'reflect']): 118 | PadLayer = nn.ReflectionPad1d 119 | elif(pad_type in ['repl', 'replicate']): 120 | PadLayer = nn.ReplicationPad1d 121 | elif(pad_type == 'zero'): 122 | PadLayer = nn.ZeroPad1d 123 | else: 124 | print('Pad type [%s] not recognized' % pad_type) 125 | return PadLayer -------------------------------------------------------------------------------- /FastFourierFiveK/models/archs/discriminator_vgg_arch.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torchvision 4 | 5 | 6 | class Discriminator_VGG_128(nn.Module): 7 | def __init__(self, in_nc, nf): 8 | super(Discriminator_VGG_128, self).__init__() 9 | # [64, 128, 128] 10 | self.conv0_0 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True) 11 | self.conv0_1 = nn.Conv2d(nf, nf, 4, 2, 1, bias=False) 12 | self.bn0_1 = nn.BatchNorm2d(nf, affine=True) 13 | # [64, 64, 64] 14 | self.conv1_0 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=False) 15 | self.bn1_0 = nn.BatchNorm2d(nf * 2, affine=True) 16 | self.conv1_1 = nn.Conv2d(nf * 2, nf * 2, 4, 2, 1, bias=False) 17 | self.bn1_1 = nn.BatchNorm2d(nf * 2, affine=True) 18 | # [128, 32, 32] 19 | self.conv2_0 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=False) 20 | self.bn2_0 = nn.BatchNorm2d(nf * 4, affine=True) 21 | self.conv2_1 = nn.Conv2d(nf * 4, nf * 4, 4, 2, 1, bias=False) 22 | self.bn2_1 = nn.BatchNorm2d(nf * 4, affine=True) 23 | # [256, 16, 16] 24 | self.conv3_0 = nn.Conv2d(nf * 4, nf * 8, 3, 1, 1, bias=False) 25 | self.bn3_0 = nn.BatchNorm2d(nf * 8, affine=True) 26 | self.conv3_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 27 | self.bn3_1 = nn.BatchNorm2d(nf * 8, affine=True) 28 | # [512, 8, 8] 29 | self.conv4_0 = nn.Conv2d(nf * 8, nf * 8, 3, 1, 1, bias=False) 30 | self.bn4_0 = nn.BatchNorm2d(nf * 8, affine=True) 31 | self.conv4_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 32 | self.bn4_1 = nn.BatchNorm2d(nf * 8, affine=True) 33 | 34 | self.linear1 = nn.Linear(512 * 4 * 4, 100) 35 | self.linear2 = nn.Linear(100, 1) 36 | 37 | # activation function 38 | self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) 39 | 40 | def forward(self, x): 41 | fea = self.lrelu(self.conv0_0(x)) 42 | fea = self.lrelu(self.bn0_1(self.conv0_1(fea))) 43 | 44 | fea = self.lrelu(self.bn1_0(self.conv1_0(fea))) 45 | fea = self.lrelu(self.bn1_1(self.conv1_1(fea))) 46 | 47 | fea = self.lrelu(self.bn2_0(self.conv2_0(fea))) 48 | fea = self.lrelu(self.bn2_1(self.conv2_1(fea))) 49 | 50 | fea = self.lrelu(self.bn3_0(self.conv3_0(fea))) 51 | fea = self.lrelu(self.bn3_1(self.conv3_1(fea))) 52 | 53 | fea = self.lrelu(self.bn4_0(self.conv4_0(fea))) 54 | fea = self.lrelu(self.bn4_1(self.conv4_1(fea))) 55 | 56 | fea = fea.view(fea.size(0), -1) 57 | fea = self.lrelu(self.linear1(fea)) 58 | out = self.linear2(fea) 59 | return out 60 | 61 | 62 | class VGGFeatureExtractor(nn.Module): 63 | def __init__(self, feature_layer=34, use_bn=False, use_input_norm=True, 64 | device=torch.device('cpu')): 65 | super(VGGFeatureExtractor, self).__init__() 66 | self.use_input_norm = use_input_norm 67 | if use_bn: 68 | model = torchvision.models.vgg19_bn(pretrained=True) 69 | else: 70 | model = torchvision.models.vgg19(pretrained=True) 71 | if self.use_input_norm: 72 | mean = torch.Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1).to(device) 73 | # [0.485 - 1, 0.456 - 1, 0.406 - 1] if input in range [-1, 1] 74 | std = torch.Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1).to(device) 75 | # [0.229 * 2, 0.224 * 2, 0.225 * 2] if input in range [-1, 1] 76 | self.register_buffer('mean', mean) 77 | self.register_buffer('std', std) 78 | self.features = nn.Sequential(*list(model.features.children())[:(feature_layer + 1)]) 79 | # No need to BP to variable 80 | for k, v in self.features.named_parameters(): 81 | v.requires_grad = False 82 | 83 | def forward(self, x): 84 | # Assume input range is [0, 1] 85 | if self.use_input_norm: 86 | x = (x - self.mean) / self.std 87 | output = self.features(x) 88 | return output 89 | -------------------------------------------------------------------------------- /FastFourierFiveK/models/loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class CharbonnierLoss(nn.Module): 6 | """Charbonnier Loss (L1)""" 7 | 8 | def __init__(self, eps=1e-6): 9 | super(CharbonnierLoss, self).__init__() 10 | self.eps = eps 11 | 12 | def forward(self, x, y): 13 | diff = x - y 14 | loss = torch.sum(torch.sqrt(diff * diff + self.eps)) 15 | return loss 16 | 17 | 18 | # Define GAN loss: [vanilla | lsgan | wgan-gp] 19 | class GANLoss(nn.Module): 20 | def __init__(self, gan_type, real_label_val=1.0, fake_label_val=0.0): 21 | super(GANLoss, self).__init__() 22 | self.gan_type = gan_type.lower() 23 | self.real_label_val = real_label_val 24 | self.fake_label_val = fake_label_val 25 | 26 | if self.gan_type == 'gan' or self.gan_type == 'ragan': 27 | self.loss = nn.BCEWithLogitsLoss() 28 | elif self.gan_type == 'lsgan': 29 | self.loss = nn.MSELoss() 30 | elif self.gan_type == 'wgan-gp': 31 | 32 | def wgan_loss(input, target): 33 | # target is boolean 34 | return -1 * input.mean() if target else input.mean() 35 | 36 | self.loss = wgan_loss 37 | else: 38 | raise NotImplementedError('GAN type [{:s}] is not found'.format(self.gan_type)) 39 | 40 | def get_target_label(self, input, target_is_real): 41 | if self.gan_type == 'wgan-gp': 42 | return target_is_real 43 | if target_is_real: 44 | return torch.empty_like(input).fill_(self.real_label_val) 45 | else: 46 | return torch.empty_like(input).fill_(self.fake_label_val) 47 | 48 | def forward(self, input, target_is_real): 49 | target_label = self.get_target_label(input, target_is_real) 50 | loss = self.loss(input, target_label) 51 | return loss 52 | 53 | 54 | class GradientPenaltyLoss(nn.Module): 55 | def __init__(self, device=torch.device('cpu')): 56 | super(GradientPenaltyLoss, self).__init__() 57 | self.register_buffer('grad_outputs', torch.Tensor()) 58 | self.grad_outputs = self.grad_outputs.to(device) 59 | 60 | def get_grad_outputs(self, input): 61 | if self.grad_outputs.size() != input.size(): 62 | self.grad_outputs.resize_(input.size()).fill_(1.0) 63 | return self.grad_outputs 64 | 65 | def forward(self, interp, interp_crit): 66 | grad_outputs = self.get_grad_outputs(interp_crit) 67 | grad_interp = torch.autograd.grad(outputs=interp_crit, inputs=interp, 68 | grad_outputs=grad_outputs, create_graph=True, 69 | retain_graph=True, only_inputs=True)[0] 70 | grad_interp = grad_interp.view(grad_interp.size(0), -1) 71 | grad_interp_norm = grad_interp.norm(2, dim=1) 72 | 73 | loss = ((grad_interp_norm - 1)**2).mean() 74 | return loss 75 | 76 | 77 | class AMPLoss(nn.Module): 78 | def __init__(self): 79 | super(AMPLoss, self).__init__() 80 | self.cri = nn.L1Loss() 81 | 82 | def forward(self, x, y): 83 | x = torch.fft.rfft2(x, norm='backward') 84 | x_mag = torch.abs(x) 85 | y = torch.fft.rfft2(y, norm='backward') 86 | y_mag = torch.abs(y) 87 | 88 | return self.cri(x_mag,y_mag) 89 | 90 | 91 | class PhaLoss(nn.Module): 92 | def __init__(self): 93 | super(PhaLoss, self).__init__() 94 | self.cri = nn.L1Loss() 95 | 96 | def forward(self, x, y): 97 | x = torch.fft.rfft2(x, norm='backward') 98 | x_mag = torch.angle(x) 99 | y = torch.fft.rfft2(y, norm='backward') 100 | y_mag = torch.angle(y) 101 | 102 | return self.cri(x_mag, y_mag) -------------------------------------------------------------------------------- /FastFourierFiveK/models/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import models.archs.discriminator_vgg_arch as SRGAN_arch 3 | import models.archs.EnhanceN_arch as EnhanceN_arch 4 | import models.archs.EnhanceN_arch1 as EnhanceN_arch1 5 | 6 | 7 | # Generator 8 | def define_G(opt): 9 | opt_net = opt['network_G'] 10 | which_model = opt_net['which_model_G'] 11 | 12 | # video restoration 13 | if which_model == 'Net': 14 | netG = EnhanceN_arch.InteractNet(nc=opt_net['nc']) 15 | elif which_model == 'Net1': 16 | netG = EnhanceN_arch1.InteractNet(nc=opt_net['nc']) 17 | else: 18 | raise NotImplementedError('Generator model [{:s}] not recognized'.format(which_model)) 19 | 20 | return netG 21 | 22 | 23 | # Discriminator 24 | def define_D(opt): 25 | opt_net = opt['network_D'] 26 | which_model = opt_net['which_model_D'] 27 | 28 | if which_model == 'discriminator_vgg_128': 29 | netD = SRGAN_arch.Discriminator_VGG_128(in_nc=opt_net['in_nc'], nf=opt_net['nf']) 30 | else: 31 | raise NotImplementedError('Discriminator model [{:s}] not recognized'.format(which_model)) 32 | return netD 33 | 34 | 35 | # Define network used for perceptual loss 36 | def define_F(opt, use_bn=False): 37 | gpu_ids = opt['gpu_ids'] 38 | device = torch.device('cuda' if gpu_ids else 'cpu') 39 | # PyTorch pretrained VGG19-54, before ReLU. 40 | if use_bn: 41 | feature_layer = 49 42 | else: 43 | feature_layer = 34 44 | netF = SRGAN_arch.VGGFeatureExtractor(feature_layer=feature_layer, use_bn=use_bn, 45 | use_input_norm=True, device=device) 46 | netF.eval() # No need to train 47 | return netF 48 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/options/__init__.py -------------------------------------------------------------------------------- /FastFourierFiveK/options/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/options/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/options/__pycache__/options.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/options/__pycache__/options.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/options/options.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as osp 3 | import logging 4 | import yaml 5 | from utils.util import OrderedYaml 6 | Loader, Dumper = OrderedYaml() 7 | 8 | 9 | def parse(opt_path, is_train=True): 10 | with open(opt_path, mode='r') as f: 11 | opt = yaml.load(f, Loader=Loader) 12 | # export CUDA_VISIBLE_DEVICES 13 | gpu_list = ','.join(str(x) for x in opt['gpu_ids']) 14 | os.environ['CUDA_VISIBLE_DEVICES'] = gpu_list 15 | print('export CUDA_VISIBLE_DEVICES=' + gpu_list) 16 | 17 | opt['is_train'] = is_train 18 | if opt['distortion'] == 'sr': 19 | scale = opt['scale'] 20 | 21 | # datasets 22 | for phase, dataset in opt['datasets'].items(): 23 | phase = phase.split('_')[0] 24 | dataset['phase'] = phase 25 | if opt['distortion'] == 'sr': 26 | dataset['scale'] = scale 27 | is_lmdb = False 28 | if dataset.get('dataroot_GT', None) is not None: 29 | dataset['dataroot_GT'] = osp.expanduser(dataset['dataroot_GT']) 30 | if dataset['dataroot_GT'].endswith('lmdb'): 31 | is_lmdb = True 32 | if dataset.get('dataroot_LQ', None) is not None: 33 | dataset['dataroot_LQ'] = osp.expanduser(dataset['dataroot_LQ']) 34 | if dataset['dataroot_LQ'].endswith('lmdb'): 35 | is_lmdb = True 36 | dataset['data_type'] = 'lmdb' if is_lmdb else 'img' 37 | if dataset['mode'].endswith('mc'): # for memcached 38 | dataset['data_type'] = 'mc' 39 | dataset['mode'] = dataset['mode'].replace('_mc', '') 40 | 41 | # path 42 | for key, path in opt['path'].items(): 43 | if path and key in opt['path'] and key != 'strict_load': 44 | opt['path'][key] = osp.expanduser(path) 45 | # opt['path']['root'] = '/home/zhanghc/IEEEyellow/code_enhance/checkpoints' 46 | if is_train: 47 | experiments_root = osp.join(opt['path']['root'], 'experiments', opt['name']) 48 | opt['path']['experiments_root'] = experiments_root 49 | opt['path']['models'] = osp.join(experiments_root, 'models') 50 | opt['path']['training_state'] = osp.join(experiments_root, 'training_state') 51 | opt['path']['log'] = experiments_root 52 | opt['path']['val_images'] = osp.join(experiments_root, 'val_images') 53 | 54 | # change some options for debug mode 55 | if 'debug' in opt['name']: 56 | opt['train']['val_freq'] = 8 57 | opt['logger']['print_freq'] = 1 58 | opt['logger']['save_checkpoint_freq'] = 8 59 | else: # test 60 | results_root = osp.join(opt['path']['root'], 'results', opt['name']) 61 | opt['path']['results_root'] = results_root 62 | opt['path']['log'] = results_root 63 | 64 | # network 65 | if opt['distortion'] == 'sr': 66 | opt['network_G']['scale'] = scale 67 | 68 | return opt 69 | 70 | 71 | def dict2str(opt, indent_l=1): 72 | '''dict to string for logger''' 73 | msg = '' 74 | for k, v in opt.items(): 75 | if isinstance(v, dict): 76 | msg += ' ' * (indent_l * 2) + k + ':[\n' 77 | msg += dict2str(v, indent_l + 1) 78 | msg += ' ' * (indent_l * 2) + ']\n' 79 | else: 80 | msg += ' ' * (indent_l * 2) + k + ': ' + str(v) + '\n' 81 | return msg 82 | 83 | 84 | class NoneDict(dict): 85 | def __missing__(self, key): 86 | return None 87 | 88 | 89 | # convert to NoneDict, which return None for missing key. 90 | def dict_to_nonedict(opt): 91 | if isinstance(opt, dict): 92 | new_opt = dict() 93 | for key, sub_opt in opt.items(): 94 | new_opt[key] = dict_to_nonedict(sub_opt) 95 | return NoneDict(**new_opt) 96 | elif isinstance(opt, list): 97 | return [dict_to_nonedict(sub_opt) for sub_opt in opt] 98 | else: 99 | return opt 100 | 101 | 102 | def check_resume(opt, resume_iter): 103 | '''Check resume states and pretrain_model paths''' 104 | logger = logging.getLogger('base') 105 | if opt['path']['resume_state']: 106 | if opt['path'].get('pretrain_model_G', None) is not None or opt['path'].get( 107 | 'pretrain_model_D', None) is not None: 108 | logger.warning('pretrain_model path will be ignored when resuming training.') 109 | 110 | opt['path']['pretrain_model_G'] = osp.join(opt['path']['models'], 111 | '{}_G.pth'.format(resume_iter)) 112 | logger.info('Set [pretrain_model_G] to ' + opt['path']['pretrain_model_G']) 113 | if 'gan' in opt['model']: 114 | opt['path']['pretrain_model_D'] = osp.join(opt['path']['models'], 115 | '{}_D.pth'.format(resume_iter)) 116 | logger.info('Set [pretrain_model_D] to ' + opt['path']['pretrain_model_D']) 117 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/test/test_ESRGAN.yml: -------------------------------------------------------------------------------- 1 | name: RRDB_ESRGAN_x4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: RRDBNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 23 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/RRDB_ESRGAN_x4.pth 33 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/test/test_SRGAN.yml: -------------------------------------------------------------------------------- 1 | name: MSRGANx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: MSRResNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 16 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/MSRGANx4.pth 33 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/test/test_SRResNet.yml: -------------------------------------------------------------------------------- 1 | name: MSRResNetx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | test_3: 21 | name: bsd100 22 | mode: LQGT 23 | dataroot_GT: ../datasets/BSD/BSDS100 24 | dataroot_LQ: ../datasets/BSD/BSDS100_bicLRx4 25 | test_4: 26 | name: urban100 27 | mode: LQGT 28 | dataroot_GT: ../datasets/urban100 29 | dataroot_LQ: ../datasets/urban100_bicLRx4 30 | test_5: 31 | name: div2k100 32 | mode: LQGT 33 | dataroot_GT: ../datasets/DIV2K100/DIV2K_valid_HR 34 | dataroot_LQ: ../datasets/DIV2K100/DIV2K_valid_bicLRx4 35 | 36 | 37 | #### network structures 38 | network_G: 39 | which_model_G: MSRResNet 40 | in_nc: 3 41 | out_nc: 3 42 | nf: 64 43 | nb: 16 44 | upscale: 4 45 | 46 | #### path 47 | path: 48 | pretrain_model_G: ../experiments/pretrained_models/MSRResNetx4.pth 49 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/train/train_Enhance.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [0] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier1/data/groups_train_FiveK.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 272 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier1/data/groups_test_FiveK.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourier1/output 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourier1/output 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourier1/pretrain 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourier1/SOTA_Final/models/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 1e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 160000 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [80000, 120000] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 20 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierFiveK/options/train/train_Enhance1.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [0] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier1/data/groups_train_FiveK.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 256 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier1/data/groups_test_FiveK.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net1 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourier1/output1 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourier1/output1 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourier1/pretrain1 49 | pretrain_model_G: ~ 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 4e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 50000 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [20000, 40000] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 20 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierFiveK/pretrain/0_bestavg.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/pretrain/0_bestavg.pth -------------------------------------------------------------------------------- /FastFourierFiveK/test.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import logging 3 | import time 4 | import argparse 5 | from collections import OrderedDict 6 | 7 | import options.options as option 8 | import utils.util as util 9 | from data.util import bgr2ycbcr 10 | from data import create_dataset, create_dataloader 11 | from models import create_model 12 | 13 | #### options 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('-opt', type=str, required=True, help='Path to options YMAL file.') 16 | opt = option.parse(parser.parse_args().opt, is_train=False) 17 | opt = option.dict_to_nonedict(opt) 18 | 19 | util.mkdirs( 20 | (path for key, path in opt['path'].items() 21 | if not key == 'experiments_root' and 'pretrain_model' not in key and 'resume' not in key)) 22 | util.setup_logger('base', opt['path']['log'], 'test_' + opt['name'], level=logging.INFO, 23 | screen=True, tofile=True) 24 | logger = logging.getLogger('base') 25 | logger.info(option.dict2str(opt)) 26 | 27 | #### Create test dataset and dataloader 28 | test_loaders = [] 29 | for phase, dataset_opt in sorted(opt['datasets'].items()): 30 | test_set = create_dataset(dataset_opt) 31 | test_loader = create_dataloader(test_set, dataset_opt) 32 | logger.info('Number of test images in [{:s}]: {:d}'.format(dataset_opt['name'], len(test_set))) 33 | test_loaders.append(test_loader) 34 | 35 | model = create_model(opt) 36 | for test_loader in test_loaders: 37 | test_set_name = test_loader.dataset.opt['name'] 38 | logger.info('\nTesting [{:s}]...'.format(test_set_name)) 39 | test_start_time = time.time() 40 | dataset_dir = osp.join(opt['path']['results_root'], test_set_name) 41 | util.mkdir(dataset_dir) 42 | 43 | test_results = OrderedDict() 44 | test_results['psnr'] = [] 45 | test_results['ssim'] = [] 46 | test_results['psnr_y'] = [] 47 | test_results['ssim_y'] = [] 48 | 49 | for data in test_loader: 50 | need_GT = False if test_loader.dataset.opt['dataroot_GT'] is None else True 51 | model.feed_data(data, need_GT=need_GT) 52 | img_path = data['GT_path'][0] if need_GT else data['LQ_path'][0] 53 | img_name = osp.splitext(osp.basename(img_path))[0] 54 | 55 | model.test() 56 | visuals = model.get_current_visuals(need_GT=need_GT) 57 | 58 | sr_img = util.tensor2img(visuals['rlt']) # uint8 59 | 60 | # save images 61 | suffix = opt['suffix'] 62 | if suffix: 63 | save_img_path = osp.join(dataset_dir, img_name + suffix + '.png') 64 | else: 65 | save_img_path = osp.join(dataset_dir, img_name + '.png') 66 | util.save_img(sr_img, save_img_path) 67 | 68 | # calculate PSNR and SSIM 69 | if need_GT: 70 | gt_img = util.tensor2img(visuals['GT']) 71 | sr_img, gt_img = util.crop_border([sr_img, gt_img], opt['scale']) 72 | psnr = util.calculate_psnr(sr_img, gt_img) 73 | ssim = util.calculate_ssim(sr_img, gt_img) 74 | test_results['psnr'].append(psnr) 75 | test_results['ssim'].append(ssim) 76 | 77 | if gt_img.shape[2] == 3: # RGB image 78 | sr_img_y = bgr2ycbcr(sr_img / 255., only_y=True) 79 | gt_img_y = bgr2ycbcr(gt_img / 255., only_y=True) 80 | 81 | psnr_y = util.calculate_psnr(sr_img_y * 255, gt_img_y * 255) 82 | ssim_y = util.calculate_ssim(sr_img_y * 255, gt_img_y * 255) 83 | test_results['psnr_y'].append(psnr_y) 84 | test_results['ssim_y'].append(ssim_y) 85 | logger.info( 86 | '{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}; PSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}.'. 87 | format(img_name, psnr, ssim, psnr_y, ssim_y)) 88 | else: 89 | logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}.'.format(img_name, psnr, ssim)) 90 | else: 91 | logger.info(img_name) 92 | 93 | if need_GT: # metrics 94 | # Average PSNR/SSIM results 95 | ave_psnr = sum(test_results['psnr']) / len(test_results['psnr']) 96 | ave_ssim = sum(test_results['ssim']) / len(test_results['ssim']) 97 | logger.info( 98 | '----Average PSNR/SSIM results for {}----\n\tPSNR: {:.6f} dB; SSIM: {:.6f}\n'.format( 99 | test_set_name, ave_psnr, ave_ssim)) 100 | if test_results['psnr_y'] and test_results['ssim_y']: 101 | ave_psnr_y = sum(test_results['psnr_y']) / len(test_results['psnr_y']) 102 | ave_ssim_y = sum(test_results['ssim_y']) / len(test_results['ssim_y']) 103 | logger.info( 104 | '----Y channel, average PSNR/SSIM----\n\tPSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}\n'. 105 | format(ave_psnr_y, ave_ssim_y)) 106 | -------------------------------------------------------------------------------- /FastFourierFiveK/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/utils/__init__.py -------------------------------------------------------------------------------- /FastFourierFiveK/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierFiveK/utils/__pycache__/util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierFiveK/utils/__pycache__/util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/create_txt.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | 4 | 5 | def mkdir(path): 6 | if not os.path.exists(path): 7 | os.mkdir(path) 8 | 9 | 10 | def main(): 11 | assert os.path.exists(inputdir), 'Input dir not found' 12 | assert os.path.exists(targetdir), 'target dir not found' 13 | mkdir(outputdir) 14 | imgs = os.listdir(inputdir) 15 | for img in imgs: 16 | groups = '' 17 | 18 | groups += os.path.join(inputdir, img) + '|' 19 | groups += os.path.join(targetdir,img) 20 | 21 | with open(os.path.join(outputdir, 'groups_test_lowReFive.txt'), 'a') as f: 22 | f.write(groups + '\n') 23 | 24 | if __name__ == '__main__': 25 | parser = argparse.ArgumentParser() 26 | parser.add_argument('--input', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Low', metavar='PATH', help='root dir to save low resolution images') 27 | parser.add_argument('--target', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Retouch', metavar='PATH', help='root dir to save high resolution images') 28 | parser.add_argument('--output', type=str, default='/ghome/huangjie/Continous/Baseline/', metavar='PATH', help='output dir to save group txt files') 29 | parser.add_argument('--ext', type=str, default='.png', help='Extension of files') 30 | args = parser.parse_args() 31 | 32 | inputdir = args.input 33 | targetdir = args.target 34 | outputdir = args.output 35 | ext = args.ext 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /FastFourierLOL/data/__init__.py: -------------------------------------------------------------------------------- 1 | """create dataset and dataloader""" 2 | import logging 3 | import torch 4 | import torch.utils.data 5 | 6 | 7 | def create_dataloader(dataset, dataset_opt, opt=None, sampler=None): 8 | phase = dataset_opt['phase'] 9 | if phase == 'train': 10 | num_workers = dataset_opt['n_workers'] * len(opt['gpu_ids']) 11 | batch_size = dataset_opt['batch_size'] 12 | # shuffle = True 13 | shuffle = dataset_opt['use_shuffle'] 14 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, 15 | num_workers=0, sampler=sampler, 16 | pin_memory=True) 17 | else: 18 | batch_size = dataset_opt['batch_size'] 19 | # shuffle = dataset_opt['use_shuffle'] 20 | shuffle = False 21 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=0, 22 | pin_memory=False) 23 | 24 | 25 | def create_dataset(opt,dataset_opt): 26 | mode = dataset_opt['mode'] 27 | # datasets for image restoration 28 | if mode == 'UEN_train': 29 | from data.SIEN_dataset import DatasetFromFolder as D 30 | 31 | dataset = D(upscale_factor=opt['scale'], data_augmentation=dataset_opt['augment'], 32 | group_file=dataset_opt['filelist'], 33 | patch_size=dataset_opt['IN_size'], black_edges_crop=False, hflip=True, rot=True) 34 | 35 | elif mode == 'UEN_val': 36 | from data.SIEN_dataset import DatasetFromFolder as D 37 | dataset = D(upscale_factor=opt['scale'], data_augmentation=False, 38 | group_file=dataset_opt['filelist'], 39 | patch_size=None, black_edges_crop=False, hflip=False, rot=False) 40 | 41 | else: 42 | raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode)) 43 | 44 | 45 | logger = logging.getLogger('base') 46 | logger.info('Dataset [{:s} - {:s}] is created.'.format(dataset.__class__.__name__, 47 | dataset_opt['name'])) 48 | return dataset 49 | -------------------------------------------------------------------------------- /FastFourierLOL/data/__pycache__/SIEN_dataset.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/data/__pycache__/SIEN_dataset.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/data/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/data/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/data/groups_test_LOL.txt: -------------------------------------------------------------------------------- 1 | /home/jieh/Dataset/Continous/LOL/test/low/1.png|/home/jieh/Dataset/Continous/LOL/test/high/1.png 2 | /home/jieh/Dataset/Continous/LOL/test/low/111.png|/home/jieh/Dataset/Continous/LOL/test/high/111.png 3 | /home/jieh/Dataset/Continous/LOL/test/low/146.png|/home/jieh/Dataset/Continous/LOL/test/high/146.png 4 | /home/jieh/Dataset/Continous/LOL/test/low/179.png|/home/jieh/Dataset/Continous/LOL/test/high/179.png 5 | /home/jieh/Dataset/Continous/LOL/test/low/22.png|/home/jieh/Dataset/Continous/LOL/test/high/22.png 6 | /home/jieh/Dataset/Continous/LOL/test/low/23.png|/home/jieh/Dataset/Continous/LOL/test/high/23.png 7 | /home/jieh/Dataset/Continous/LOL/test/low/493.png|/home/jieh/Dataset/Continous/LOL/test/high/493.png 8 | /home/jieh/Dataset/Continous/LOL/test/low/547.png|/home/jieh/Dataset/Continous/LOL/test/high/547.png 9 | /home/jieh/Dataset/Continous/LOL/test/low/55.png|/home/jieh/Dataset/Continous/LOL/test/high/55.png 10 | /home/jieh/Dataset/Continous/LOL/test/low/665.png|/home/jieh/Dataset/Continous/LOL/test/high/665.png 11 | /home/jieh/Dataset/Continous/LOL/test/low/669.png|/home/jieh/Dataset/Continous/LOL/test/high/669.png 12 | /home/jieh/Dataset/Continous/LOL/test/low/748.png|/home/jieh/Dataset/Continous/LOL/test/high/748.png 13 | /home/jieh/Dataset/Continous/LOL/test/low/778.png|/home/jieh/Dataset/Continous/LOL/test/high/778.png 14 | /home/jieh/Dataset/Continous/LOL/test/low/780.png|/home/jieh/Dataset/Continous/LOL/test/high/780.png 15 | /home/jieh/Dataset/Continous/LOL/test/low/79.png|/home/jieh/Dataset/Continous/LOL/test/high/79.png 16 | -------------------------------------------------------------------------------- /FastFourierLOL/data/shuffle.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | out = open("/ghome/huangjie/Continous/Baseline/groups_train_mixReFive.txt",'w') 4 | lines=[] 5 | with open("/ghome/huangjie/Continous/Baseline/mix.txt", 'r') as infile: 6 | for line in infile: 7 | lines.append(line) 8 | random.shuffle(lines) 9 | for line in lines: 10 | out.write(line) 11 | 12 | infile.close() 13 | out.close() 14 | 15 | -------------------------------------------------------------------------------- /FastFourierLOL/eval.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test Vid4 (SR) and REDS4 (SR-clean, SR-blur, deblur-clean, deblur-compression) datasets 3 | ''' 4 | import os 5 | import os.path as osp 6 | import glob 7 | import logging 8 | import numpy as np 9 | import cv2 10 | import torch 11 | import argparse 12 | import utils.util as util 13 | import data.util as data_util 14 | import models.archs.EnhanceN_arch as EnhanceN_arch 15 | 16 | def dataload_test(img_path): 17 | img_numpy = cv2.imread(img_path,cv2.IMREAD_UNCHANGED).astype(np.float32)/255.0 18 | # img_numpy = cv2.resize(img_numpy,(512,512)) 19 | img_numpy = img_numpy[:, :, [2, 1, 0]] 20 | img_numpy = torch.from_numpy(np.ascontiguousarray(np.transpose(img_numpy, (2, 0, 1)))).float() 21 | img_numpy = img_numpy.unsqueeze(0) 22 | return img_numpy 23 | 24 | 25 | def forward_eval(model,img): 26 | with torch.no_grad(): 27 | model_output = model(img,torch.cuda.FloatTensor().resize_(1).zero_()+1, 28 | torch.cuda.FloatTensor().resize_(1).zero_()+1) 29 | # if isinstance(model_output, list) or isinstance(model_output, tuple): 30 | output = model_output 31 | # else: 32 | # output = model_output 33 | output = output.data.float().cpu() 34 | 35 | return output 36 | 37 | 38 | def main(root, save_folder, imageLists, modelPath): 39 | ################# 40 | # configurations 41 | ################# 42 | device = torch.device('cuda') 43 | os.environ['CUDA_VISIBLE_DEVICES'] = '0' 44 | ############################################################################ 45 | #### model 46 | model_path = modelPath 47 | model = EnhanceN_arch.Net() 48 | 49 | #### dataset 50 | test_dataset_folder = root 51 | save_imgs = True 52 | util.mkdirs(save_folder) 53 | # util.setup_logger('base', save_folder, 'test', level=logging.INFO, screen=True, tofile=True) 54 | # logger = logging.getLogger('base') 55 | 56 | #### set up the models 57 | model.load_state_dict(torch.load(model_path), strict=True) 58 | print("load model successfully") 59 | model.eval() 60 | model = model.to(device) 61 | 62 | image_filenames = [line.rstrip() for line in open(os.path.join(imageLists))] 63 | 64 | # process each image 65 | j = 0 66 | for img_idx in range(len(image_filenames)): 67 | 68 | img_name = os.path.basename(image_filenames[img_idx]) 69 | img = dataload_test(image_filenames[img_idx]).to(device) 70 | folder = image_filenames[img_idx].split('/')[-2] 71 | util.mkdirs(os.path.join(save_folder,folder)) 72 | # if img_right.shape[3] < 1000: 73 | # continue 74 | # for tx in range(2): 75 | # img_left = img_left_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_left_ori.shape[3])] 76 | # img_right = img_right_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_right_ori.shape[3])] 77 | 78 | output = forward_eval(model,img) 79 | output = util.tensor2img(output.squeeze(0)) 80 | 81 | if save_imgs: 82 | 83 | cv2.imwrite(osp.join(save_folder,folder,img_name), output) 84 | 85 | 86 | j = j + 1 87 | print("process %d th image" % j) 88 | 89 | print('################ Finish Testing ################') 90 | 91 | 92 | 93 | if __name__ == '__main__': 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('--root', type=str, default='/data/1760921465/NTIRE2021/SR/test_input/', metavar='PATH', help='validation dataset root dir') 96 | parser.add_argument('--imageLists', type=str, default='/code/UEN/data/srtest_input.txt', metavar='FILE', help='record video ids') 97 | parser.add_argument('--save_folder', type=str, default='/data/1760921465/NTIRE2021/SR/GFN_test', metavar='PATH', help='save results') 98 | parser.add_argument('--modelPath', type=str, default='/model/1760921465/NTIRE2021/SR/GFN.pth', help='Model path') 99 | 100 | args = parser.parse_args() 101 | 102 | root = args.root 103 | imageLists = args.imageLists 104 | save_folder = args.save_folder 105 | modelPath = args.modelPath 106 | 107 | main(root, save_folder, imageLists, modelPath) 108 | -------------------------------------------------------------------------------- /FastFourierLOL/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | logger = logging.getLogger('base') 3 | 4 | 5 | def create_model(opt): 6 | # image restoration 7 | model = opt['model'] 8 | if model == 'sr': 9 | from .SIEN_model import SIEN_Model as M 10 | else: 11 | raise NotImplementedError('Model [{:s}] not recognized.'.format(model)) 12 | m = M(opt) 13 | logger.info('Model [{:s}] is created.'.format(m.__class__.__name__)) 14 | return m 15 | 16 | -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/SIEN_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/SIEN_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/base_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/base_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/loss.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/loss.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/loss_new.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/loss_new.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/lr_scheduler.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/lr_scheduler.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/__pycache__/networks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/__pycache__/networks.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__init__.py -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/EDVR_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/EDVR_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/EDVR_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/EDVR_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/arch_util.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/arch_util.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/arch_util.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/arch_util.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/arch_util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/arch_util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/arch_util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Adobe Inc. All rights reserved. 2 | # 3 | # This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4 | # 4.0 International Public License. To view a copy of this license, visit 5 | # https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode. 6 | 7 | 8 | 9 | ######## https://github.com/adobe/antialiased-cnns/blob/master/models_lpf/__init__.py 10 | 11 | 12 | 13 | import torch 14 | import torch.nn.parallel 15 | import numpy as np 16 | import torch.nn as nn 17 | import torch.nn.functional as F 18 | 19 | class Downsample(nn.Module): 20 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 21 | super(Downsample, self).__init__() 22 | self.filt_size = filt_size 23 | self.pad_off = pad_off 24 | self.pad_sizes = [int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2)), int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2))] 25 | self.pad_sizes = [pad_size+pad_off for pad_size in self.pad_sizes] 26 | self.stride = stride 27 | self.off = int((self.stride-1)/2.) 28 | self.channels = channels 29 | 30 | # print('Filter size [%i]'%filt_size) 31 | if(self.filt_size==1): 32 | a = np.array([1.,]) 33 | elif(self.filt_size==2): 34 | a = np.array([1., 1.]) 35 | elif(self.filt_size==3): 36 | a = np.array([1., 2., 1.]) 37 | elif(self.filt_size==4): 38 | a = np.array([1., 3., 3., 1.]) 39 | elif(self.filt_size==5): 40 | a = np.array([1., 4., 6., 4., 1.]) 41 | elif(self.filt_size==6): 42 | a = np.array([1., 5., 10., 10., 5., 1.]) 43 | elif(self.filt_size==7): 44 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 45 | 46 | filt = torch.Tensor(a[:,None]*a[None,:]) 47 | filt = filt/torch.sum(filt) 48 | self.register_buffer('filt', filt[None,None,:,:].repeat((self.channels,1,1,1))) 49 | 50 | self.pad = get_pad_layer(pad_type)(self.pad_sizes) 51 | 52 | def forward(self, inp): 53 | if(self.filt_size==1): 54 | if(self.pad_off==0): 55 | return inp[:,:,::self.stride,::self.stride] 56 | else: 57 | return self.pad(inp)[:,:,::self.stride,::self.stride] 58 | else: 59 | return F.conv2d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 60 | 61 | def get_pad_layer(pad_type): 62 | if(pad_type in ['refl','reflect']): 63 | PadLayer = nn.ReflectionPad2d 64 | elif(pad_type in ['repl','replicate']): 65 | PadLayer = nn.ReplicationPad2d 66 | elif(pad_type=='zero'): 67 | PadLayer = nn.ZeroPad2d 68 | else: 69 | print('Pad type [%s] not recognized'%pad_type) 70 | return PadLayer 71 | 72 | 73 | class Downsample1D(nn.Module): 74 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 75 | super(Downsample1D, self).__init__() 76 | self.filt_size = filt_size 77 | self.pad_off = pad_off 78 | self.pad_sizes = [int(1. * (filt_size - 1) / 2), int(np.ceil(1. * (filt_size - 1) / 2))] 79 | self.pad_sizes = [pad_size + pad_off for pad_size in self.pad_sizes] 80 | self.stride = stride 81 | self.off = int((self.stride - 1) / 2.) 82 | self.channels = channels 83 | 84 | # print('Filter size [%i]' % filt_size) 85 | if(self.filt_size == 1): 86 | a = np.array([1., ]) 87 | elif(self.filt_size == 2): 88 | a = np.array([1., 1.]) 89 | elif(self.filt_size == 3): 90 | a = np.array([1., 2., 1.]) 91 | elif(self.filt_size == 4): 92 | a = np.array([1., 3., 3., 1.]) 93 | elif(self.filt_size == 5): 94 | a = np.array([1., 4., 6., 4., 1.]) 95 | elif(self.filt_size == 6): 96 | a = np.array([1., 5., 10., 10., 5., 1.]) 97 | elif(self.filt_size == 7): 98 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 99 | 100 | filt = torch.Tensor(a) 101 | filt = filt / torch.sum(filt) 102 | self.register_buffer('filt', filt[None, None, :].repeat((self.channels, 1, 1))) 103 | 104 | self.pad = get_pad_layer_1d(pad_type)(self.pad_sizes) 105 | 106 | def forward(self, inp): 107 | if(self.filt_size == 1): 108 | if(self.pad_off == 0): 109 | return inp[:, :, ::self.stride] 110 | else: 111 | return self.pad(inp)[:, :, ::self.stride] 112 | else: 113 | return F.conv1d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 114 | 115 | 116 | def get_pad_layer_1d(pad_type): 117 | if(pad_type in ['refl', 'reflect']): 118 | PadLayer = nn.ReflectionPad1d 119 | elif(pad_type in ['repl', 'replicate']): 120 | PadLayer = nn.ReplicationPad1d 121 | elif(pad_type == 'zero'): 122 | PadLayer = nn.ZeroPad1d 123 | else: 124 | print('Pad type [%s] not recognized' % pad_type) 125 | return PadLayer -------------------------------------------------------------------------------- /FastFourierLOL/models/archs/discriminator_vgg_arch.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torchvision 4 | 5 | 6 | class Discriminator_VGG_128(nn.Module): 7 | def __init__(self, in_nc, nf): 8 | super(Discriminator_VGG_128, self).__init__() 9 | # [64, 128, 128] 10 | self.conv0_0 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True) 11 | self.conv0_1 = nn.Conv2d(nf, nf, 4, 2, 1, bias=False) 12 | self.bn0_1 = nn.BatchNorm2d(nf, affine=True) 13 | # [64, 64, 64] 14 | self.conv1_0 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=False) 15 | self.bn1_0 = nn.BatchNorm2d(nf * 2, affine=True) 16 | self.conv1_1 = nn.Conv2d(nf * 2, nf * 2, 4, 2, 1, bias=False) 17 | self.bn1_1 = nn.BatchNorm2d(nf * 2, affine=True) 18 | # [128, 32, 32] 19 | self.conv2_0 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=False) 20 | self.bn2_0 = nn.BatchNorm2d(nf * 4, affine=True) 21 | self.conv2_1 = nn.Conv2d(nf * 4, nf * 4, 4, 2, 1, bias=False) 22 | self.bn2_1 = nn.BatchNorm2d(nf * 4, affine=True) 23 | # [256, 16, 16] 24 | self.conv3_0 = nn.Conv2d(nf * 4, nf * 8, 3, 1, 1, bias=False) 25 | self.bn3_0 = nn.BatchNorm2d(nf * 8, affine=True) 26 | self.conv3_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 27 | self.bn3_1 = nn.BatchNorm2d(nf * 8, affine=True) 28 | # [512, 8, 8] 29 | self.conv4_0 = nn.Conv2d(nf * 8, nf * 8, 3, 1, 1, bias=False) 30 | self.bn4_0 = nn.BatchNorm2d(nf * 8, affine=True) 31 | self.conv4_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 32 | self.bn4_1 = nn.BatchNorm2d(nf * 8, affine=True) 33 | 34 | self.linear1 = nn.Linear(512 * 4 * 4, 100) 35 | self.linear2 = nn.Linear(100, 1) 36 | 37 | # activation function 38 | self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) 39 | 40 | def forward(self, x): 41 | fea = self.lrelu(self.conv0_0(x)) 42 | fea = self.lrelu(self.bn0_1(self.conv0_1(fea))) 43 | 44 | fea = self.lrelu(self.bn1_0(self.conv1_0(fea))) 45 | fea = self.lrelu(self.bn1_1(self.conv1_1(fea))) 46 | 47 | fea = self.lrelu(self.bn2_0(self.conv2_0(fea))) 48 | fea = self.lrelu(self.bn2_1(self.conv2_1(fea))) 49 | 50 | fea = self.lrelu(self.bn3_0(self.conv3_0(fea))) 51 | fea = self.lrelu(self.bn3_1(self.conv3_1(fea))) 52 | 53 | fea = self.lrelu(self.bn4_0(self.conv4_0(fea))) 54 | fea = self.lrelu(self.bn4_1(self.conv4_1(fea))) 55 | 56 | fea = fea.view(fea.size(0), -1) 57 | fea = self.lrelu(self.linear1(fea)) 58 | out = self.linear2(fea) 59 | return out 60 | 61 | 62 | class VGGFeatureExtractor(nn.Module): 63 | def __init__(self, feature_layer=34, use_bn=False, use_input_norm=True, 64 | device=torch.device('cpu')): 65 | super(VGGFeatureExtractor, self).__init__() 66 | self.use_input_norm = use_input_norm 67 | if use_bn: 68 | model = torchvision.models.vgg19_bn(pretrained=True) 69 | else: 70 | model = torchvision.models.vgg19(pretrained=True) 71 | if self.use_input_norm: 72 | mean = torch.Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1).to(device) 73 | # [0.485 - 1, 0.456 - 1, 0.406 - 1] if input in range [-1, 1] 74 | std = torch.Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1).to(device) 75 | # [0.229 * 2, 0.224 * 2, 0.225 * 2] if input in range [-1, 1] 76 | self.register_buffer('mean', mean) 77 | self.register_buffer('std', std) 78 | self.features = nn.Sequential(*list(model.features.children())[:(feature_layer + 1)]) 79 | # No need to BP to variable 80 | for k, v in self.features.named_parameters(): 81 | v.requires_grad = False 82 | 83 | def forward(self, x): 84 | # Assume input range is [0, 1] 85 | if self.use_input_norm: 86 | x = (x - self.mean) / self.std 87 | output = self.features(x) 88 | return output 89 | -------------------------------------------------------------------------------- /FastFourierLOL/models/base_model.py: -------------------------------------------------------------------------------- 1 | import os 2 | from collections import OrderedDict 3 | import torch 4 | import torch.nn as nn 5 | from torch.nn.parallel import DistributedDataParallel 6 | 7 | 8 | class BaseModel(): 9 | def __init__(self, opt): 10 | self.opt = opt 11 | self.device = torch.device('cuda' if opt['gpu_ids'] is not None else 'cpu') 12 | self.is_train = opt['is_train'] 13 | self.schedulers = [] 14 | self.optimizers = [] 15 | 16 | def feed_data(self, data): 17 | pass 18 | 19 | def optimize_parameters(self): 20 | pass 21 | 22 | def get_current_visuals(self): 23 | pass 24 | 25 | def get_current_losses(self): 26 | pass 27 | 28 | def print_network(self): 29 | pass 30 | 31 | def save(self, label): 32 | pass 33 | 34 | def load(self): 35 | pass 36 | 37 | def _set_lr(self, lr_groups_l): 38 | """Set learning rate for warmup 39 | lr_groups_l: list for lr_groups. each for a optimizer""" 40 | for optimizer, lr_groups in zip(self.optimizers, lr_groups_l): 41 | for param_group, lr in zip(optimizer.param_groups, lr_groups): 42 | param_group['lr'] = lr 43 | 44 | def _get_init_lr(self): 45 | """Get the initial lr, which is set by the scheduler""" 46 | init_lr_groups_l = [] 47 | for optimizer in self.optimizers: 48 | init_lr_groups_l.append([v['initial_lr'] for v in optimizer.param_groups]) 49 | return init_lr_groups_l 50 | 51 | def update_learning_rate(self, cur_iter, warmup_iter=-1): 52 | for scheduler in self.schedulers: 53 | scheduler.step() 54 | # set up warm-up learning rate 55 | if cur_iter < warmup_iter: 56 | # get initial lr for each group 57 | init_lr_g_l = self._get_init_lr() 58 | # modify warming-up learning rates 59 | warm_up_lr_l = [] 60 | for init_lr_g in init_lr_g_l: 61 | warm_up_lr_l.append([v / warmup_iter * cur_iter for v in init_lr_g]) 62 | # set learning rate 63 | self._set_lr(warm_up_lr_l) 64 | 65 | def get_current_learning_rate(self): 66 | return [param_group['lr'] for param_group in self.optimizers[0].param_groups] 67 | 68 | def get_network_description(self, network): 69 | """Get the string and total parameters of the network""" 70 | if isinstance(network, nn.DataParallel) or isinstance(network, DistributedDataParallel): 71 | network = network.module 72 | return str(network), sum(map(lambda x: x.numel(), network.parameters())) 73 | 74 | def save_network(self, network, network_label, iter_label): 75 | save_filename = '{}_{}.pth'.format(iter_label, network_label) 76 | save_path = os.path.join(self.opt['path']['models'], save_filename) 77 | if isinstance(network, nn.DataParallel) or isinstance(network, DistributedDataParallel): 78 | network = network.module 79 | state_dict = network.state_dict() 80 | for key, param in state_dict.items(): 81 | state_dict[key] = param.cpu() 82 | torch.save(state_dict, save_path) 83 | 84 | def load_network(self, load_path, network, strict=True): 85 | if isinstance(network, nn.DataParallel) or isinstance(network, DistributedDataParallel): 86 | network = network.module 87 | if os.path.exists(load_path): 88 | load_net = torch.load(load_path) 89 | load_net_clean = OrderedDict() # remove unnecessary 'module.' 90 | for k, v in load_net.items(): 91 | if k.startswith('module.'): 92 | load_net_clean[k[7:]] = v 93 | else: 94 | load_net_clean[k] = v 95 | network.load_state_dict(load_net_clean, strict=strict) 96 | print("Succcefully!!!!! pretrained model has loaded!!!!!!!!!!!!!!!") 97 | else: 98 | print("Wrong!!!!! pretrained path not exists") 99 | 100 | def save_training_state(self, epoch, iter_step): 101 | """Save training state during training, which will be used for resuming""" 102 | state = {'epoch': epoch, 'iter': iter_step, 'schedulers': [], 'optimizers': []} 103 | for s in self.schedulers: 104 | state['schedulers'].append(s.state_dict()) 105 | for o in self.optimizers: 106 | state['optimizers'].append(o.state_dict()) 107 | save_filename = '{}.state'.format(iter_step) 108 | save_path = os.path.join(self.opt['path']['training_state'], save_filename) 109 | torch.save(state, save_path) 110 | 111 | def resume_training(self, resume_state): 112 | """Resume the optimizers and schedulers for training""" 113 | resume_optimizers = resume_state['optimizers'] 114 | resume_schedulers = resume_state['schedulers'] 115 | assert len(resume_optimizers) == len(self.optimizers), 'Wrong lengths of optimizers' 116 | assert len(resume_schedulers) == len(self.schedulers), 'Wrong lengths of schedulers' 117 | for i, o in enumerate(resume_optimizers): 118 | self.optimizers[i].load_state_dict(o) 119 | for i, s in enumerate(resume_schedulers): 120 | self.schedulers[i].load_state_dict(s) 121 | -------------------------------------------------------------------------------- /FastFourierLOL/models/loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class CharbonnierLoss(nn.Module): 6 | """Charbonnier Loss (L1)""" 7 | 8 | def __init__(self, eps=1e-6): 9 | super(CharbonnierLoss, self).__init__() 10 | self.eps = eps 11 | 12 | def forward(self, x, y): 13 | diff = x - y 14 | loss = torch.sum(torch.sqrt(diff * diff + self.eps)) 15 | return loss 16 | 17 | 18 | # Define GAN loss: [vanilla | lsgan | wgan-gp] 19 | class GANLoss(nn.Module): 20 | def __init__(self, gan_type, real_label_val=1.0, fake_label_val=0.0): 21 | super(GANLoss, self).__init__() 22 | self.gan_type = gan_type.lower() 23 | self.real_label_val = real_label_val 24 | self.fake_label_val = fake_label_val 25 | 26 | if self.gan_type == 'gan' or self.gan_type == 'ragan': 27 | self.loss = nn.BCEWithLogitsLoss() 28 | elif self.gan_type == 'lsgan': 29 | self.loss = nn.MSELoss() 30 | elif self.gan_type == 'wgan-gp': 31 | 32 | def wgan_loss(input, target): 33 | # target is boolean 34 | return -1 * input.mean() if target else input.mean() 35 | 36 | self.loss = wgan_loss 37 | else: 38 | raise NotImplementedError('GAN type [{:s}] is not found'.format(self.gan_type)) 39 | 40 | def get_target_label(self, input, target_is_real): 41 | if self.gan_type == 'wgan-gp': 42 | return target_is_real 43 | if target_is_real: 44 | return torch.empty_like(input).fill_(self.real_label_val) 45 | else: 46 | return torch.empty_like(input).fill_(self.fake_label_val) 47 | 48 | def forward(self, input, target_is_real): 49 | target_label = self.get_target_label(input, target_is_real) 50 | loss = self.loss(input, target_label) 51 | return loss 52 | 53 | 54 | class GradientPenaltyLoss(nn.Module): 55 | def __init__(self, device=torch.device('cpu')): 56 | super(GradientPenaltyLoss, self).__init__() 57 | self.register_buffer('grad_outputs', torch.Tensor()) 58 | self.grad_outputs = self.grad_outputs.to(device) 59 | 60 | def get_grad_outputs(self, input): 61 | if self.grad_outputs.size() != input.size(): 62 | self.grad_outputs.resize_(input.size()).fill_(1.0) 63 | return self.grad_outputs 64 | 65 | def forward(self, interp, interp_crit): 66 | grad_outputs = self.get_grad_outputs(interp_crit) 67 | grad_interp = torch.autograd.grad(outputs=interp_crit, inputs=interp, 68 | grad_outputs=grad_outputs, create_graph=True, 69 | retain_graph=True, only_inputs=True)[0] 70 | grad_interp = grad_interp.view(grad_interp.size(0), -1) 71 | grad_interp_norm = grad_interp.norm(2, dim=1) 72 | 73 | loss = ((grad_interp_norm - 1)**2).mean() 74 | return loss 75 | 76 | 77 | class AMPLoss(nn.Module): 78 | def __init__(self): 79 | super(AMPLoss, self).__init__() 80 | self.cri = nn.L1Loss() 81 | 82 | def forward(self, x, y): 83 | x = torch.fft.rfft2(x, norm='backward') 84 | x_mag = torch.abs(x) 85 | y = torch.fft.rfft2(y, norm='backward') 86 | y_mag = torch.abs(y) 87 | 88 | return self.cri(x_mag,y_mag) 89 | 90 | 91 | class PhaLoss(nn.Module): 92 | def __init__(self): 93 | super(PhaLoss, self).__init__() 94 | self.cri = nn.L1Loss() 95 | 96 | def forward(self, x, y): 97 | x = torch.fft.rfft2(x, norm='backward') 98 | x_mag = torch.angle(x) 99 | y = torch.fft.rfft2(y, norm='backward') 100 | y_mag = torch.angle(y) 101 | 102 | return self.cri(x_mag, y_mag) -------------------------------------------------------------------------------- /FastFourierLOL/models/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import models.archs.discriminator_vgg_arch as SRGAN_arch 3 | import models.archs.EnhanceN_arch as EnhanceN_arch 4 | import models.archs.EnhanceN_arch1 as EnhanceN_arch1 5 | 6 | 7 | # Generator 8 | def define_G(opt): 9 | opt_net = opt['network_G'] 10 | which_model = opt_net['which_model_G'] 11 | 12 | # video restoration 13 | if which_model == 'Net': 14 | netG = EnhanceN_arch.InteractNet(nc=opt_net['nc']) 15 | elif which_model == 'Net1': 16 | netG = EnhanceN_arch1.InteractNet(nc=opt_net['nc']) 17 | else: 18 | raise NotImplementedError('Generator model [{:s}] not recognized'.format(which_model)) 19 | 20 | return netG 21 | 22 | 23 | # Discriminator 24 | def define_D(opt): 25 | opt_net = opt['network_D'] 26 | which_model = opt_net['which_model_D'] 27 | 28 | if which_model == 'discriminator_vgg_128': 29 | netD = SRGAN_arch.Discriminator_VGG_128(in_nc=opt_net['in_nc'], nf=opt_net['nf']) 30 | else: 31 | raise NotImplementedError('Discriminator model [{:s}] not recognized'.format(which_model)) 32 | return netD 33 | 34 | 35 | # Define network used for perceptual loss 36 | def define_F(opt, use_bn=False): 37 | gpu_ids = opt['gpu_ids'] 38 | device = torch.device('cuda' if gpu_ids else 'cpu') 39 | # PyTorch pretrained VGG19-54, before ReLU. 40 | if use_bn: 41 | feature_layer = 49 42 | else: 43 | feature_layer = 34 44 | netF = SRGAN_arch.VGGFeatureExtractor(feature_layer=feature_layer, use_bn=use_bn, 45 | use_input_norm=True, device=device) 46 | netF.eval() # No need to train 47 | return netF 48 | -------------------------------------------------------------------------------- /FastFourierLOL/options/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/options/__init__.py -------------------------------------------------------------------------------- /FastFourierLOL/options/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/options/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/options/__pycache__/options.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/options/__pycache__/options.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/options/options.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as osp 3 | import logging 4 | import yaml 5 | from utils.util import OrderedYaml 6 | Loader, Dumper = OrderedYaml() 7 | 8 | 9 | def parse(opt_path, is_train=True): 10 | with open(opt_path, mode='r') as f: 11 | opt = yaml.load(f, Loader=Loader) 12 | # export CUDA_VISIBLE_DEVICES 13 | gpu_list = ','.join(str(x) for x in opt['gpu_ids']) 14 | os.environ['CUDA_VISIBLE_DEVICES'] = gpu_list 15 | print('export CUDA_VISIBLE_DEVICES=' + gpu_list) 16 | 17 | opt['is_train'] = is_train 18 | if opt['distortion'] == 'sr': 19 | scale = opt['scale'] 20 | 21 | # datasets 22 | for phase, dataset in opt['datasets'].items(): 23 | phase = phase.split('_')[0] 24 | dataset['phase'] = phase 25 | if opt['distortion'] == 'sr': 26 | dataset['scale'] = scale 27 | is_lmdb = False 28 | if dataset.get('dataroot_GT', None) is not None: 29 | dataset['dataroot_GT'] = osp.expanduser(dataset['dataroot_GT']) 30 | if dataset['dataroot_GT'].endswith('lmdb'): 31 | is_lmdb = True 32 | if dataset.get('dataroot_LQ', None) is not None: 33 | dataset['dataroot_LQ'] = osp.expanduser(dataset['dataroot_LQ']) 34 | if dataset['dataroot_LQ'].endswith('lmdb'): 35 | is_lmdb = True 36 | dataset['data_type'] = 'lmdb' if is_lmdb else 'img' 37 | if dataset['mode'].endswith('mc'): # for memcached 38 | dataset['data_type'] = 'mc' 39 | dataset['mode'] = dataset['mode'].replace('_mc', '') 40 | 41 | # path 42 | for key, path in opt['path'].items(): 43 | if path and key in opt['path'] and key != 'strict_load': 44 | opt['path'][key] = osp.expanduser(path) 45 | # opt['path']['root'] = '/home/zhanghc/IEEEyellow/code_enhance/checkpoints' 46 | if is_train: 47 | experiments_root = osp.join(opt['path']['root'], 'experiments', opt['name']) 48 | opt['path']['experiments_root'] = experiments_root 49 | opt['path']['models'] = osp.join(experiments_root, 'models') 50 | opt['path']['training_state'] = osp.join(experiments_root, 'training_state') 51 | opt['path']['log'] = experiments_root 52 | opt['path']['val_images'] = osp.join(experiments_root, 'val_images') 53 | 54 | # change some options for debug mode 55 | if 'debug' in opt['name']: 56 | opt['train']['val_freq'] = 8 57 | opt['logger']['print_freq'] = 1 58 | opt['logger']['save_checkpoint_freq'] = 8 59 | else: # test 60 | results_root = osp.join(opt['path']['root'], 'results', opt['name']) 61 | opt['path']['results_root'] = results_root 62 | opt['path']['log'] = results_root 63 | 64 | # network 65 | if opt['distortion'] == 'sr': 66 | opt['network_G']['scale'] = scale 67 | 68 | return opt 69 | 70 | 71 | def dict2str(opt, indent_l=1): 72 | '''dict to string for logger''' 73 | msg = '' 74 | for k, v in opt.items(): 75 | if isinstance(v, dict): 76 | msg += ' ' * (indent_l * 2) + k + ':[\n' 77 | msg += dict2str(v, indent_l + 1) 78 | msg += ' ' * (indent_l * 2) + ']\n' 79 | else: 80 | msg += ' ' * (indent_l * 2) + k + ': ' + str(v) + '\n' 81 | return msg 82 | 83 | 84 | class NoneDict(dict): 85 | def __missing__(self, key): 86 | return None 87 | 88 | 89 | # convert to NoneDict, which return None for missing key. 90 | def dict_to_nonedict(opt): 91 | if isinstance(opt, dict): 92 | new_opt = dict() 93 | for key, sub_opt in opt.items(): 94 | new_opt[key] = dict_to_nonedict(sub_opt) 95 | return NoneDict(**new_opt) 96 | elif isinstance(opt, list): 97 | return [dict_to_nonedict(sub_opt) for sub_opt in opt] 98 | else: 99 | return opt 100 | 101 | 102 | def check_resume(opt, resume_iter): 103 | '''Check resume states and pretrain_model paths''' 104 | logger = logging.getLogger('base') 105 | if opt['path']['resume_state']: 106 | if opt['path'].get('pretrain_model_G', None) is not None or opt['path'].get( 107 | 'pretrain_model_D', None) is not None: 108 | logger.warning('pretrain_model path will be ignored when resuming training.') 109 | 110 | opt['path']['pretrain_model_G'] = osp.join(opt['path']['models'], 111 | '{}_G.pth'.format(resume_iter)) 112 | logger.info('Set [pretrain_model_G] to ' + opt['path']['pretrain_model_G']) 113 | if 'gan' in opt['model']: 114 | opt['path']['pretrain_model_D'] = osp.join(opt['path']['models'], 115 | '{}_D.pth'.format(resume_iter)) 116 | logger.info('Set [pretrain_model_D] to ' + opt['path']['pretrain_model_D']) 117 | -------------------------------------------------------------------------------- /FastFourierLOL/options/test/test_ESRGAN.yml: -------------------------------------------------------------------------------- 1 | name: RRDB_ESRGAN_x4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: RRDBNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 23 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/RRDB_ESRGAN_x4.pth 33 | -------------------------------------------------------------------------------- /FastFourierLOL/options/test/test_SRGAN.yml: -------------------------------------------------------------------------------- 1 | name: MSRGANx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: MSRResNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 16 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/MSRGANx4.pth 33 | -------------------------------------------------------------------------------- /FastFourierLOL/options/test/test_SRResNet.yml: -------------------------------------------------------------------------------- 1 | name: MSRResNetx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | test_3: 21 | name: bsd100 22 | mode: LQGT 23 | dataroot_GT: ../datasets/BSD/BSDS100 24 | dataroot_LQ: ../datasets/BSD/BSDS100_bicLRx4 25 | test_4: 26 | name: urban100 27 | mode: LQGT 28 | dataroot_GT: ../datasets/urban100 29 | dataroot_LQ: ../datasets/urban100_bicLRx4 30 | test_5: 31 | name: div2k100 32 | mode: LQGT 33 | dataroot_GT: ../datasets/DIV2K100/DIV2K_valid_HR 34 | dataroot_LQ: ../datasets/DIV2K100/DIV2K_valid_bicLRx4 35 | 36 | 37 | #### network structures 38 | network_G: 39 | which_model_G: MSRResNet 40 | in_nc: 3 41 | out_nc: 3 42 | nf: 64 43 | nb: 16 44 | upscale: 4 45 | 46 | #### path 47 | path: 48 | pretrain_model_G: ../experiments/pretrained_models/MSRResNetx4.pth 49 | -------------------------------------------------------------------------------- /FastFourierLOL/options/train/train_Enhance.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [1] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier/data/groups_train_LOL.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 384 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier/data/groups_test_LOL.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourier/output 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourier/output 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourier/pretrain 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourier/output/experiments/SOTA1/models/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 1.5e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 50000 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [20000, 40000] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 20 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierLOL/options/train/train_Enhance1.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [0] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier/data/groups_train_LOL.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 256 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourier/data/groups_test_LOL.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net1 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourier/output1 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourier/output1 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourier/pretrain1 49 | pretrain_model_G: ~ 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 4e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 50000 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [20000, 40000] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 20 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierLOL/pretrain/0_bestavg.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/pretrain/0_bestavg.pth -------------------------------------------------------------------------------- /FastFourierLOL/test.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import logging 3 | import time 4 | import argparse 5 | from collections import OrderedDict 6 | 7 | import options.options as option 8 | import utils.util as util 9 | from data.util import bgr2ycbcr 10 | from data import create_dataset, create_dataloader 11 | from models import create_model 12 | 13 | #### options 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('-opt', type=str, required=True, help='Path to options YMAL file.') 16 | opt = option.parse(parser.parse_args().opt, is_train=False) 17 | opt = option.dict_to_nonedict(opt) 18 | 19 | util.mkdirs( 20 | (path for key, path in opt['path'].items() 21 | if not key == 'experiments_root' and 'pretrain_model' not in key and 'resume' not in key)) 22 | util.setup_logger('base', opt['path']['log'], 'test_' + opt['name'], level=logging.INFO, 23 | screen=True, tofile=True) 24 | logger = logging.getLogger('base') 25 | logger.info(option.dict2str(opt)) 26 | 27 | #### Create test dataset and dataloader 28 | test_loaders = [] 29 | for phase, dataset_opt in sorted(opt['datasets'].items()): 30 | test_set = create_dataset(dataset_opt) 31 | test_loader = create_dataloader(test_set, dataset_opt) 32 | logger.info('Number of test images in [{:s}]: {:d}'.format(dataset_opt['name'], len(test_set))) 33 | test_loaders.append(test_loader) 34 | 35 | model = create_model(opt) 36 | for test_loader in test_loaders: 37 | test_set_name = test_loader.dataset.opt['name'] 38 | logger.info('\nTesting [{:s}]...'.format(test_set_name)) 39 | test_start_time = time.time() 40 | dataset_dir = osp.join(opt['path']['results_root'], test_set_name) 41 | util.mkdir(dataset_dir) 42 | 43 | test_results = OrderedDict() 44 | test_results['psnr'] = [] 45 | test_results['ssim'] = [] 46 | test_results['psnr_y'] = [] 47 | test_results['ssim_y'] = [] 48 | 49 | for data in test_loader: 50 | need_GT = False if test_loader.dataset.opt['dataroot_GT'] is None else True 51 | model.feed_data(data, need_GT=need_GT) 52 | img_path = data['GT_path'][0] if need_GT else data['LQ_path'][0] 53 | img_name = osp.splitext(osp.basename(img_path))[0] 54 | 55 | model.test() 56 | visuals = model.get_current_visuals(need_GT=need_GT) 57 | 58 | sr_img = util.tensor2img(visuals['rlt']) # uint8 59 | 60 | # save images 61 | suffix = opt['suffix'] 62 | if suffix: 63 | save_img_path = osp.join(dataset_dir, img_name + suffix + '.png') 64 | else: 65 | save_img_path = osp.join(dataset_dir, img_name + '.png') 66 | util.save_img(sr_img, save_img_path) 67 | 68 | # calculate PSNR and SSIM 69 | if need_GT: 70 | gt_img = util.tensor2img(visuals['GT']) 71 | sr_img, gt_img = util.crop_border([sr_img, gt_img], opt['scale']) 72 | psnr = util.calculate_psnr(sr_img, gt_img) 73 | ssim = util.calculate_ssim(sr_img, gt_img) 74 | test_results['psnr'].append(psnr) 75 | test_results['ssim'].append(ssim) 76 | 77 | if gt_img.shape[2] == 3: # RGB image 78 | sr_img_y = bgr2ycbcr(sr_img / 255., only_y=True) 79 | gt_img_y = bgr2ycbcr(gt_img / 255., only_y=True) 80 | 81 | psnr_y = util.calculate_psnr(sr_img_y * 255, gt_img_y * 255) 82 | ssim_y = util.calculate_ssim(sr_img_y * 255, gt_img_y * 255) 83 | test_results['psnr_y'].append(psnr_y) 84 | test_results['ssim_y'].append(ssim_y) 85 | logger.info( 86 | '{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}; PSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}.'. 87 | format(img_name, psnr, ssim, psnr_y, ssim_y)) 88 | else: 89 | logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}.'.format(img_name, psnr, ssim)) 90 | else: 91 | logger.info(img_name) 92 | 93 | if need_GT: # metrics 94 | # Average PSNR/SSIM results 95 | ave_psnr = sum(test_results['psnr']) / len(test_results['psnr']) 96 | ave_ssim = sum(test_results['ssim']) / len(test_results['ssim']) 97 | logger.info( 98 | '----Average PSNR/SSIM results for {}----\n\tPSNR: {:.6f} dB; SSIM: {:.6f}\n'.format( 99 | test_set_name, ave_psnr, ave_ssim)) 100 | if test_results['psnr_y'] and test_results['ssim_y']: 101 | ave_psnr_y = sum(test_results['psnr_y']) / len(test_results['psnr_y']) 102 | ave_ssim_y = sum(test_results['ssim_y']) / len(test_results['ssim_y']) 103 | logger.info( 104 | '----Y channel, average PSNR/SSIM----\n\tPSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}\n'. 105 | format(ave_psnr_y, ave_ssim_y)) 106 | -------------------------------------------------------------------------------- /FastFourierLOL/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/utils/__init__.py -------------------------------------------------------------------------------- /FastFourierLOL/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierLOL/utils/__pycache__/util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierLOL/utils/__pycache__/util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/create_txt.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | 4 | 5 | def mkdir(path): 6 | if not os.path.exists(path): 7 | os.mkdir(path) 8 | 9 | 10 | def main(): 11 | assert os.path.exists(inputdir), 'Input dir not found' 12 | assert os.path.exists(targetdir), 'target dir not found' 13 | mkdir(outputdir) 14 | imgs = sorted(os.listdir(inputdir)) 15 | for idx,img in enumerate(imgs): 16 | groups = '' 17 | 18 | groups += os.path.join(inputdir, img) + '|' 19 | # groups += os.path.join(args.auxi, img) + '|' 20 | groups += os.path.join(targetdir,img) 21 | 22 | # if idx >= 800: 23 | # break 24 | 25 | with open(os.path.join(outputdir, 'groups_test_mixexposure.txt'), 'a') as f: 26 | f.write(groups + '\n') 27 | 28 | 29 | if __name__ == '__main__': 30 | parser = argparse.ArgumentParser() 31 | parser.add_argument('--input', type=str, default='/home/jieh/Dataset/Continous/Exposure/test/input/Exp5/', metavar='PATH', help='root dir to save low resolution images') 32 | # parser.add_argument('--auxi', type=str, default='/home/jieh/Dataset/Continous/ExpFiveLarge/train/Mid', metavar='PATH', help='root dir to save high resolution images') 33 | parser.add_argument('--target', type=str, default='/home/jieh/Dataset/Continous/Exposure/test/target/', metavar='PATH', help='root dir to save high resolution images') 34 | parser.add_argument('--output', type=str, default='/home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/', metavar='PATH', help='output dir to save group txt files') 35 | parser.add_argument('--ext', type=str, default='.png', help='Extension of files') 36 | args = parser.parse_args() 37 | 38 | inputdir = args.input 39 | targetdir = args.target 40 | outputdir = args.output 41 | ext = args.ext 42 | 43 | main() 44 | -------------------------------------------------------------------------------- /FastFourierMSEC/data/__init__.py: -------------------------------------------------------------------------------- 1 | """create dataset and dataloader""" 2 | import logging 3 | import torch 4 | import torch.utils.data 5 | 6 | 7 | def create_dataloader(dataset, dataset_opt, opt=None, sampler=None): 8 | phase = dataset_opt['phase'] 9 | if phase == 'train': 10 | num_workers = dataset_opt['n_workers'] * len(opt['gpu_ids']) 11 | batch_size = dataset_opt['batch_size'] 12 | # shuffle = True 13 | shuffle = dataset_opt['use_shuffle'] 14 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, 15 | num_workers=0, sampler=sampler, 16 | pin_memory=True) 17 | else: 18 | batch_size = dataset_opt['batch_size'] 19 | # shuffle = dataset_opt['use_shuffle'] 20 | shuffle = False 21 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=0, 22 | pin_memory=False) 23 | 24 | 25 | def create_dataset(opt,dataset_opt): 26 | mode = dataset_opt['mode'] 27 | # datasets for image restoration 28 | if mode == 'UEN_train': 29 | from data.SIEN_dataset import DatasetFromFolder as D 30 | 31 | dataset = D(upscale_factor=opt['scale'], data_augmentation=dataset_opt['augment'], 32 | group_file=dataset_opt['filelist'], 33 | patch_size=dataset_opt['IN_size'], black_edges_crop=False, hflip=True, rot=True) 34 | 35 | elif mode == 'UEN_val': 36 | from data.SIEN_dataset import DatasetFromFolder as D 37 | dataset = D(upscale_factor=opt['scale'], data_augmentation=False, 38 | group_file=dataset_opt['filelist'], 39 | patch_size=None, black_edges_crop=False, hflip=False, rot=False) 40 | 41 | else: 42 | raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode)) 43 | 44 | 45 | logger = logging.getLogger('base') 46 | logger.info('Dataset [{:s} - {:s}] is created.'.format(dataset.__class__.__name__, 47 | dataset_opt['name'])) 48 | return dataset 49 | -------------------------------------------------------------------------------- /FastFourierMSEC/data/__pycache__/SIEN_dataset.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/data/__pycache__/SIEN_dataset.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/data/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/data/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/data/shuffle.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | out = open("/home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/groups_train_mixexposure.txt",'w') 4 | lines=[] 5 | with open("/home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/exposure.txt", 'r') as infile: 6 | for line in infile: 7 | lines.append(line) 8 | random.shuffle(lines) 9 | for line in lines: 10 | out.write(line) 11 | 12 | infile.close() 13 | out.close() 14 | 15 | -------------------------------------------------------------------------------- /FastFourierMSEC/eval.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test Vid4 (SR) and REDS4 (SR-clean, SR-blur, deblur-clean, deblur-compression) datasets 3 | ''' 4 | import os 5 | import os.path as osp 6 | import glob 7 | import logging 8 | import numpy as np 9 | import cv2 10 | import torch 11 | import argparse 12 | import utils.util as util 13 | import data.util as data_util 14 | import models.archs.EnhanceN_arch as EnhanceN_arch 15 | 16 | def dataload_test(img_path): 17 | img_numpy = cv2.imread(img_path,cv2.IMREAD_UNCHANGED).astype(np.float32)/255.0 18 | # img_numpy = cv2.resize(img_numpy,(512,512)) 19 | img_numpy = img_numpy[:, :, [2, 1, 0]] 20 | img_numpy = torch.from_numpy(np.ascontiguousarray(np.transpose(img_numpy, (2, 0, 1)))).float() 21 | img_numpy = img_numpy.unsqueeze(0) 22 | return img_numpy 23 | 24 | 25 | def forward_eval(model,img): 26 | with torch.no_grad(): 27 | model_output = model(img,torch.cuda.FloatTensor().resize_(1).zero_()+1, 28 | torch.cuda.FloatTensor().resize_(1).zero_()+1) 29 | # if isinstance(model_output, list) or isinstance(model_output, tuple): 30 | output = model_output 31 | # else: 32 | # output = model_output 33 | output = output.data.float().cpu() 34 | 35 | return output 36 | 37 | 38 | def main(root, save_folder, imageLists, modelPath): 39 | ################# 40 | # configurations 41 | ################# 42 | device = torch.device('cuda') 43 | os.environ['CUDA_VISIBLE_DEVICES'] = '0' 44 | ############################################################################ 45 | #### model 46 | model_path = modelPath 47 | model = EnhanceN_arch.Net() 48 | 49 | #### dataset 50 | test_dataset_folder = root 51 | save_imgs = True 52 | util.mkdirs(save_folder) 53 | # util.setup_logger('base', save_folder, 'test', level=logging.INFO, screen=True, tofile=True) 54 | # logger = logging.getLogger('base') 55 | 56 | #### set up the models 57 | model.load_state_dict(torch.load(model_path), strict=True) 58 | print("load model successfully") 59 | model.eval() 60 | model = model.to(device) 61 | 62 | image_filenames = [line.rstrip() for line in open(os.path.join(imageLists))] 63 | 64 | # process each image 65 | j = 0 66 | for img_idx in range(len(image_filenames)): 67 | 68 | img_name = os.path.basename(image_filenames[img_idx]) 69 | img = dataload_test(image_filenames[img_idx]).to(device) 70 | folder = image_filenames[img_idx].split('/')[-2] 71 | util.mkdirs(os.path.join(save_folder,folder)) 72 | # if img_right.shape[3] < 1000: 73 | # continue 74 | # for tx in range(2): 75 | # img_left = img_left_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_left_ori.shape[3])] 76 | # img_right = img_right_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_right_ori.shape[3])] 77 | 78 | output = forward_eval(model,img) 79 | output = util.tensor2img(output.squeeze(0)) 80 | 81 | if save_imgs: 82 | 83 | cv2.imwrite(osp.join(save_folder,folder,img_name), output) 84 | 85 | 86 | j = j + 1 87 | print("process %d th image" % j) 88 | 89 | print('################ Finish Testing ################') 90 | 91 | 92 | 93 | if __name__ == '__main__': 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('--root', type=str, default='/data/1760921465/NTIRE2021/SR/test_input/', metavar='PATH', help='validation dataset root dir') 96 | parser.add_argument('--imageLists', type=str, default='/code/UEN/data/srtest_input.txt', metavar='FILE', help='record video ids') 97 | parser.add_argument('--save_folder', type=str, default='/data/1760921465/NTIRE2021/SR/GFN_test', metavar='PATH', help='save results') 98 | parser.add_argument('--modelPath', type=str, default='/model/1760921465/NTIRE2021/SR/GFN.pth', help='Model path') 99 | 100 | args = parser.parse_args() 101 | 102 | root = args.root 103 | imageLists = args.imageLists 104 | save_folder = args.save_folder 105 | modelPath = args.modelPath 106 | 107 | main(root, save_folder, imageLists, modelPath) 108 | -------------------------------------------------------------------------------- /FastFourierMSEC/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | logger = logging.getLogger('base') 3 | 4 | 5 | def create_model(opt): 6 | # image restoration 7 | model = opt['model'] 8 | if model == 'sr': 9 | from .SIEN_model import SIEN_Model as M 10 | else: 11 | raise NotImplementedError('Model [{:s}] not recognized.'.format(model)) 12 | m = M(opt) 13 | logger.info('Model [{:s}] is created.'.format(m.__class__.__name__)) 14 | return m 15 | 16 | -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/SIEN_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/SIEN_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/base_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/base_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/loss.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/loss.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/loss_new.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/loss_new.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/lr_scheduler.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/lr_scheduler.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/__pycache__/networks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/__pycache__/networks.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__init__.py -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EDVR_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EDVR_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EDVR_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EDVR_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/EnhanceN_arch2.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/arch_util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/arch_util1.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/arch_util1.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/__pycache__/layer.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/models/archs/__pycache__/layer.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/arch_util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Adobe Inc. All rights reserved. 2 | # 3 | # This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4 | # 4.0 International Public License. To view a copy of this license, visit 5 | # https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode. 6 | 7 | 8 | 9 | ######## https://github.com/adobe/antialiased-cnns/blob/master/models_lpf/__init__.py 10 | 11 | 12 | 13 | import torch 14 | import torch.nn.parallel 15 | import numpy as np 16 | import torch.nn as nn 17 | import torch.nn.functional as F 18 | 19 | class Downsample(nn.Module): 20 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 21 | super(Downsample, self).__init__() 22 | self.filt_size = filt_size 23 | self.pad_off = pad_off 24 | self.pad_sizes = [int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2)), int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2))] 25 | self.pad_sizes = [pad_size+pad_off for pad_size in self.pad_sizes] 26 | self.stride = stride 27 | self.off = int((self.stride-1)/2.) 28 | self.channels = channels 29 | 30 | # print('Filter size [%i]'%filt_size) 31 | if(self.filt_size==1): 32 | a = np.array([1.,]) 33 | elif(self.filt_size==2): 34 | a = np.array([1., 1.]) 35 | elif(self.filt_size==3): 36 | a = np.array([1., 2., 1.]) 37 | elif(self.filt_size==4): 38 | a = np.array([1., 3., 3., 1.]) 39 | elif(self.filt_size==5): 40 | a = np.array([1., 4., 6., 4., 1.]) 41 | elif(self.filt_size==6): 42 | a = np.array([1., 5., 10., 10., 5., 1.]) 43 | elif(self.filt_size==7): 44 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 45 | 46 | filt = torch.Tensor(a[:,None]*a[None,:]) 47 | filt = filt/torch.sum(filt) 48 | self.register_buffer('filt', filt[None,None,:,:].repeat((self.channels,1,1,1))) 49 | 50 | self.pad = get_pad_layer(pad_type)(self.pad_sizes) 51 | 52 | def forward(self, inp): 53 | if(self.filt_size==1): 54 | if(self.pad_off==0): 55 | return inp[:,:,::self.stride,::self.stride] 56 | else: 57 | return self.pad(inp)[:,:,::self.stride,::self.stride] 58 | else: 59 | return F.conv2d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 60 | 61 | def get_pad_layer(pad_type): 62 | if(pad_type in ['refl','reflect']): 63 | PadLayer = nn.ReflectionPad2d 64 | elif(pad_type in ['repl','replicate']): 65 | PadLayer = nn.ReplicationPad2d 66 | elif(pad_type=='zero'): 67 | PadLayer = nn.ZeroPad2d 68 | else: 69 | print('Pad type [%s] not recognized'%pad_type) 70 | return PadLayer 71 | 72 | 73 | class Downsample1D(nn.Module): 74 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 75 | super(Downsample1D, self).__init__() 76 | self.filt_size = filt_size 77 | self.pad_off = pad_off 78 | self.pad_sizes = [int(1. * (filt_size - 1) / 2), int(np.ceil(1. * (filt_size - 1) / 2))] 79 | self.pad_sizes = [pad_size + pad_off for pad_size in self.pad_sizes] 80 | self.stride = stride 81 | self.off = int((self.stride - 1) / 2.) 82 | self.channels = channels 83 | 84 | # print('Filter size [%i]' % filt_size) 85 | if(self.filt_size == 1): 86 | a = np.array([1., ]) 87 | elif(self.filt_size == 2): 88 | a = np.array([1., 1.]) 89 | elif(self.filt_size == 3): 90 | a = np.array([1., 2., 1.]) 91 | elif(self.filt_size == 4): 92 | a = np.array([1., 3., 3., 1.]) 93 | elif(self.filt_size == 5): 94 | a = np.array([1., 4., 6., 4., 1.]) 95 | elif(self.filt_size == 6): 96 | a = np.array([1., 5., 10., 10., 5., 1.]) 97 | elif(self.filt_size == 7): 98 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 99 | 100 | filt = torch.Tensor(a) 101 | filt = filt / torch.sum(filt) 102 | self.register_buffer('filt', filt[None, None, :].repeat((self.channels, 1, 1))) 103 | 104 | self.pad = get_pad_layer_1d(pad_type)(self.pad_sizes) 105 | 106 | def forward(self, inp): 107 | if(self.filt_size == 1): 108 | if(self.pad_off == 0): 109 | return inp[:, :, ::self.stride] 110 | else: 111 | return self.pad(inp)[:, :, ::self.stride] 112 | else: 113 | return F.conv1d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 114 | 115 | 116 | def get_pad_layer_1d(pad_type): 117 | if(pad_type in ['refl', 'reflect']): 118 | PadLayer = nn.ReflectionPad1d 119 | elif(pad_type in ['repl', 'replicate']): 120 | PadLayer = nn.ReplicationPad1d 121 | elif(pad_type == 'zero'): 122 | PadLayer = nn.ZeroPad1d 123 | else: 124 | print('Pad type [%s] not recognized' % pad_type) 125 | return PadLayer -------------------------------------------------------------------------------- /FastFourierMSEC/models/archs/discriminator_vgg_arch.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torchvision 4 | 5 | 6 | class Discriminator_VGG_128(nn.Module): 7 | def __init__(self, in_nc, nf): 8 | super(Discriminator_VGG_128, self).__init__() 9 | # [64, 128, 128] 10 | self.conv0_0 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True) 11 | self.conv0_1 = nn.Conv2d(nf, nf, 4, 2, 1, bias=False) 12 | self.bn0_1 = nn.BatchNorm2d(nf, affine=True) 13 | # [64, 64, 64] 14 | self.conv1_0 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=False) 15 | self.bn1_0 = nn.BatchNorm2d(nf * 2, affine=True) 16 | self.conv1_1 = nn.Conv2d(nf * 2, nf * 2, 4, 2, 1, bias=False) 17 | self.bn1_1 = nn.BatchNorm2d(nf * 2, affine=True) 18 | # [128, 32, 32] 19 | self.conv2_0 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=False) 20 | self.bn2_0 = nn.BatchNorm2d(nf * 4, affine=True) 21 | self.conv2_1 = nn.Conv2d(nf * 4, nf * 4, 4, 2, 1, bias=False) 22 | self.bn2_1 = nn.BatchNorm2d(nf * 4, affine=True) 23 | # [256, 16, 16] 24 | self.conv3_0 = nn.Conv2d(nf * 4, nf * 8, 3, 1, 1, bias=False) 25 | self.bn3_0 = nn.BatchNorm2d(nf * 8, affine=True) 26 | self.conv3_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 27 | self.bn3_1 = nn.BatchNorm2d(nf * 8, affine=True) 28 | # [512, 8, 8] 29 | self.conv4_0 = nn.Conv2d(nf * 8, nf * 8, 3, 1, 1, bias=False) 30 | self.bn4_0 = nn.BatchNorm2d(nf * 8, affine=True) 31 | self.conv4_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 32 | self.bn4_1 = nn.BatchNorm2d(nf * 8, affine=True) 33 | 34 | self.linear1 = nn.Linear(512 * 4 * 4, 100) 35 | self.linear2 = nn.Linear(100, 1) 36 | 37 | # activation function 38 | self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) 39 | 40 | def forward(self, x): 41 | fea = self.lrelu(self.conv0_0(x)) 42 | fea = self.lrelu(self.bn0_1(self.conv0_1(fea))) 43 | 44 | fea = self.lrelu(self.bn1_0(self.conv1_0(fea))) 45 | fea = self.lrelu(self.bn1_1(self.conv1_1(fea))) 46 | 47 | fea = self.lrelu(self.bn2_0(self.conv2_0(fea))) 48 | fea = self.lrelu(self.bn2_1(self.conv2_1(fea))) 49 | 50 | fea = self.lrelu(self.bn3_0(self.conv3_0(fea))) 51 | fea = self.lrelu(self.bn3_1(self.conv3_1(fea))) 52 | 53 | fea = self.lrelu(self.bn4_0(self.conv4_0(fea))) 54 | fea = self.lrelu(self.bn4_1(self.conv4_1(fea))) 55 | 56 | fea = fea.view(fea.size(0), -1) 57 | fea = self.lrelu(self.linear1(fea)) 58 | out = self.linear2(fea) 59 | return out 60 | 61 | 62 | class VGGFeatureExtractor(nn.Module): 63 | def __init__(self, feature_layer=34, use_bn=False, use_input_norm=True, 64 | device=torch.device('cpu')): 65 | super(VGGFeatureExtractor, self).__init__() 66 | self.use_input_norm = use_input_norm 67 | if use_bn: 68 | model = torchvision.models.vgg19_bn(pretrained=True) 69 | else: 70 | model = torchvision.models.vgg19(pretrained=True) 71 | if self.use_input_norm: 72 | mean = torch.Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1).to(device) 73 | # [0.485 - 1, 0.456 - 1, 0.406 - 1] if input in range [-1, 1] 74 | std = torch.Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1).to(device) 75 | # [0.229 * 2, 0.224 * 2, 0.225 * 2] if input in range [-1, 1] 76 | self.register_buffer('mean', mean) 77 | self.register_buffer('std', std) 78 | self.features = nn.Sequential(*list(model.features.children())[:(feature_layer + 1)]) 79 | # No need to BP to variable 80 | for k, v in self.features.named_parameters(): 81 | v.requires_grad = False 82 | 83 | def forward(self, x): 84 | # Assume input range is [0, 1] 85 | if self.use_input_norm: 86 | x = (x - self.mean) / self.std 87 | output = self.features(x) 88 | return output 89 | -------------------------------------------------------------------------------- /FastFourierMSEC/models/loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class CharbonnierLoss(nn.Module): 6 | """Charbonnier Loss (L1)""" 7 | 8 | def __init__(self, eps=1e-6): 9 | super(CharbonnierLoss, self).__init__() 10 | self.eps = eps 11 | 12 | def forward(self, x, y): 13 | diff = x - y 14 | loss = torch.sum(torch.sqrt(diff * diff + self.eps)) 15 | return loss 16 | 17 | 18 | # Define GAN loss: [vanilla | lsgan | wgan-gp] 19 | class GANLoss(nn.Module): 20 | def __init__(self, gan_type, real_label_val=1.0, fake_label_val=0.0): 21 | super(GANLoss, self).__init__() 22 | self.gan_type = gan_type.lower() 23 | self.real_label_val = real_label_val 24 | self.fake_label_val = fake_label_val 25 | 26 | if self.gan_type == 'gan' or self.gan_type == 'ragan': 27 | self.loss = nn.BCEWithLogitsLoss() 28 | elif self.gan_type == 'lsgan': 29 | self.loss = nn.MSELoss() 30 | elif self.gan_type == 'wgan-gp': 31 | 32 | def wgan_loss(input, target): 33 | # target is boolean 34 | return -1 * input.mean() if target else input.mean() 35 | 36 | self.loss = wgan_loss 37 | else: 38 | raise NotImplementedError('GAN type [{:s}] is not found'.format(self.gan_type)) 39 | 40 | def get_target_label(self, input, target_is_real): 41 | if self.gan_type == 'wgan-gp': 42 | return target_is_real 43 | if target_is_real: 44 | return torch.empty_like(input).fill_(self.real_label_val) 45 | else: 46 | return torch.empty_like(input).fill_(self.fake_label_val) 47 | 48 | def forward(self, input, target_is_real): 49 | target_label = self.get_target_label(input, target_is_real) 50 | loss = self.loss(input, target_label) 51 | return loss 52 | 53 | 54 | class GradientPenaltyLoss(nn.Module): 55 | def __init__(self, device=torch.device('cpu')): 56 | super(GradientPenaltyLoss, self).__init__() 57 | self.register_buffer('grad_outputs', torch.Tensor()) 58 | self.grad_outputs = self.grad_outputs.to(device) 59 | 60 | def get_grad_outputs(self, input): 61 | if self.grad_outputs.size() != input.size(): 62 | self.grad_outputs.resize_(input.size()).fill_(1.0) 63 | return self.grad_outputs 64 | 65 | def forward(self, interp, interp_crit): 66 | grad_outputs = self.get_grad_outputs(interp_crit) 67 | grad_interp = torch.autograd.grad(outputs=interp_crit, inputs=interp, 68 | grad_outputs=grad_outputs, create_graph=True, 69 | retain_graph=True, only_inputs=True)[0] 70 | grad_interp = grad_interp.view(grad_interp.size(0), -1) 71 | grad_interp_norm = grad_interp.norm(2, dim=1) 72 | 73 | loss = ((grad_interp_norm - 1)**2).mean() 74 | return loss 75 | 76 | 77 | class AMPLoss(nn.Module): 78 | def __init__(self): 79 | super(AMPLoss, self).__init__() 80 | self.cri = nn.L1Loss() 81 | 82 | def forward(self, x, y): 83 | x = torch.fft.rfft2(x, norm='backward') 84 | x_mag = torch.abs(x) 85 | y = torch.fft.rfft2(y, norm='backward') 86 | y_mag = torch.abs(y) 87 | 88 | return self.cri(x_mag,y_mag) 89 | 90 | 91 | class PhaLoss(nn.Module): 92 | def __init__(self): 93 | super(PhaLoss, self).__init__() 94 | self.cri = nn.L1Loss() 95 | 96 | def forward(self, x, y): 97 | x = torch.fft.rfft2(x, norm='backward') 98 | x_mag = torch.angle(x) 99 | y = torch.fft.rfft2(y, norm='backward') 100 | y_mag = torch.angle(y) 101 | 102 | return self.cri(x_mag, y_mag) 103 | 104 | class FourierLoss(nn.Module): 105 | def __init__(self): 106 | super(FourierLoss, self).__init__() 107 | self.cri = nn.L1Loss() 108 | 109 | def forward(self, x, y): 110 | x = torch.fft.rfft2(x, norm='backward') 111 | x_amp = torch.abs(x) 112 | x_pha = torch.angle(x) 113 | y = torch.fft.rfft2(y, norm='backward') 114 | y_amp = torch.abs(y) 115 | y_pha = torch.angle(y) 116 | 117 | x_fourier = torch.cat([x_amp,x_pha],1) 118 | y_fourier = torch.cat([y_amp,y_pha],1) 119 | 120 | return self.cri(x_fourier,y_fourier) -------------------------------------------------------------------------------- /FastFourierMSEC/models/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import models.archs.discriminator_vgg_arch as SRGAN_arch 3 | import models.archs.EnhanceN_arch as EnhanceN_arch 4 | import models.archs.EnhanceN_arch1 as EnhanceN_arch1 5 | 6 | 7 | # Generator 8 | def define_G(opt): 9 | opt_net = opt['network_G'] 10 | which_model = opt_net['which_model_G'] 11 | 12 | # video restoration 13 | if which_model == 'Net': 14 | netG = EnhanceN_arch.InteractNet(nc=opt_net['nc']) 15 | elif which_model == 'Net1': 16 | netG = EnhanceN_arch1.InteractNet(nc=opt_net['nc']) 17 | else: 18 | raise NotImplementedError('Generator model [{:s}] not recognized'.format(which_model)) 19 | 20 | return netG 21 | 22 | 23 | # Discriminator 24 | def define_D(opt): 25 | opt_net = opt['network_D'] 26 | which_model = opt_net['which_model_D'] 27 | 28 | if which_model == 'discriminator_vgg_128': 29 | netD = SRGAN_arch.Discriminator_VGG_128(in_nc=opt_net['in_nc'], nf=opt_net['nf']) 30 | else: 31 | raise NotImplementedError('Discriminator model [{:s}] not recognized'.format(which_model)) 32 | return netD 33 | 34 | 35 | # Define network used for perceptual loss 36 | def define_F(opt, use_bn=False): 37 | gpu_ids = opt['gpu_ids'] 38 | device = torch.device('cuda' if gpu_ids else 'cpu') 39 | # PyTorch pretrained VGG19-54, before ReLU. 40 | if use_bn: 41 | feature_layer = 49 42 | else: 43 | feature_layer = 34 44 | netF = SRGAN_arch.VGGFeatureExtractor(feature_layer=feature_layer, use_bn=use_bn, 45 | use_input_norm=True, device=device) 46 | netF.eval() # No need to train 47 | return netF 48 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/options/__init__.py -------------------------------------------------------------------------------- /FastFourierMSEC/options/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/options/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/options/__pycache__/options.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/options/__pycache__/options.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/options/options.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as osp 3 | import logging 4 | import yaml 5 | from utils.util import OrderedYaml 6 | Loader, Dumper = OrderedYaml() 7 | 8 | 9 | def parse(opt_path, is_train=True): 10 | with open(opt_path, mode='r') as f: 11 | opt = yaml.load(f, Loader=Loader) 12 | # export CUDA_VISIBLE_DEVICES 13 | gpu_list = ','.join(str(x) for x in opt['gpu_ids']) 14 | os.environ['CUDA_VISIBLE_DEVICES'] = gpu_list 15 | print('export CUDA_VISIBLE_DEVICES=' + gpu_list) 16 | 17 | opt['is_train'] = is_train 18 | if opt['distortion'] == 'sr': 19 | scale = opt['scale'] 20 | 21 | # datasets 22 | for phase, dataset in opt['datasets'].items(): 23 | phase = phase.split('_')[0] 24 | dataset['phase'] = phase 25 | if opt['distortion'] == 'sr': 26 | dataset['scale'] = scale 27 | is_lmdb = False 28 | if dataset.get('dataroot_GT', None) is not None: 29 | dataset['dataroot_GT'] = osp.expanduser(dataset['dataroot_GT']) 30 | if dataset['dataroot_GT'].endswith('lmdb'): 31 | is_lmdb = True 32 | if dataset.get('dataroot_LQ', None) is not None: 33 | dataset['dataroot_LQ'] = osp.expanduser(dataset['dataroot_LQ']) 34 | if dataset['dataroot_LQ'].endswith('lmdb'): 35 | is_lmdb = True 36 | dataset['data_type'] = 'lmdb' if is_lmdb else 'img' 37 | if dataset['mode'].endswith('mc'): # for memcached 38 | dataset['data_type'] = 'mc' 39 | dataset['mode'] = dataset['mode'].replace('_mc', '') 40 | 41 | # path 42 | for key, path in opt['path'].items(): 43 | if path and key in opt['path'] and key != 'strict_load': 44 | opt['path'][key] = osp.expanduser(path) 45 | # opt['path']['root'] = '/home/zhanghc/IEEEyellow/code_enhance/checkpoints' 46 | if is_train: 47 | experiments_root = osp.join(opt['path']['root'], 'experiments', opt['name']) 48 | opt['path']['experiments_root'] = experiments_root 49 | opt['path']['models'] = osp.join(experiments_root, 'models') 50 | opt['path']['training_state'] = osp.join(experiments_root, 'training_state') 51 | opt['path']['log'] = experiments_root 52 | opt['path']['val_images'] = osp.join(experiments_root, 'val_images') 53 | 54 | # change some options for debug mode 55 | if 'debug' in opt['name']: 56 | opt['train']['val_freq'] = 8 57 | opt['logger']['print_freq'] = 1 58 | opt['logger']['save_checkpoint_freq'] = 8 59 | else: # test 60 | results_root = osp.join(opt['path']['root'], 'results', opt['name']) 61 | opt['path']['results_root'] = results_root 62 | opt['path']['log'] = results_root 63 | 64 | # network 65 | if opt['distortion'] == 'sr': 66 | opt['network_G']['scale'] = scale 67 | 68 | return opt 69 | 70 | 71 | def dict2str(opt, indent_l=1): 72 | '''dict to string for logger''' 73 | msg = '' 74 | for k, v in opt.items(): 75 | if isinstance(v, dict): 76 | msg += ' ' * (indent_l * 2) + k + ':[\n' 77 | msg += dict2str(v, indent_l + 1) 78 | msg += ' ' * (indent_l * 2) + ']\n' 79 | else: 80 | msg += ' ' * (indent_l * 2) + k + ': ' + str(v) + '\n' 81 | return msg 82 | 83 | 84 | class NoneDict(dict): 85 | def __missing__(self, key): 86 | return None 87 | 88 | 89 | # convert to NoneDict, which return None for missing key. 90 | def dict_to_nonedict(opt): 91 | if isinstance(opt, dict): 92 | new_opt = dict() 93 | for key, sub_opt in opt.items(): 94 | new_opt[key] = dict_to_nonedict(sub_opt) 95 | return NoneDict(**new_opt) 96 | elif isinstance(opt, list): 97 | return [dict_to_nonedict(sub_opt) for sub_opt in opt] 98 | else: 99 | return opt 100 | 101 | 102 | def check_resume(opt, resume_iter): 103 | '''Check resume states and pretrain_model paths''' 104 | logger = logging.getLogger('base') 105 | if opt['path']['resume_state']: 106 | if opt['path'].get('pretrain_model_G', None) is not None or opt['path'].get( 107 | 'pretrain_model_D', None) is not None: 108 | logger.warning('pretrain_model path will be ignored when resuming training.') 109 | 110 | opt['path']['pretrain_model_G'] = osp.join(opt['path']['models'], 111 | '{}_G.pth'.format(resume_iter)) 112 | logger.info('Set [pretrain_model_G] to ' + opt['path']['pretrain_model_G']) 113 | if 'gan' in opt['model']: 114 | opt['path']['pretrain_model_D'] = osp.join(opt['path']['models'], 115 | '{}_D.pth'.format(resume_iter)) 116 | logger.info('Set [pretrain_model_D] to ' + opt['path']['pretrain_model_D']) 117 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/test/test_ESRGAN.yml: -------------------------------------------------------------------------------- 1 | name: RRDB_ESRGAN_x4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: RRDBNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 23 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/RRDB_ESRGAN_x4.pth 33 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/test/test_SRGAN.yml: -------------------------------------------------------------------------------- 1 | name: MSRGANx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: MSRResNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 16 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/MSRGANx4.pth 33 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/test/test_SRResNet.yml: -------------------------------------------------------------------------------- 1 | name: MSRResNetx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | test_3: 21 | name: bsd100 22 | mode: LQGT 23 | dataroot_GT: ../datasets/BSD/BSDS100 24 | dataroot_LQ: ../datasets/BSD/BSDS100_bicLRx4 25 | test_4: 26 | name: urban100 27 | mode: LQGT 28 | dataroot_GT: ../datasets/urban100 29 | dataroot_LQ: ../datasets/urban100_bicLRx4 30 | test_5: 31 | name: div2k100 32 | mode: LQGT 33 | dataroot_GT: ../datasets/DIV2K100/DIV2K_valid_HR 34 | dataroot_LQ: ../datasets/DIV2K100/DIV2K_valid_bicLRx4 35 | 36 | 37 | #### network structures 38 | network_G: 39 | which_model_G: MSRResNet 40 | in_nc: 3 41 | out_nc: 3 42 | nf: 64 43 | nb: 16 44 | upscale: 4 45 | 46 | #### path 47 | path: 48 | pretrain_model_G: ../experiments/pretrained_models/MSRResNetx4.pth 49 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/train/train_Enhance.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [0] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/groups_train_mixexposure.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 8 24 | IN_size: 384 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/groups_valid_mixexposure.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/output 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/output 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/pretrain1 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/SOTA_Finals1/models/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | train: 54 | lr_G: 0.0004 55 | lr_scheme: MultiStepLR 56 | beta1: 0.9 57 | beta2: 0.99 58 | niter: 353600 59 | ewc: False 60 | distill: False 61 | ewc_coff: 8.0 62 | distill_coff: 0.05 63 | fix_some_part: ~ 64 | warmup_iter: -1 65 | ComputeImportance: False 66 | istraining: True 67 | lr_steps: [176800, 265200] 68 | lr_gamma: 0.5 69 | eta_min: 5e-06 70 | pixel_criterion: l1 71 | pixel_weight: 5000.0 72 | ssim_weight: 1000.0 73 | vgg_weight: 1000.0 74 | val_epoch: 1.0 75 | manual_seed: 0 76 | 77 | #### logger 78 | logger: 79 | print_freq: 80 80 | save_checkpoint_epoch: !!float 100 81 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/train/train_Enhance1.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [1] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/groups_train_mixexposure.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 6 24 | IN_size: 384 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/data/groups_valid_mixexposure.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net1 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/output1 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/output1 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/pretrain1 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourierExp1/SOTA_Finals/models/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | train: 54 | lr_G: 0.00007 55 | lr_scheme: MultiStepLR 56 | beta1: 0.9 57 | beta2: 0.99 58 | niter: 120000 59 | ewc: False 60 | distill: False 61 | ewc_coff: 8.0 62 | distill_coff: 0.05 63 | fix_some_part: ~ 64 | warmup_iter: -1 65 | ComputeImportance: False 66 | istraining: True 67 | lr_steps: [40000, 80000] 68 | lr_gamma: 0.5 69 | eta_min: 5e-06 70 | pixel_criterion: l1 71 | pixel_weight: 5000.0 72 | ssim_weight: 1000.0 73 | vgg_weight: 1000.0 74 | val_epoch: 1.0 75 | manual_seed: 0 76 | 77 | #### logger 78 | logger: 79 | print_freq: 80 80 | save_checkpoint_epoch: !!float 100 81 | -------------------------------------------------------------------------------- /FastFourierMSEC/options/train/train_Enhance2.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [1] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/Continous/UEN_DRBN/data/groups_train_mixSICEV2.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 256 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/Continous/UEN_DRBN/data/groups_test_mixSICEV2.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: DRBNIN3 41 | nf: 16 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/Continous/UEN_DRBN/output_DRBNIN3 47 | results_root: /home/jieh/Projects/Continous/UEN_DRBN/output_DRBNIN3 48 | pretrain: /home/jieh/Projects/Continous/UEN_DRBN/pretrain1 49 | pretrain_model_G: /home/jieh/Projects/Continous/UEN_DRBN/pretrain1/0_best.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 1e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 51200 60 | ewc: false 61 | distill: false 62 | ewc_coff: 50.0 63 | distill_coff: 0.05 64 | fix_some_part: ~ 65 | warmup_iter: -1 # -1: no warm up 66 | ComputeImportance: false 67 | istraining: true 68 | #### for cosine adjustment 69 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 70 | # restarts: [400000, 1400000, 2700000, 4200000] 71 | # restart_weights: [1, 1, 1, 1] 72 | lr_scheme: MultiStepLR 73 | lr_steps: [25600, 38400] 74 | lr_gamma: 0.5 75 | 76 | eta_min: !!float 5e-6 77 | pixel_criterion: l1 78 | pixel_weight: 5000.0 79 | ssim_weight: 1000.0 80 | vgg_weight: 1000.0 81 | 82 | val_epoch: !!float 1 83 | manual_seed: 0 84 | 85 | #### logger 86 | logger: 87 | print_freq: 40 88 | save_checkpoint_epoch: !!float 10 89 | -------------------------------------------------------------------------------- /FastFourierMSEC/pretrain/0_bestavg.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/pretrain/0_bestavg.pth -------------------------------------------------------------------------------- /FastFourierMSEC/scripts/back_projection/backprojection.m: -------------------------------------------------------------------------------- 1 | function [im_h] = backprojection(im_h, im_l, maxIter) 2 | 3 | [row_l, col_l,~] = size(im_l); 4 | [row_h, col_h,~] = size(im_h); 5 | 6 | p = fspecial('gaussian', 5, 1); 7 | p = p.^2; 8 | p = p./sum(p(:)); 9 | 10 | im_l = double(im_l); 11 | im_h = double(im_h); 12 | 13 | for ii = 1:maxIter 14 | im_l_s = imresize(im_h, [row_l, col_l], 'bicubic'); 15 | im_diff = im_l - im_l_s; 16 | im_diff = imresize(im_diff, [row_h, col_h], 'bicubic'); 17 | im_h(:,:,1) = im_h(:,:,1) + conv2(im_diff(:,:,1), p, 'same'); 18 | im_h(:,:,2) = im_h(:,:,2) + conv2(im_diff(:,:,2), p, 'same'); 19 | im_h(:,:,3) = im_h(:,:,3) + conv2(im_diff(:,:,3), p, 'same'); 20 | end 21 | -------------------------------------------------------------------------------- /FastFourierMSEC/scripts/back_projection/main_bp.m: -------------------------------------------------------------------------------- 1 | clear; close all; clc; 2 | 3 | LR_folder = './LR'; % LR 4 | preout_folder = './results'; % pre output 5 | save_folder = './results_20bp'; 6 | filepaths = dir(fullfile(preout_folder, '*.png')); 7 | max_iter = 20; 8 | 9 | if ~ exist(save_folder, 'dir') 10 | mkdir(save_folder); 11 | end 12 | 13 | for idx_im = 1:length(filepaths) 14 | fprintf([num2str(idx_im) '\n']); 15 | im_name = filepaths(idx_im).name; 16 | im_LR = im2double(imread(fullfile(LR_folder, im_name))); 17 | im_out = im2double(imread(fullfile(preout_folder, im_name))); 18 | %tic 19 | im_out = backprojection(im_out, im_LR, max_iter); 20 | %toc 21 | imwrite(im_out, fullfile(save_folder, im_name)); 22 | end 23 | -------------------------------------------------------------------------------- /FastFourierMSEC/scripts/back_projection/main_reverse_filter.m: -------------------------------------------------------------------------------- 1 | clear; close all; clc; 2 | 3 | LR_folder = './LR'; % LR 4 | preout_folder = './results'; % pre output 5 | save_folder = './results_20if'; 6 | filepaths = dir(fullfile(preout_folder, '*.png')); 7 | max_iter = 20; 8 | 9 | if ~ exist(save_folder, 'dir') 10 | mkdir(save_folder); 11 | end 12 | 13 | for idx_im = 1:length(filepaths) 14 | fprintf([num2str(idx_im) '\n']); 15 | im_name = filepaths(idx_im).name; 16 | im_LR = im2double(imread(fullfile(LR_folder, im_name))); 17 | im_out = im2double(imread(fullfile(preout_folder, im_name))); 18 | J = imresize(im_LR,4,'bicubic'); 19 | %tic 20 | for m = 1:max_iter 21 | im_out = im_out + (J - imresize(imresize(im_out,1/4,'bicubic'),4,'bicubic')); 22 | end 23 | %toc 24 | imwrite(im_out, fullfile(save_folder, im_name)); 25 | end 26 | -------------------------------------------------------------------------------- /FastFourierMSEC/test.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import logging 3 | import time 4 | import argparse 5 | from collections import OrderedDict 6 | 7 | import options.options as option 8 | import utils.util as util 9 | from data.util import bgr2ycbcr 10 | from data import create_dataset, create_dataloader 11 | from models import create_model 12 | 13 | #### options 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('-opt', type=str, required=True, help='Path to options YMAL file.') 16 | opt = option.parse(parser.parse_args().opt, is_train=False) 17 | opt = option.dict_to_nonedict(opt) 18 | 19 | util.mkdirs( 20 | (path for key, path in opt['path'].items() 21 | if not key == 'experiments_root' and 'pretrain_model' not in key and 'resume' not in key)) 22 | util.setup_logger('base', opt['path']['log'], 'test_' + opt['name'], level=logging.INFO, 23 | screen=True, tofile=True) 24 | logger = logging.getLogger('base') 25 | logger.info(option.dict2str(opt)) 26 | 27 | #### Create test dataset and dataloader 28 | test_loaders = [] 29 | for phase, dataset_opt in sorted(opt['datasets'].items()): 30 | test_set = create_dataset(dataset_opt) 31 | test_loader = create_dataloader(test_set, dataset_opt) 32 | logger.info('Number of test images in [{:s}]: {:d}'.format(dataset_opt['name'], len(test_set))) 33 | test_loaders.append(test_loader) 34 | 35 | model = create_model(opt) 36 | for test_loader in test_loaders: 37 | test_set_name = test_loader.dataset.opt['name'] 38 | logger.info('\nTesting [{:s}]...'.format(test_set_name)) 39 | test_start_time = time.time() 40 | dataset_dir = osp.join(opt['path']['results_root'], test_set_name) 41 | util.mkdir(dataset_dir) 42 | 43 | test_results = OrderedDict() 44 | test_results['psnr'] = [] 45 | test_results['ssim'] = [] 46 | test_results['psnr_y'] = [] 47 | test_results['ssim_y'] = [] 48 | 49 | for data in test_loader: 50 | need_GT = False if test_loader.dataset.opt['dataroot_GT'] is None else True 51 | model.feed_data(data, need_GT=need_GT) 52 | img_path = data['GT_path'][0] if need_GT else data['LQ_path'][0] 53 | img_name = osp.splitext(osp.basename(img_path))[0] 54 | 55 | model.test() 56 | visuals = model.get_current_visuals(need_GT=need_GT) 57 | 58 | sr_img = util.tensor2img(visuals['rlt']) # uint8 59 | 60 | # save images 61 | suffix = opt['suffix'] 62 | if suffix: 63 | save_img_path = osp.join(dataset_dir, img_name + suffix + '.png') 64 | else: 65 | save_img_path = osp.join(dataset_dir, img_name + '.png') 66 | util.save_img(sr_img, save_img_path) 67 | 68 | # calculate PSNR and SSIM 69 | if need_GT: 70 | gt_img = util.tensor2img(visuals['GT']) 71 | sr_img, gt_img = util.crop_border([sr_img, gt_img], opt['scale']) 72 | psnr = util.calculate_psnr(sr_img, gt_img) 73 | ssim = util.calculate_ssim(sr_img, gt_img) 74 | test_results['psnr'].append(psnr) 75 | test_results['ssim'].append(ssim) 76 | 77 | if gt_img.shape[2] == 3: # RGB image 78 | sr_img_y = bgr2ycbcr(sr_img / 255., only_y=True) 79 | gt_img_y = bgr2ycbcr(gt_img / 255., only_y=True) 80 | 81 | psnr_y = util.calculate_psnr(sr_img_y * 255, gt_img_y * 255) 82 | ssim_y = util.calculate_ssim(sr_img_y * 255, gt_img_y * 255) 83 | test_results['psnr_y'].append(psnr_y) 84 | test_results['ssim_y'].append(ssim_y) 85 | logger.info( 86 | '{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}; PSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}.'. 87 | format(img_name, psnr, ssim, psnr_y, ssim_y)) 88 | else: 89 | logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}.'.format(img_name, psnr, ssim)) 90 | else: 91 | logger.info(img_name) 92 | 93 | if need_GT: # metrics 94 | # Average PSNR/SSIM results 95 | ave_psnr = sum(test_results['psnr']) / len(test_results['psnr']) 96 | ave_ssim = sum(test_results['ssim']) / len(test_results['ssim']) 97 | logger.info( 98 | '----Average PSNR/SSIM results for {}----\n\tPSNR: {:.6f} dB; SSIM: {:.6f}\n'.format( 99 | test_set_name, ave_psnr, ave_ssim)) 100 | if test_results['psnr_y'] and test_results['ssim_y']: 101 | ave_psnr_y = sum(test_results['psnr_y']) / len(test_results['psnr_y']) 102 | ave_ssim_y = sum(test_results['ssim_y']) / len(test_results['ssim_y']) 103 | logger.info( 104 | '----Y channel, average PSNR/SSIM----\n\tPSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}\n'. 105 | format(ave_psnr_y, ave_ssim_y)) 106 | -------------------------------------------------------------------------------- /FastFourierMSEC/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/utils/__init__.py -------------------------------------------------------------------------------- /FastFourierMSEC/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierMSEC/utils/__pycache__/util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierMSEC/utils/__pycache__/util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/create_txt.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | 4 | 5 | def mkdir(path): 6 | if not os.path.exists(path): 7 | os.mkdir(path) 8 | 9 | 10 | def main(): 11 | assert os.path.exists(inputdir), 'Input dir not found' 12 | assert os.path.exists(targetdir), 'target dir not found' 13 | mkdir(outputdir) 14 | imgs = os.listdir(inputdir) 15 | for img in imgs: 16 | groups = '' 17 | 18 | groups += os.path.join(inputdir, img) + '|' 19 | groups += os.path.join(targetdir,img) 20 | 21 | with open(os.path.join(outputdir, 'groups_test_lowReFive.txt'), 'a') as f: 22 | f.write(groups + '\n') 23 | 24 | if __name__ == '__main__': 25 | parser = argparse.ArgumentParser() 26 | parser.add_argument('--input', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Low', metavar='PATH', help='root dir to save low resolution images') 27 | parser.add_argument('--target', type=str, default='/gdata/huangjie/Continous/ExpFive/test/Retouch', metavar='PATH', help='root dir to save high resolution images') 28 | parser.add_argument('--output', type=str, default='/ghome/huangjie/Continous/Baseline/', metavar='PATH', help='output dir to save group txt files') 29 | parser.add_argument('--ext', type=str, default='.png', help='Extension of files') 30 | args = parser.parse_args() 31 | 32 | inputdir = args.input 33 | targetdir = args.target 34 | outputdir = args.output 35 | ext = args.ext 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /FastFourierSICE/data/__init__.py: -------------------------------------------------------------------------------- 1 | """create dataset and dataloader""" 2 | import logging 3 | import torch 4 | import torch.utils.data 5 | 6 | 7 | def create_dataloader(dataset, dataset_opt, opt=None, sampler=None): 8 | phase = dataset_opt['phase'] 9 | if phase == 'train': 10 | num_workers = dataset_opt['n_workers'] * len(opt['gpu_ids']) 11 | batch_size = dataset_opt['batch_size'] 12 | # shuffle = True 13 | shuffle = dataset_opt['use_shuffle'] 14 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, 15 | num_workers=0, sampler=sampler, 16 | pin_memory=True) 17 | else: 18 | batch_size = dataset_opt['batch_size'] 19 | # shuffle = dataset_opt['use_shuffle'] 20 | shuffle = False 21 | return torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=0, 22 | pin_memory=False) 23 | 24 | 25 | def create_dataset(opt,dataset_opt): 26 | mode = dataset_opt['mode'] 27 | # datasets for image restoration 28 | if mode == 'UEN_train': 29 | from data.SIEN_dataset import DatasetFromFolder as D 30 | 31 | dataset = D(upscale_factor=opt['scale'], data_augmentation=dataset_opt['augment'], 32 | group_file=dataset_opt['filelist'], 33 | patch_size=dataset_opt['IN_size'], black_edges_crop=False, hflip=True, rot=True) 34 | 35 | elif mode == 'UEN_val': 36 | from data.SIEN_dataset import DatasetFromFolder as D 37 | dataset = D(upscale_factor=opt['scale'], data_augmentation=False, 38 | group_file=dataset_opt['filelist'], 39 | patch_size=None, black_edges_crop=False, hflip=False, rot=False) 40 | 41 | else: 42 | raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode)) 43 | 44 | 45 | logger = logging.getLogger('base') 46 | logger.info('Dataset [{:s} - {:s}] is created.'.format(dataset.__class__.__name__, 47 | dataset_opt['name'])) 48 | return dataset 49 | -------------------------------------------------------------------------------- /FastFourierSICE/data/__pycache__/SIEN_dataset.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/data/__pycache__/SIEN_dataset.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/data/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/data/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/data/shuffle.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | out = open("/ghome/huangjie/Continous/Baseline/groups_train_mixReFive.txt",'w') 4 | lines=[] 5 | with open("/ghome/huangjie/Continous/Baseline/mix.txt", 'r') as infile: 6 | for line in infile: 7 | lines.append(line) 8 | random.shuffle(lines) 9 | for line in lines: 10 | out.write(line) 11 | 12 | infile.close() 13 | out.close() 14 | 15 | -------------------------------------------------------------------------------- /FastFourierSICE/eval.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test Vid4 (SR) and REDS4 (SR-clean, SR-blur, deblur-clean, deblur-compression) datasets 3 | ''' 4 | import os 5 | import os.path as osp 6 | import glob 7 | import logging 8 | import numpy as np 9 | import cv2 10 | import torch 11 | import argparse 12 | import utils.util as util 13 | import data.util as data_util 14 | import models.archs.EnhanceN_arch as EnhanceN_arch 15 | 16 | def dataload_test(img_path): 17 | img_numpy = cv2.imread(img_path,cv2.IMREAD_UNCHANGED).astype(np.float32)/255.0 18 | # img_numpy = cv2.resize(img_numpy,(512,512)) 19 | img_numpy = img_numpy[:, :, [2, 1, 0]] 20 | img_numpy = torch.from_numpy(np.ascontiguousarray(np.transpose(img_numpy, (2, 0, 1)))).float() 21 | img_numpy = img_numpy.unsqueeze(0) 22 | return img_numpy 23 | 24 | 25 | def forward_eval(model,img): 26 | with torch.no_grad(): 27 | model_output = model(img,torch.cuda.FloatTensor().resize_(1).zero_()+1, 28 | torch.cuda.FloatTensor().resize_(1).zero_()+1) 29 | # if isinstance(model_output, list) or isinstance(model_output, tuple): 30 | output = model_output 31 | # else: 32 | # output = model_output 33 | output = output.data.float().cpu() 34 | 35 | return output 36 | 37 | 38 | def main(root, save_folder, imageLists, modelPath): 39 | ################# 40 | # configurations 41 | ################# 42 | device = torch.device('cuda') 43 | os.environ['CUDA_VISIBLE_DEVICES'] = '0' 44 | ############################################################################ 45 | #### model 46 | model_path = modelPath 47 | model = EnhanceN_arch.Net() 48 | 49 | #### dataset 50 | test_dataset_folder = root 51 | save_imgs = True 52 | util.mkdirs(save_folder) 53 | # util.setup_logger('base', save_folder, 'test', level=logging.INFO, screen=True, tofile=True) 54 | # logger = logging.getLogger('base') 55 | 56 | #### set up the models 57 | model.load_state_dict(torch.load(model_path), strict=True) 58 | print("load model successfully") 59 | model.eval() 60 | model = model.to(device) 61 | 62 | image_filenames = [line.rstrip() for line in open(os.path.join(imageLists))] 63 | 64 | # process each image 65 | j = 0 66 | for img_idx in range(len(image_filenames)): 67 | 68 | img_name = os.path.basename(image_filenames[img_idx]) 69 | img = dataload_test(image_filenames[img_idx]).to(device) 70 | folder = image_filenames[img_idx].split('/')[-2] 71 | util.mkdirs(os.path.join(save_folder,folder)) 72 | # if img_right.shape[3] < 1000: 73 | # continue 74 | # for tx in range(2): 75 | # img_left = img_left_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_left_ori.shape[3])] 76 | # img_right = img_right_ori[:, :, :, max(0, 736 * tx - 32):min(736 * (tx + 1) + 32, img_right_ori.shape[3])] 77 | 78 | output = forward_eval(model,img) 79 | output = util.tensor2img(output.squeeze(0)) 80 | 81 | if save_imgs: 82 | 83 | cv2.imwrite(osp.join(save_folder,folder,img_name), output) 84 | 85 | 86 | j = j + 1 87 | print("process %d th image" % j) 88 | 89 | print('################ Finish Testing ################') 90 | 91 | 92 | 93 | if __name__ == '__main__': 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('--root', type=str, default='/data/1760921465/NTIRE2021/SR/test_input/', metavar='PATH', help='validation dataset root dir') 96 | parser.add_argument('--imageLists', type=str, default='/code/UEN/data/srtest_input.txt', metavar='FILE', help='record video ids') 97 | parser.add_argument('--save_folder', type=str, default='/data/1760921465/NTIRE2021/SR/GFN_test', metavar='PATH', help='save results') 98 | parser.add_argument('--modelPath', type=str, default='/model/1760921465/NTIRE2021/SR/GFN.pth', help='Model path') 99 | 100 | args = parser.parse_args() 101 | 102 | root = args.root 103 | imageLists = args.imageLists 104 | save_folder = args.save_folder 105 | modelPath = args.modelPath 106 | 107 | main(root, save_folder, imageLists, modelPath) 108 | -------------------------------------------------------------------------------- /FastFourierSICE/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/metrics/__pycache__/calculate_PSNR_SSIM.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | logger = logging.getLogger('base') 3 | 4 | 5 | def create_model(opt): 6 | # image restoration 7 | model = opt['model'] 8 | if model == 'sr': 9 | from .SIEN_model import SIEN_Model as M 10 | else: 11 | raise NotImplementedError('Model [{:s}] not recognized.'.format(model)) 12 | m = M(opt) 13 | logger.info('Model [{:s}] is created.'.format(m.__class__.__name__)) 14 | return m 15 | 16 | -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/SIEN_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/SIEN_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/base_model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/base_model.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/loss.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/loss.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/loss_new.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/loss_new.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/lr_scheduler.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/lr_scheduler.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/__pycache__/networks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/__pycache__/networks.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__init__.py -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/EDVR_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/EDVR_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/EDVR_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/EDVR_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/EnhanceN_arch.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/EnhanceN_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/EnhanceN_arch1.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/arch_util.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/arch_util.cpython-35.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/arch_util.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/arch_util.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/arch_util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/arch_util.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/discriminator_vgg_arch.cpython-36.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/models/archs/__pycache__/discriminator_vgg_arch.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/arch_util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, Adobe Inc. All rights reserved. 2 | # 3 | # This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4 | # 4.0 International Public License. To view a copy of this license, visit 5 | # https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode. 6 | 7 | 8 | 9 | ######## https://github.com/adobe/antialiased-cnns/blob/master/models_lpf/__init__.py 10 | 11 | 12 | 13 | import torch 14 | import torch.nn.parallel 15 | import numpy as np 16 | import torch.nn as nn 17 | import torch.nn.functional as F 18 | 19 | class Downsample(nn.Module): 20 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 21 | super(Downsample, self).__init__() 22 | self.filt_size = filt_size 23 | self.pad_off = pad_off 24 | self.pad_sizes = [int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2)), int(1.*(filt_size-1)/2), int(np.ceil(1.*(filt_size-1)/2))] 25 | self.pad_sizes = [pad_size+pad_off for pad_size in self.pad_sizes] 26 | self.stride = stride 27 | self.off = int((self.stride-1)/2.) 28 | self.channels = channels 29 | 30 | # print('Filter size [%i]'%filt_size) 31 | if(self.filt_size==1): 32 | a = np.array([1.,]) 33 | elif(self.filt_size==2): 34 | a = np.array([1., 1.]) 35 | elif(self.filt_size==3): 36 | a = np.array([1., 2., 1.]) 37 | elif(self.filt_size==4): 38 | a = np.array([1., 3., 3., 1.]) 39 | elif(self.filt_size==5): 40 | a = np.array([1., 4., 6., 4., 1.]) 41 | elif(self.filt_size==6): 42 | a = np.array([1., 5., 10., 10., 5., 1.]) 43 | elif(self.filt_size==7): 44 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 45 | 46 | filt = torch.Tensor(a[:,None]*a[None,:]) 47 | filt = filt/torch.sum(filt) 48 | self.register_buffer('filt', filt[None,None,:,:].repeat((self.channels,1,1,1))) 49 | 50 | self.pad = get_pad_layer(pad_type)(self.pad_sizes) 51 | 52 | def forward(self, inp): 53 | if(self.filt_size==1): 54 | if(self.pad_off==0): 55 | return inp[:,:,::self.stride,::self.stride] 56 | else: 57 | return self.pad(inp)[:,:,::self.stride,::self.stride] 58 | else: 59 | return F.conv2d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 60 | 61 | def get_pad_layer(pad_type): 62 | if(pad_type in ['refl','reflect']): 63 | PadLayer = nn.ReflectionPad2d 64 | elif(pad_type in ['repl','replicate']): 65 | PadLayer = nn.ReplicationPad2d 66 | elif(pad_type=='zero'): 67 | PadLayer = nn.ZeroPad2d 68 | else: 69 | print('Pad type [%s] not recognized'%pad_type) 70 | return PadLayer 71 | 72 | 73 | class Downsample1D(nn.Module): 74 | def __init__(self, pad_type='reflect', filt_size=3, stride=2, channels=None, pad_off=0): 75 | super(Downsample1D, self).__init__() 76 | self.filt_size = filt_size 77 | self.pad_off = pad_off 78 | self.pad_sizes = [int(1. * (filt_size - 1) / 2), int(np.ceil(1. * (filt_size - 1) / 2))] 79 | self.pad_sizes = [pad_size + pad_off for pad_size in self.pad_sizes] 80 | self.stride = stride 81 | self.off = int((self.stride - 1) / 2.) 82 | self.channels = channels 83 | 84 | # print('Filter size [%i]' % filt_size) 85 | if(self.filt_size == 1): 86 | a = np.array([1., ]) 87 | elif(self.filt_size == 2): 88 | a = np.array([1., 1.]) 89 | elif(self.filt_size == 3): 90 | a = np.array([1., 2., 1.]) 91 | elif(self.filt_size == 4): 92 | a = np.array([1., 3., 3., 1.]) 93 | elif(self.filt_size == 5): 94 | a = np.array([1., 4., 6., 4., 1.]) 95 | elif(self.filt_size == 6): 96 | a = np.array([1., 5., 10., 10., 5., 1.]) 97 | elif(self.filt_size == 7): 98 | a = np.array([1., 6., 15., 20., 15., 6., 1.]) 99 | 100 | filt = torch.Tensor(a) 101 | filt = filt / torch.sum(filt) 102 | self.register_buffer('filt', filt[None, None, :].repeat((self.channels, 1, 1))) 103 | 104 | self.pad = get_pad_layer_1d(pad_type)(self.pad_sizes) 105 | 106 | def forward(self, inp): 107 | if(self.filt_size == 1): 108 | if(self.pad_off == 0): 109 | return inp[:, :, ::self.stride] 110 | else: 111 | return self.pad(inp)[:, :, ::self.stride] 112 | else: 113 | return F.conv1d(self.pad(inp), self.filt, stride=self.stride, groups=inp.shape[1]) 114 | 115 | 116 | def get_pad_layer_1d(pad_type): 117 | if(pad_type in ['refl', 'reflect']): 118 | PadLayer = nn.ReflectionPad1d 119 | elif(pad_type in ['repl', 'replicate']): 120 | PadLayer = nn.ReplicationPad1d 121 | elif(pad_type == 'zero'): 122 | PadLayer = nn.ZeroPad1d 123 | else: 124 | print('Pad type [%s] not recognized' % pad_type) 125 | return PadLayer -------------------------------------------------------------------------------- /FastFourierSICE/models/archs/discriminator_vgg_arch.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torchvision 4 | 5 | 6 | class Discriminator_VGG_128(nn.Module): 7 | def __init__(self, in_nc, nf): 8 | super(Discriminator_VGG_128, self).__init__() 9 | # [64, 128, 128] 10 | self.conv0_0 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True) 11 | self.conv0_1 = nn.Conv2d(nf, nf, 4, 2, 1, bias=False) 12 | self.bn0_1 = nn.BatchNorm2d(nf, affine=True) 13 | # [64, 64, 64] 14 | self.conv1_0 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=False) 15 | self.bn1_0 = nn.BatchNorm2d(nf * 2, affine=True) 16 | self.conv1_1 = nn.Conv2d(nf * 2, nf * 2, 4, 2, 1, bias=False) 17 | self.bn1_1 = nn.BatchNorm2d(nf * 2, affine=True) 18 | # [128, 32, 32] 19 | self.conv2_0 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=False) 20 | self.bn2_0 = nn.BatchNorm2d(nf * 4, affine=True) 21 | self.conv2_1 = nn.Conv2d(nf * 4, nf * 4, 4, 2, 1, bias=False) 22 | self.bn2_1 = nn.BatchNorm2d(nf * 4, affine=True) 23 | # [256, 16, 16] 24 | self.conv3_0 = nn.Conv2d(nf * 4, nf * 8, 3, 1, 1, bias=False) 25 | self.bn3_0 = nn.BatchNorm2d(nf * 8, affine=True) 26 | self.conv3_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 27 | self.bn3_1 = nn.BatchNorm2d(nf * 8, affine=True) 28 | # [512, 8, 8] 29 | self.conv4_0 = nn.Conv2d(nf * 8, nf * 8, 3, 1, 1, bias=False) 30 | self.bn4_0 = nn.BatchNorm2d(nf * 8, affine=True) 31 | self.conv4_1 = nn.Conv2d(nf * 8, nf * 8, 4, 2, 1, bias=False) 32 | self.bn4_1 = nn.BatchNorm2d(nf * 8, affine=True) 33 | 34 | self.linear1 = nn.Linear(512 * 4 * 4, 100) 35 | self.linear2 = nn.Linear(100, 1) 36 | 37 | # activation function 38 | self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) 39 | 40 | def forward(self, x): 41 | fea = self.lrelu(self.conv0_0(x)) 42 | fea = self.lrelu(self.bn0_1(self.conv0_1(fea))) 43 | 44 | fea = self.lrelu(self.bn1_0(self.conv1_0(fea))) 45 | fea = self.lrelu(self.bn1_1(self.conv1_1(fea))) 46 | 47 | fea = self.lrelu(self.bn2_0(self.conv2_0(fea))) 48 | fea = self.lrelu(self.bn2_1(self.conv2_1(fea))) 49 | 50 | fea = self.lrelu(self.bn3_0(self.conv3_0(fea))) 51 | fea = self.lrelu(self.bn3_1(self.conv3_1(fea))) 52 | 53 | fea = self.lrelu(self.bn4_0(self.conv4_0(fea))) 54 | fea = self.lrelu(self.bn4_1(self.conv4_1(fea))) 55 | 56 | fea = fea.view(fea.size(0), -1) 57 | fea = self.lrelu(self.linear1(fea)) 58 | out = self.linear2(fea) 59 | return out 60 | 61 | 62 | class VGGFeatureExtractor(nn.Module): 63 | def __init__(self, feature_layer=34, use_bn=False, use_input_norm=True, 64 | device=torch.device('cpu')): 65 | super(VGGFeatureExtractor, self).__init__() 66 | self.use_input_norm = use_input_norm 67 | if use_bn: 68 | model = torchvision.models.vgg19_bn(pretrained=True) 69 | else: 70 | model = torchvision.models.vgg19(pretrained=True) 71 | if self.use_input_norm: 72 | mean = torch.Tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1).to(device) 73 | # [0.485 - 1, 0.456 - 1, 0.406 - 1] if input in range [-1, 1] 74 | std = torch.Tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1).to(device) 75 | # [0.229 * 2, 0.224 * 2, 0.225 * 2] if input in range [-1, 1] 76 | self.register_buffer('mean', mean) 77 | self.register_buffer('std', std) 78 | self.features = nn.Sequential(*list(model.features.children())[:(feature_layer + 1)]) 79 | # No need to BP to variable 80 | for k, v in self.features.named_parameters(): 81 | v.requires_grad = False 82 | 83 | def forward(self, x): 84 | # Assume input range is [0, 1] 85 | if self.use_input_norm: 86 | x = (x - self.mean) / self.std 87 | output = self.features(x) 88 | return output 89 | -------------------------------------------------------------------------------- /FastFourierSICE/models/loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class CharbonnierLoss(nn.Module): 6 | """Charbonnier Loss (L1)""" 7 | 8 | def __init__(self, eps=1e-6): 9 | super(CharbonnierLoss, self).__init__() 10 | self.eps = eps 11 | 12 | def forward(self, x, y): 13 | diff = x - y 14 | loss = torch.sum(torch.sqrt(diff * diff + self.eps)) 15 | return loss 16 | 17 | 18 | # Define GAN loss: [vanilla | lsgan | wgan-gp] 19 | class GANLoss(nn.Module): 20 | def __init__(self, gan_type, real_label_val=1.0, fake_label_val=0.0): 21 | super(GANLoss, self).__init__() 22 | self.gan_type = gan_type.lower() 23 | self.real_label_val = real_label_val 24 | self.fake_label_val = fake_label_val 25 | 26 | if self.gan_type == 'gan' or self.gan_type == 'ragan': 27 | self.loss = nn.BCEWithLogitsLoss() 28 | elif self.gan_type == 'lsgan': 29 | self.loss = nn.MSELoss() 30 | elif self.gan_type == 'wgan-gp': 31 | 32 | def wgan_loss(input, target): 33 | # target is boolean 34 | return -1 * input.mean() if target else input.mean() 35 | 36 | self.loss = wgan_loss 37 | else: 38 | raise NotImplementedError('GAN type [{:s}] is not found'.format(self.gan_type)) 39 | 40 | def get_target_label(self, input, target_is_real): 41 | if self.gan_type == 'wgan-gp': 42 | return target_is_real 43 | if target_is_real: 44 | return torch.empty_like(input).fill_(self.real_label_val) 45 | else: 46 | return torch.empty_like(input).fill_(self.fake_label_val) 47 | 48 | def forward(self, input, target_is_real): 49 | target_label = self.get_target_label(input, target_is_real) 50 | loss = self.loss(input, target_label) 51 | return loss 52 | 53 | 54 | class GradientPenaltyLoss(nn.Module): 55 | def __init__(self, device=torch.device('cpu')): 56 | super(GradientPenaltyLoss, self).__init__() 57 | self.register_buffer('grad_outputs', torch.Tensor()) 58 | self.grad_outputs = self.grad_outputs.to(device) 59 | 60 | def get_grad_outputs(self, input): 61 | if self.grad_outputs.size() != input.size(): 62 | self.grad_outputs.resize_(input.size()).fill_(1.0) 63 | return self.grad_outputs 64 | 65 | def forward(self, interp, interp_crit): 66 | grad_outputs = self.get_grad_outputs(interp_crit) 67 | grad_interp = torch.autograd.grad(outputs=interp_crit, inputs=interp, 68 | grad_outputs=grad_outputs, create_graph=True, 69 | retain_graph=True, only_inputs=True)[0] 70 | grad_interp = grad_interp.view(grad_interp.size(0), -1) 71 | grad_interp_norm = grad_interp.norm(2, dim=1) 72 | 73 | loss = ((grad_interp_norm - 1)**2).mean() 74 | return loss 75 | 76 | 77 | class AMPLoss(nn.Module): 78 | def __init__(self): 79 | super(AMPLoss, self).__init__() 80 | self.cri = nn.L1Loss() 81 | 82 | def forward(self, x, y): 83 | x = torch.fft.rfft2(x, norm='backward') 84 | x_mag = torch.abs(x) 85 | y = torch.fft.rfft2(y, norm='backward') 86 | y_mag = torch.abs(y) 87 | 88 | return self.cri(x_mag,y_mag) 89 | 90 | 91 | class PhaLoss(nn.Module): 92 | def __init__(self): 93 | super(PhaLoss, self).__init__() 94 | self.cri = nn.L1Loss() 95 | 96 | def forward(self, x, y): 97 | x = torch.fft.rfft2(x, norm='backward') 98 | x_mag = torch.angle(x) 99 | y = torch.fft.rfft2(y, norm='backward') 100 | y_mag = torch.angle(y) 101 | 102 | return self.cri(x_mag, y_mag) 103 | 104 | 105 | class FourierLoss(nn.Module): 106 | def __init__(self): 107 | super(FourierLoss, self).__init__() 108 | self.cri = nn.L1Loss() 109 | 110 | def forward(self, x, y): 111 | x = torch.fft.rfft2(x, norm='backward') 112 | x_amp = torch.abs(x) 113 | x_pha = torch.angle(x) 114 | y = torch.fft.rfft2(y, norm='backward') 115 | y_amp = torch.abs(y) 116 | y_pha = torch.angle(y) 117 | 118 | x_fourier = torch.cat([x_amp,x_pha],1) 119 | y_fourier = torch.cat([y_amp,y_pha],1) 120 | 121 | return self.cri(x_fourier,y_fourier) -------------------------------------------------------------------------------- /FastFourierSICE/models/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import models.archs.discriminator_vgg_arch as SRGAN_arch 3 | import models.archs.EnhanceN_arch as EnhanceN_arch 4 | import models.archs.EnhanceN_arch1 as EnhanceN_arch1 5 | 6 | 7 | # Generator 8 | def define_G(opt): 9 | opt_net = opt['network_G'] 10 | which_model = opt_net['which_model_G'] 11 | 12 | # video restoration 13 | if which_model == 'Net': 14 | netG = EnhanceN_arch.InteractNet(nc=opt_net['nc']) 15 | elif which_model == 'Net1': 16 | netG = EnhanceN_arch1.InteractNet(nc=opt_net['nc']) 17 | else: 18 | raise NotImplementedError('Generator model [{:s}] not recognized'.format(which_model)) 19 | 20 | return netG 21 | 22 | 23 | # Discriminator 24 | def define_D(opt): 25 | opt_net = opt['network_D'] 26 | which_model = opt_net['which_model_D'] 27 | 28 | if which_model == 'discriminator_vgg_128': 29 | netD = SRGAN_arch.Discriminator_VGG_128(in_nc=opt_net['in_nc'], nf=opt_net['nf']) 30 | else: 31 | raise NotImplementedError('Discriminator model [{:s}] not recognized'.format(which_model)) 32 | return netD 33 | 34 | 35 | # Define network used for perceptual loss 36 | def define_F(opt, use_bn=False): 37 | gpu_ids = opt['gpu_ids'] 38 | device = torch.device('cuda' if gpu_ids else 'cpu') 39 | # PyTorch pretrained VGG19-54, before ReLU. 40 | if use_bn: 41 | feature_layer = 49 42 | else: 43 | feature_layer = 34 44 | netF = SRGAN_arch.VGGFeatureExtractor(feature_layer=feature_layer, use_bn=use_bn, 45 | use_input_norm=True, device=device) 46 | netF.eval() # No need to train 47 | return netF 48 | -------------------------------------------------------------------------------- /FastFourierSICE/options/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/options/__init__.py -------------------------------------------------------------------------------- /FastFourierSICE/options/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/options/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/options/__pycache__/options.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/options/__pycache__/options.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/options/options.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as osp 3 | import logging 4 | import yaml 5 | from utils.util import OrderedYaml 6 | Loader, Dumper = OrderedYaml() 7 | 8 | 9 | def parse(opt_path, is_train=True): 10 | with open(opt_path, mode='r') as f: 11 | opt = yaml.load(f, Loader=Loader) 12 | # export CUDA_VISIBLE_DEVICES 13 | gpu_list = ','.join(str(x) for x in opt['gpu_ids']) 14 | os.environ['CUDA_VISIBLE_DEVICES'] = gpu_list 15 | print('export CUDA_VISIBLE_DEVICES=' + gpu_list) 16 | 17 | opt['is_train'] = is_train 18 | if opt['distortion'] == 'sr': 19 | scale = opt['scale'] 20 | 21 | # datasets 22 | for phase, dataset in opt['datasets'].items(): 23 | phase = phase.split('_')[0] 24 | dataset['phase'] = phase 25 | if opt['distortion'] == 'sr': 26 | dataset['scale'] = scale 27 | is_lmdb = False 28 | if dataset.get('dataroot_GT', None) is not None: 29 | dataset['dataroot_GT'] = osp.expanduser(dataset['dataroot_GT']) 30 | if dataset['dataroot_GT'].endswith('lmdb'): 31 | is_lmdb = True 32 | if dataset.get('dataroot_LQ', None) is not None: 33 | dataset['dataroot_LQ'] = osp.expanduser(dataset['dataroot_LQ']) 34 | if dataset['dataroot_LQ'].endswith('lmdb'): 35 | is_lmdb = True 36 | dataset['data_type'] = 'lmdb' if is_lmdb else 'img' 37 | if dataset['mode'].endswith('mc'): # for memcached 38 | dataset['data_type'] = 'mc' 39 | dataset['mode'] = dataset['mode'].replace('_mc', '') 40 | 41 | # path 42 | for key, path in opt['path'].items(): 43 | if path and key in opt['path'] and key != 'strict_load': 44 | opt['path'][key] = osp.expanduser(path) 45 | # opt['path']['root'] = '/home/zhanghc/IEEEyellow/code_enhance/checkpoints' 46 | if is_train: 47 | experiments_root = osp.join(opt['path']['root'], 'experiments', opt['name']) 48 | opt['path']['experiments_root'] = experiments_root 49 | opt['path']['models'] = osp.join(experiments_root, 'models') 50 | opt['path']['training_state'] = osp.join(experiments_root, 'training_state') 51 | opt['path']['log'] = experiments_root 52 | opt['path']['val_images'] = osp.join(experiments_root, 'val_images') 53 | 54 | # change some options for debug mode 55 | if 'debug' in opt['name']: 56 | opt['train']['val_freq'] = 8 57 | opt['logger']['print_freq'] = 1 58 | opt['logger']['save_checkpoint_freq'] = 8 59 | else: # test 60 | results_root = osp.join(opt['path']['root'], 'results', opt['name']) 61 | opt['path']['results_root'] = results_root 62 | opt['path']['log'] = results_root 63 | 64 | # network 65 | if opt['distortion'] == 'sr': 66 | opt['network_G']['scale'] = scale 67 | 68 | return opt 69 | 70 | 71 | def dict2str(opt, indent_l=1): 72 | '''dict to string for logger''' 73 | msg = '' 74 | for k, v in opt.items(): 75 | if isinstance(v, dict): 76 | msg += ' ' * (indent_l * 2) + k + ':[\n' 77 | msg += dict2str(v, indent_l + 1) 78 | msg += ' ' * (indent_l * 2) + ']\n' 79 | else: 80 | msg += ' ' * (indent_l * 2) + k + ': ' + str(v) + '\n' 81 | return msg 82 | 83 | 84 | class NoneDict(dict): 85 | def __missing__(self, key): 86 | return None 87 | 88 | 89 | # convert to NoneDict, which return None for missing key. 90 | def dict_to_nonedict(opt): 91 | if isinstance(opt, dict): 92 | new_opt = dict() 93 | for key, sub_opt in opt.items(): 94 | new_opt[key] = dict_to_nonedict(sub_opt) 95 | return NoneDict(**new_opt) 96 | elif isinstance(opt, list): 97 | return [dict_to_nonedict(sub_opt) for sub_opt in opt] 98 | else: 99 | return opt 100 | 101 | 102 | def check_resume(opt, resume_iter): 103 | '''Check resume states and pretrain_model paths''' 104 | logger = logging.getLogger('base') 105 | if opt['path']['resume_state']: 106 | if opt['path'].get('pretrain_model_G', None) is not None or opt['path'].get( 107 | 'pretrain_model_D', None) is not None: 108 | logger.warning('pretrain_model path will be ignored when resuming training.') 109 | 110 | opt['path']['pretrain_model_G'] = osp.join(opt['path']['models'], 111 | '{}_G.pth'.format(resume_iter)) 112 | logger.info('Set [pretrain_model_G] to ' + opt['path']['pretrain_model_G']) 113 | if 'gan' in opt['model']: 114 | opt['path']['pretrain_model_D'] = osp.join(opt['path']['models'], 115 | '{}_D.pth'.format(resume_iter)) 116 | logger.info('Set [pretrain_model_D] to ' + opt['path']['pretrain_model_D']) 117 | -------------------------------------------------------------------------------- /FastFourierSICE/options/test/test_ESRGAN.yml: -------------------------------------------------------------------------------- 1 | name: RRDB_ESRGAN_x4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: RRDBNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 23 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/RRDB_ESRGAN_x4.pth 33 | -------------------------------------------------------------------------------- /FastFourierSICE/options/test/test_SRGAN.yml: -------------------------------------------------------------------------------- 1 | name: MSRGANx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | 21 | #### network structures 22 | network_G: 23 | which_model_G: MSRResNet 24 | in_nc: 3 25 | out_nc: 3 26 | nf: 64 27 | nb: 16 28 | upscale: 4 29 | 30 | #### path 31 | path: 32 | pretrain_model_G: ../experiments/pretrained_models/MSRGANx4.pth 33 | -------------------------------------------------------------------------------- /FastFourierSICE/options/test/test_SRResNet.yml: -------------------------------------------------------------------------------- 1 | name: MSRResNetx4 2 | suffix: ~ # add suffix to saved images 3 | model: sr 4 | distortion: sr 5 | scale: 4 6 | crop_border: ~ # crop border when evaluation. If None(~), crop the scale pixels 7 | gpu_ids: [0] 8 | 9 | datasets: 10 | test_1: # the 1st test dataset 11 | name: set5 12 | mode: LQGT 13 | dataroot_GT: ../datasets/val_set5/Set5 14 | dataroot_LQ: ../datasets/val_set5/Set5_bicLRx4 15 | test_2: # the 2st test dataset 16 | name: set14 17 | mode: LQGT 18 | dataroot_GT: ../datasets/val_set14/Set14 19 | dataroot_LQ: ../datasets/val_set14/Set14_bicLRx4 20 | test_3: 21 | name: bsd100 22 | mode: LQGT 23 | dataroot_GT: ../datasets/BSD/BSDS100 24 | dataroot_LQ: ../datasets/BSD/BSDS100_bicLRx4 25 | test_4: 26 | name: urban100 27 | mode: LQGT 28 | dataroot_GT: ../datasets/urban100 29 | dataroot_LQ: ../datasets/urban100_bicLRx4 30 | test_5: 31 | name: div2k100 32 | mode: LQGT 33 | dataroot_GT: ../datasets/DIV2K100/DIV2K_valid_HR 34 | dataroot_LQ: ../datasets/DIV2K100/DIV2K_valid_bicLRx4 35 | 36 | 37 | #### network structures 38 | network_G: 39 | which_model_G: MSRResNet 40 | in_nc: 3 41 | out_nc: 3 42 | nf: 64 43 | nb: 16 44 | upscale: 4 45 | 46 | #### path 47 | path: 48 | pretrain_model_G: ../experiments/pretrained_models/MSRResNetx4.pth 49 | -------------------------------------------------------------------------------- /FastFourierSICE/options/train/train_Enhance.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [0] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp/data/groups_train_mixSICEV2.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 256 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp/data/groups_train_mixSICEV2.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourierExp/SOTA_Finals/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 1e-4 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 51200 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [25600, 38400] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 40 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierSICE/options/train/train_Enhance1.yml: -------------------------------------------------------------------------------- 1 | #### general settings 2 | name: STEN 3 | use_tb_logger: true 4 | model: sr 5 | distortion: sr 6 | scale: 1 7 | gpu_ids: [1] 8 | 9 | #### datasets 10 | datasets: 11 | train: 12 | name: UEN 13 | mode: UEN_train 14 | interval_list: [1] 15 | random_reverse: false 16 | border_mode: false 17 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 18 | cache_keys: ~ 19 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp/data/groups_train_mixSICEV2.txt 20 | 21 | use_shuffle: true 22 | n_workers: 0 # per GPU 23 | batch_size: 4 24 | IN_size: 384 25 | augment: true 26 | color: RGB 27 | 28 | val: 29 | name: UEN 30 | mode: UEN_val 31 | # dataroot: /data/1760921465/dped/iphone/test_data/patches 32 | filelist: /home/jieh/Projects/ExposureFrequency/FastFourierExp/data/groups_test_mixSICEV2.txt 33 | 34 | batch_size: 1 35 | use_shuffle: false 36 | 37 | 38 | #### network structures 39 | network_G: 40 | which_model_G: Net1 41 | nc: 8 42 | groups: 8 43 | 44 | #### path 45 | path: 46 | root: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output1 47 | results_root: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output1 48 | pretrain: /home/jieh/Projects/ExposureFrequency/FastFourierExp/pretrain1 49 | pretrain_model_G: /home/jieh/Projects/ExposureFrequency/FastFourierExp/output1/experiments/SOTA/0_bestavg.pth 50 | strict_load: false 51 | resume_state: ~ 52 | 53 | #### training settings: learning rate scheme, loss 54 | train: 55 | lr_G: !!float 6e-5 56 | lr_scheme: MultiStepLR 57 | beta1: 0.9 58 | beta2: 0.99 59 | niter: 50000 60 | fix_some_part: ~ 61 | warmup_iter: -1 # -1: no warm up 62 | 63 | #### for cosine adjustment 64 | # T_period: [400000, 1000000, 1500000, 1500000, 1500000] 65 | # restarts: [400000, 1400000, 2700000, 4200000] 66 | # restart_weights: [1, 1, 1, 1] 67 | lr_scheme: MultiStepLR 68 | lr_steps: [20000, 40000] 69 | lr_gamma: 0.5 70 | 71 | eta_min: !!float 5e-6 72 | pixel_criterion: l1 73 | pixel_weight: 5000.0 74 | ssim_weight: 1000.0 75 | vgg_weight: 1000.0 76 | 77 | val_epoch: !!float 1 78 | manual_seed: 0 79 | 80 | #### logger 81 | logger: 82 | print_freq: 40 83 | save_checkpoint_epoch: !!float 100 84 | -------------------------------------------------------------------------------- /FastFourierSICE/pretrain/0_bestavg.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/pretrain/0_bestavg.pth -------------------------------------------------------------------------------- /FastFourierSICE/test.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import logging 3 | import time 4 | import argparse 5 | from collections import OrderedDict 6 | 7 | import options.options as option 8 | import utils.util as util 9 | from data.util import bgr2ycbcr 10 | from data import create_dataset, create_dataloader 11 | from models import create_model 12 | 13 | #### options 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('-opt', type=str, required=True, help='Path to options YMAL file.') 16 | opt = option.parse(parser.parse_args().opt, is_train=False) 17 | opt = option.dict_to_nonedict(opt) 18 | 19 | util.mkdirs( 20 | (path for key, path in opt['path'].items() 21 | if not key == 'experiments_root' and 'pretrain_model' not in key and 'resume' not in key)) 22 | util.setup_logger('base', opt['path']['log'], 'test_' + opt['name'], level=logging.INFO, 23 | screen=True, tofile=True) 24 | logger = logging.getLogger('base') 25 | logger.info(option.dict2str(opt)) 26 | 27 | #### Create test dataset and dataloader 28 | test_loaders = [] 29 | for phase, dataset_opt in sorted(opt['datasets'].items()): 30 | test_set = create_dataset(dataset_opt) 31 | test_loader = create_dataloader(test_set, dataset_opt) 32 | logger.info('Number of test images in [{:s}]: {:d}'.format(dataset_opt['name'], len(test_set))) 33 | test_loaders.append(test_loader) 34 | 35 | model = create_model(opt) 36 | for test_loader in test_loaders: 37 | test_set_name = test_loader.dataset.opt['name'] 38 | logger.info('\nTesting [{:s}]...'.format(test_set_name)) 39 | test_start_time = time.time() 40 | dataset_dir = osp.join(opt['path']['results_root'], test_set_name) 41 | util.mkdir(dataset_dir) 42 | 43 | test_results = OrderedDict() 44 | test_results['psnr'] = [] 45 | test_results['ssim'] = [] 46 | test_results['psnr_y'] = [] 47 | test_results['ssim_y'] = [] 48 | 49 | for data in test_loader: 50 | need_GT = False if test_loader.dataset.opt['dataroot_GT'] is None else True 51 | model.feed_data(data, need_GT=need_GT) 52 | img_path = data['GT_path'][0] if need_GT else data['LQ_path'][0] 53 | img_name = osp.splitext(osp.basename(img_path))[0] 54 | 55 | model.test() 56 | visuals = model.get_current_visuals(need_GT=need_GT) 57 | 58 | sr_img = util.tensor2img(visuals['rlt']) # uint8 59 | 60 | # save images 61 | suffix = opt['suffix'] 62 | if suffix: 63 | save_img_path = osp.join(dataset_dir, img_name + suffix + '.png') 64 | else: 65 | save_img_path = osp.join(dataset_dir, img_name + '.png') 66 | util.save_img(sr_img, save_img_path) 67 | 68 | # calculate PSNR and SSIM 69 | if need_GT: 70 | gt_img = util.tensor2img(visuals['GT']) 71 | sr_img, gt_img = util.crop_border([sr_img, gt_img], opt['scale']) 72 | psnr = util.calculate_psnr(sr_img, gt_img) 73 | ssim = util.calculate_ssim(sr_img, gt_img) 74 | test_results['psnr'].append(psnr) 75 | test_results['ssim'].append(ssim) 76 | 77 | if gt_img.shape[2] == 3: # RGB image 78 | sr_img_y = bgr2ycbcr(sr_img / 255., only_y=True) 79 | gt_img_y = bgr2ycbcr(gt_img / 255., only_y=True) 80 | 81 | psnr_y = util.calculate_psnr(sr_img_y * 255, gt_img_y * 255) 82 | ssim_y = util.calculate_ssim(sr_img_y * 255, gt_img_y * 255) 83 | test_results['psnr_y'].append(psnr_y) 84 | test_results['ssim_y'].append(ssim_y) 85 | logger.info( 86 | '{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}; PSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}.'. 87 | format(img_name, psnr, ssim, psnr_y, ssim_y)) 88 | else: 89 | logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}.'.format(img_name, psnr, ssim)) 90 | else: 91 | logger.info(img_name) 92 | 93 | if need_GT: # metrics 94 | # Average PSNR/SSIM results 95 | ave_psnr = sum(test_results['psnr']) / len(test_results['psnr']) 96 | ave_ssim = sum(test_results['ssim']) / len(test_results['ssim']) 97 | logger.info( 98 | '----Average PSNR/SSIM results for {}----\n\tPSNR: {:.6f} dB; SSIM: {:.6f}\n'.format( 99 | test_set_name, ave_psnr, ave_ssim)) 100 | if test_results['psnr_y'] and test_results['ssim_y']: 101 | ave_psnr_y = sum(test_results['psnr_y']) / len(test_results['psnr_y']) 102 | ave_ssim_y = sum(test_results['ssim_y']) / len(test_results['ssim_y']) 103 | logger.info( 104 | '----Y channel, average PSNR/SSIM----\n\tPSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}\n'. 105 | format(ave_psnr_y, ave_ssim_y)) 106 | -------------------------------------------------------------------------------- /FastFourierSICE/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/utils/__init__.py -------------------------------------------------------------------------------- /FastFourierSICE/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /FastFourierSICE/utils/__pycache__/util.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinJ-Huang/FECNet/fc5a9eb224c448d190919558cc87ea7b7447f7f4/FastFourierSICE/utils/__pycache__/util.cpython-38.pyc -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Deep Fourier-based Exposure Correction with Spatial-Frequency Interaction (ECCV 2022) 2 | 3 | Jie Huang+, Yajing Liu+, Feng Zhao*, Keyu Yan, Jinghao Zhang, Yukun Huang, Man Zhou, Zhiwei Xiong 4 | 5 | *Equal Corresponding Authors 6 | 7 | +Equal Contributions 8 | 9 | University of Science and Technology of China (USTC) 10 | 11 | ## Introduction 12 | 13 | This repository is the **official implementation** of the paper, "Deep Fourier-based Exposure Correction with Spatial-Frequency Interaction", where more implementation details are presented. 14 | 15 | ### 0. Hyper-Parameters setting 16 | 17 | Overall, most parameters can be set in options/train/train_Enhance.yml 18 | 19 | ### 1. Dataset Preparation 20 | 21 | Create a .txt file to put the path of the dataset using 22 | 23 | ```python 24 | python create_txt.py 25 | ``` 26 | 27 | ### 2. Training 28 | 29 | ```python 30 | python train.py --opt options/train/train_Enhance.yml 31 | ``` 32 | 33 | 34 | ### 3. Inference 35 | 36 | set is_training in "options/train/train_Enhance.yml" as False 37 | set the val:filelist as the validation set. 38 | 39 | then 40 | ```python 41 | python train.py --opt options/train/train_Enhance.yml 42 | ``` 43 | 44 | ## Dataset 45 | MSEC dataset (please refer to https://github.com/mahmoudnafifi/Exposure_Correction) 46 | 47 | SICE dataset (I have uploaded it to https://share.weiyun.com/C2aJ1Cti) 48 | 49 | ## Ours Results 50 | 51 | MSEC dataset (https://drive.google.com/file/d/1AOuWujPffYaYJsDmkA8OcyU5S5a4zClP/view?usp=drive_link) 52 | 53 | SICE dataset (https://drive.google.com/file/d/1_Ya8iyRqOGoOy10nAyTHZS-6dJcuLVhU/view?usp=drive_link) 54 | 55 | ## Contact 56 | 57 | If you have any problem with the released code, please do not hesitate to contact me by email (hj0117@mail.ustc.edu.cn). 58 | 59 | ## Cite 60 | 61 | ``` 62 | ``` 63 | --------------------------------------------------------------------------------