模型:
eugenesiow/msrn
MSRN模型是在DIV2K数据集上进行预训练的,该数据集包含800张图像用于2x、3x和4x图像超分辨率任务的训练,通过数据增强扩展成4000张图像,并有100张验证集。该模型由Li等人在2018年的论文中提出,并首次在 this repository 上发布。
图像超分辨率的目标是从一张低分辨率(LR)图像中恢复出一张高分辨率(HR)图像。下图显示了真实值(HR)、双三次插值2x缩放以及模型2x缩放的图像。
MSRN模型提出了一种特征提取结构,称为多尺度残差块。该模块能够“自适应地在不同尺度上检测图像特征”并“发挥图像的潜在特征”。
您可以使用预训练的模型进行2x、3x和4x图像的放大。您还可以使用训练器在自己的数据集上训练模型。
该模型可以使用 super_image 库进行使用:
pip install super-image
以下是如何使用预训练模型放大图像的方法:
from super_image import MsrnModel, 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 = MsrnModel.from_pretrained('eugenesiow/msrn', scale=4) # scale 2, 3 and 4 models available inputs = ImageLoader.load_image(image) preds = model(inputs) ImageLoader.save_image(preds, './scaled_4x.png') # save the output 4x scaled image to `./scaled_4x.png` ImageLoader.save_compare(inputs, preds, './scaled_4x_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)图像的尺寸缩小x2、x3和x4倍来创建低分辨率(LR)图像。在训练时,使用64×64大小的RGB块从LR输入中提取,同时使用对应的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, MsrnModel, MsrnConfig training_args = TrainingArguments( output_dir='./results', # output directory num_train_epochs=1000, # total number of training epochs ) config = MsrnConfig( scale=4, # train a model to upscale 4x ) model = MsrnModel(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,并与双三次插值基准进行比较。
|数据集|缩放倍数|双三次插值|MSRN||---|---|---|---||Set5|2x|33.64/0.9292|38.08/0.9609||Set5|3x|30.39/0.8678|35.12/0.9409||Set5|4x|28.42/0.8101|32.19/0.8951||Set14|2x|30.22/0.8683|33.75/0.9183||Set14|3x|27.53/0.7737|31.08/0.8593||Set14|4x|25.99/0.7023|28.78/0.7862||BSD100|2x|29.55/0.8425|33.82/0.9258||BSD100|3x|27.20/0.7382|29.67/0.8198||BSD100|4x|25.96/0.6672|28.53/0.7657||Urban100|2x|26.66/0.8408|32.14/0.9287||Urban100|3x| |29.31/0.8743||Urban100|4x|23.14/0.6573|26.12/0.7866|
您可以在以下notebook中找到方便运行预训练模型评估的方法:
@InProceedings{Agustsson_2017_CVPR_Workshops, author = {Agustsson, Eirikur and Timofte, Radu}, title = {NTIRE 2017 Challenge on Single Image Super-Resolution: Dataset and Study}, booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Workshops}, url = "http://www.vision.ee.ethz.ch/~timofter/publications/Agustsson-CVPRW-2017.pdf", month = {July}, year = {2017} }