EDSR模型是在DIV2K数据集上预训练的(800张图像进行训练,增加到4000张图像,并使用100张验证图像),用于2x、3x和4x的图像超分辨率。它是由Lim等人于2017年在论文中引入的,并首次在发布中提出。
图像超分辨的目标是从单个低分辨率(LR)图像中恢复出高分辨率(HR)图像。下图展示了真实值(HR)、双三次插值放大2倍和EDSR放大2倍的效果。
EDSR是一种使用更深和更宽的架构(32个ResBlocks和256个通道)来提高性能的模型。它使用了全局和局部的跳跃连接,并且上采样是在网络末端完成的。它不使用批归一化层(输入和输出具有相似的分布,对中间特征进行归一化可能不是理想的选择),而是使用常量缩放层来确保稳定的训练。使用了L1损失函数(绝对误差)而不是L2(均方差),作者经验上表明使用L1损失函数在性能上更好,并且需要更少的计算。
这是一个基本模型(大约5MB对比大约100MB),只包括16个ResBlocks和64个通道。
您可以使用预训练模型将图像放大2倍、3倍和4倍。您还可以使用训练器在自己的数据集上训练模型。
该模型可以与库 super_image 一起使用:
pip install super-image
以下是如何使用预训练模型放大图像的示例:
from super_image import EdsrModel, ImageLoader from PIL import Image import requests url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg' image = Image.open(requests.get(url, stream=True).raw) model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=2) # scale 2, 3 and 4 models available inputs = ImageLoader.load_image(image) preds = model(inputs) ImageLoader.save_image(preds, './scaled_2x.png') # save the output 2x scaled image to `./scaled_2x.png` ImageLoader.save_compare(inputs, preds, './scaled_2x_compare.png') # save an output comparing the super-image with a bicubic scaling
2x、3x和4x的图像超分辨率模型是在 DIV2K 数据集上进行预训练的,该数据集包含800张高质量(2K分辨率)图像进行训练,增加到4000张图像,并使用100张验证图像(图像编号为801至900)。
我们按照 Wang et al. 的预处理和训练方法。通过使用双三次插值作为调整大小方法,将高分辨率(HR)图像的尺寸缩小2倍、3倍和4倍来创建低分辨率(LR)图像。在训练期间,使用大小为64×64的RGB图像块与其对应的HR图像块一起使用。在预处理阶段对训练集应用数据增强,从原始图像的四个角和中心创建出五个图像。
我们需要huggingface datasets 库来下载数据:
pip install datasets
下面的代码获取数据并对数据进行预处理和增强。
from datasets import load_dataset from super_image.data import EvalDataset, TrainDataset, augment_five_crop augmented_dataset = load_dataset('eugenesiow/Div2k', 'bicubic_x4', split='train')\ .map(augment_five_crop, batched=True, desc="Augmenting Dataset") # download and augment the data with the five_crop method train_dataset = TrainDataset(augmented_dataset) # prepare the train dataset for loading PyTorch DataLoader eval_dataset = EvalDataset(load_dataset('eugenesiow/Div2k', 'bicubic_x4', split='validation')) # prepare the eval dataset for the PyTorch DataLoader
该模型是在GPU上训练的。以下是训练代码:
from super_image import Trainer, TrainingArguments, EdsrModel, EdsrConfig training_args = TrainingArguments( output_dir='./results', # output directory num_train_epochs=1000, # total number of training epochs ) config = EdsrConfig( scale=4, # train a model to upscale 4x ) model = EdsrModel(config) trainer = Trainer( model=model, # the instantiated model to be trained args=training_args, # training arguments, defined above train_dataset=train_dataset, # training dataset eval_dataset=eval_dataset # evaluation dataset ) trainer.train()
评估数据集包括:
下面的结果列以PSNR/SSIM进行表示,并与双三次插值基准进行比较。
|数据集|比例|双三次插值|edsr-base||---|---|---|---||Set5|2x|33.64/0.9292|38.02/0.9607||Set5|3x|30.39/0.8678|35.04/0.9403||Set5|4x|28.42/0.8101|32.12/0.8947||Set14|2x|30.22/0.8683|33.57/0.9172||Set14|3x|27.53/0.7737|30.93/0.8567||Set14|4x|25.99/0.7023|28.60/0.7815||BSD100|2x|29.55/0.8425|32.21/0.8999||BSD100|3x|27.20/0.7382|29.65/0.8204||BSD100|4x|25.96/0.6672|27.61/0.7363||Urban100|2x|26.66/0.8408|32.04/0.9276||Urban100|3x| |29.23/0.8723||Urban100|4x|23.14/0.6573|26.02/0.7832|
您可以在下面的笔记本中找到轻松运行预训练模型评估的代码:
@InProceedings{Lim_2017_CVPR_Workshops, author = {Lim, Bee and Son, Sanghyun and Kim, Heewon and Nah, Seungjun and Lee, Kyoung Mu}, title = {Enhanced Deep Residual Networks for Single Image Super-Resolution}, booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Workshops}, month = {July}, year = {2017} }