DRLN模型是在DIV2K(800张训练图像,扩充到4000张,100张验证图像)上进行了预训练,用于2x、3x和4x图像超分辨率。它是在Anwar等人(2020年)的论文中提出的,并在 this repository 中首次发布。
图像超分辨率的目标是从单个低分辨率(LR)图像中恢复出高分辨率(HR)图像。下图显示了真实图像(HR),双三次插值图像和模型放大图像。
最近,超分辨率卷积神经网络在单幅图像的高质量恢复方面表现出色。然而,现有的算法通常需要非常深的架构和长时间的训练。此外,当前的超分辨率卷积神经网络无法充分利用多尺度的特征并平等地权衡它们,限制了它们的学习能力。在本文中,我们提出了一种紧凑而准确的超分辨率算法,即Densely Residual Laplacian Network(DRLN)。所提出的网络使用级联的残余结构,使得低频信息的流动集中于学习高级和中级特征。此外,通过密集连接的残差块设置实现了深层监督,这也有助于学习高级复杂特征。此外,我们提出了Laplacian注意力来建模关键特征,以学习特征图之间的内部和内部级别依赖关系。此外,对低分辨率、噪声低分辨率和真实历史图像基准数据集的全面定量和定性评估表明,我们的DRLN算法在视觉上和准确上都表现出色,优于最先进的方法。
此模型还应用了 Wang et al. (2021) 提出的平衡注意力(BAM)方法来进一步改善结果。
您可以使用预训练模型将图像放大2x、3x和4x。您还可以使用训练器在自己的数据集上训练模型。
您可以使用 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-bam', 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. 的预处理和训练方法。使用双三次插值作为调整尺寸的方法,通过x2、x3和x4倍降低高分辨率(HR)图像的大小来创建低分辨率(LR)图像。在训练过程中,使用来自LR输入的大小为64x64的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, 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 bam=True, # apply balanced attention to the network ) 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-bam ||--- |--- |--- |--- ||Set5 |2x |33.64/0.9292 | 38.23/0.9614 ||Set5 |3x |30.39/0.8678 | 35.3/0.9422 ||Set5 |4x |28.42/0.8101 | 32.49/0.8986 ||Set14 |2x |30.22/0.8683 | 33.95/0.9206 ||Set14 |3x |27.53/0.7737 | 31.27/0.8624 ||Set14 |4x |25.99/0.7023 | 28.94/0.7899 ||BSD100 |2x |29.55/0.8425 | 33.95/0.9269 ||BSD100 |3x |27.20/0.7382 | 29.78/0.8224 ||BSD100 |4x |25.96/0.6672 | 28.63/0.7686 ||Urban100 |2x |26.66/0.8408 | 32.81/0.9339 ||Urban100 |3x | | 29.82/0.8828 ||Urban100 |4x |23.14/0.6573 | 26.53/0.7991 |
您可以在下面找到一个笔记本,以便轻松运行对预训练模型的评估:
@misc{wang2021bam, title={BAM: A Lightweight and Efficient Balanced Attention Mechanism for Single Image Super Resolution}, author={Fanyi Wang and Haotian Hu and Cheng Shen}, year={2021}, eprint={2104.07566}, archivePrefix={arXiv}, primaryClass={eess.IV} }
@misc{anwar2019densely, title={Densely Residual Laplacian Super-Resolution}, author={Saeed Anwar and Nick Barnes}, year={2019}, eprint={1906.12021}, archivePrefix={arXiv}, primaryClass={eess.IV} }