DRLN模型在DIV2K上进行了预训练(800张图像进行训练,增加到4000张图像,100张图像进行验证),用于2倍、3倍和4倍的图像超分辨率。它由Anwar等人在2020年的论文 Densely Residual Laplacian Super-resolution 中介绍,并首次在 this repository 中发布。
图像超分辨率的目标是从单个低分辨率(LR)图像恢复高分辨率(HR)图像。下面的图像显示了真实图像(HR),双三次插值上采样和模型上采样。
最近的超分辨率卷积神经网络在单张图像的高质量恢复方面取得了很好的效果。然而,现有算法通常需要非常深的架构和长时间的训练。此外,当前用于超分辨率的卷积神经网络无法利用多种尺度的特征并平等地加以权衡,限制了它们的学习能力。在本文中,我们提出了一种紧凑且准确的超分辨率算法,即Densely Residual Laplacian Network(DRLN)。提出的网络采用了级联残差结构,使低频信息的流动集中在学习高和中等级特征上。此外,通过密集连接的残差块设置实现了深度监督,这也有助于从高级复杂特征中进行学习。此外,我们提出了拉普拉斯注意力来建模关键特征,以学习特征图之间的层间和层内依赖关系。此外,对于低分辨率、有噪声的低分辨率和真实历史图像基准数据集进行了全面的定量和定性评估,结果表明我们的DRLN算法在视觉和准确性上表现优异,超过了最先进的方法。
您可以使用预训练模型来将图像放大2倍、3倍和4倍。您还可以使用训练器在自己的数据集上训练模型。
该模型可以与 super_image 库一起使用:
pip install super-image
下面是如何使用预训练模型放大图像:
from super_image import DrlnModel, 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 = DrlnModel.from_pretrained('eugenesiow/drln', 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
2倍、3倍和4倍的图像超分辨率模型是在 DIV2K 上进行预训练的,该数据集包含800个高质量的(2K分辨率)训练图像,经过增强得到4000个图像,并使用100个验证图像集(图像编号801到900)。
我们遵循 Wang et al. 的预处理和训练方法。使用双三次插值作为调整大小方法,将高分辨率(HR)图像的尺寸缩小2倍、3倍和4倍来创建低分辨率(LR)图像。在训练过程中,使用从LR输入中大小为64×64的RGB块以及对应的HR块。在预处理阶段,对训练集应用数据增强,从原始图像的四个角落和中心创建五个图像。
我们需要使用 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, DrlnModel, DrlnConfig training_args = TrainingArguments( output_dir='./results', # output directory num_train_epochs=1000, # total number of training epochs ) config = DrlnConfig( scale=4, # train a model to upscale 4x ) model = DrlnModel(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表示。它们与双三次插值基线进行比较。
|数据集 |倍数 |双三次插值 |drln ||--- |--- |--- |--- ||Set5 |2x |33.64/0.9292 |38.22/0.9614 ||Set5 |3x |30.39/0.8678 |35.31/0.9423 ||Set5 |4x |28.42/0.8101 |32.55/0.899 ||Set14 |2x |30.22/0.8683 |34.01/0.9211 ||Set14 |3x |27.53/0.7737 |31.21/0.8619 ||Set14 |4x |25.99/0.7023 |28.96/0.7901 ||BSD100 |2x |29.55/0.8425 |33.93/0.9269 ||BSD100 |3x |27.20/0.7382 |29.77/0.8223 ||BSD100 |4x |25.96/0.6672 |28.65/0.7692 ||Urban100 |2x |26.66/0.8408 |32.82/0.934 ||Urban100 |3x | |29.79/0.8825 ||Urban100 |4x |23.14/0.6573 |26.56/0.7998 |
您可以在下面找到一个笔记本,以便轻松运行预训练模型的评估:
@misc{anwar2019densely, title={Densely Residual Laplacian Super-Resolution}, author={Saeed Anwar and Nick Barnes}, year={2019}, eprint={1906.12021}, archivePrefix={arXiv}, primaryClass={eess.IV} }