CARN模型在DIV2K(800张训练图像,增加到4000张图像,100张验证图像)上进行了预训练,用于2倍、3倍和4倍的图像超分辨率。它在Ahn等人的论文《 Fast, Accurate, and Lightweight Super-Resolution with Cascading Residual Network 》中提出,并于《 this repository 》首次发布。
图像超分辨的目标是从单个低分辨率(LR)图像恢复出高分辨率(HR)图像。下面的图像展示了真值(HR)、双三次插值放大和模型放大。
CARN模型提出了一种基于残差网络的级联机制,用于准确且轻量级的图像超分辨率。
该模型还应用了由《 Wang et al. (2021) 》发明的平衡注意力(BAM)方法,以进一步提高结果。
您可以使用预训练模型将图像放大2倍、3倍和4倍。您还可以使用训练器在自己的数据集上训练模型。
该模型可以与《 super_image 》库一起使用:
pip install super-image
以下是如何使用预训练模型放大图像的示例:
from super_image import CarnModel, 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 = CarnModel.from_pretrained('eugenesiow/carn-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
2倍、3倍和4倍图像超分辨率的模型在《 DIV2K 》上进行了预训练,该数据集包含800张高质量(2K分辨率)的训练图像,经过增强后共有4000张图像,并使用了100张验证图像(图像编号为801至900)。
我们遵循了《 Wang et al. 》的预处理和训练方法。使用双三次插值作为调整大小方法,将高分辨率(HR)图像的大小缩小x2、x3和x4倍以创建低分辨率(LR)图像。训练过程中,使用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, CarnModel, CarnConfig training_args = TrainingArguments( output_dir='./results', # output directory num_train_epochs=1000, # total number of training epochs ) config = CarnConfig( scale=4, # train a model to upscale 4x bam=True, # apply balanced attention to the network ) model = CarnModel(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,并与双三次插值基准进行比较。
|数据集|比例|双三次插值|CARN-BAM||---|---|---|---||Set5|2x|33.64/0.9292|37.83/0.96||Set5|3x|30.39/0.8678|34.82/0.9385||Set5|4x|28.42/0.8101|32.0/0.8923||Set14|2x|30.22/0.8683|33.51/0.9166||Set14|3x|27.53/0.7737|30.9/0.8558||Set14|4x|25.99/0.7023|28.62/0.7822||BSD100|2x|29.55/0.8425|33.64/0.924||BSD100|3x|27.20/0.7382|29.54/0.8166||BSD100|4x|25.96/0.6672|28.41/0.7614||Urban100|2x|26.66/0.8408|31.53/0.922||Urban100|3x||28.84/0.8648||Urban100|4x|23.14/0.6573|25.77/0.7741|
您可以在以下notebook中找到轻松运行预训练模型评估的方法:
@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} }
@article{ahn2018fast, title={Fast, Accurate, and Lightweight Super-Resolution with Cascading Residual Network}, author={Ahn, Namhyuk and Kang, Byungkon and Sohn, Kyung-Ah}, journal={arXiv preprint arXiv:1803.08664}, year={2018} }