视觉人工智能指南

SwinIR 变压器恢复

SwinIR is an image restoration network from ETH Zurich, published in August 2021, that uses the Swin Transformer's shifted-window attention to upscale, denoise and remove JPEG artifacts from images.

听听这个指南AI叙述 · ~8 min

在本页阅读时间 9 分钟
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. Tracing a 4x upscale through SwinIR
  5. 现实世界的实施
  6. SwinIR 变压器恢复的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

It matters because it showed a compact transformer, about 12 million parameters, could beat larger convolutional and transformer models on standard restoration benchmarks, and it became a common upscaler and a baseline for later work.

主要要点

  1. SwinIR, posted in August 2021 by ETH Zurich researchers, applies Swin Transformer window attention to super-resolution, denoising and JPEG artifact reduction.
  2. Its default model stacks 6 residual Swin Transformer blocks of 6 layers each, with 8 by 8 attention windows and 180 channels.
  3. SwinIR beat the transformer model IPT on super-resolution with 11.8 million parameters instead of 115.5 million.
  4. Fewer parameters did not mean faster inference: the paper reports about 1.1 seconds per 1,024 by 1,024 image versus about 0.2 seconds for the CNN RCAN.
  5. Successors including Swin2SR and HAT build directly on SwinIR and report better results against it.

深入探讨

SwinIR, short for Swin Image Restoration, is a neural network that takes a damaged or low-resolution image and outputs a cleaner or larger version. Image restoration covers several problems: super-resolution, which enlarges an image while inventing plausible fine detail; denoising, which removes random grain; and JPEG compression artifact reduction, which removes the blocky patterns and color smearing that heavy compression leaves behind. SwinIR handles all of them with one architecture trained separately for each task. It was introduced by Jingyun Liang, Jiezhang Cao, Guolei Sun, Kai Zhang, Luc Van Gool and Radu Timofte of the Computer Vision Lab at ETH Zurich, with KU Leuven, in a paper posted to arXiv on August 23, 2021.

Before SwinIR, the best restoration models were convolutional neural networks (CNNs), which slide small learned filters across an image. The SwinIR paper points to two weaknesses of convolution for this job: the same filter is applied to every region regardless of content, and each filter sees only a small neighborhood, so long-range patterns are hard to use. Transformers, which use self-attention to let every position weigh information from other positions based on content, address both, but full self-attention over every pixel pair is far too expensive for large images. The earlier transformer model IPT also needed more than 115.5 million parameters and pretraining on ImageNet.

SwinIR's answer is the Swin Transformer, a vision backbone posted to arXiv in March 2021 by Ze Liu and colleagues. Swin computes attention only inside small non-overlapping windows, which keeps cost linear in image size rather than quadratic, and it alternates between a regular window grid and one shifted by half a window so that information flows across window borders from one layer to the next. SwinIR adapts this to restoration in three stages. A single 3 by 3 convolution extracts shallow features from the input. A deep feature extraction module then applies a stack of residual Swin Transformer blocks (RSTBs); each contains several Swin Transformer layers followed by a convolution and a skip connection that adds the block's input back to its output. Finally, a reconstruction module combines shallow and deep features and, for super-resolution, enlarges them with a sub-pixel convolution, a layer that rearranges extra feature channels into extra pixels.

The default configuration in the paper uses 6 RSTBs, 6 Swin layers per block, an 8 by 8 attention window, 180 feature channels and 6 attention heads, about 11.8 million parameters for classical super-resolution. A lightweight version cuts this to 4 blocks and 60 channels, under 900,000 parameters. Super-resolution models are trained with an L1 loss, the average absolute pixel difference from the ground truth; denoising and JPEG models use the closely related Charbonnier loss. For real-world photos, where no perfect ground truth exists, the model is retrained on images degraded with the BSRGAN degradation model and trained with a mix of pixel, adversarial (GAN) and perceptual losses to look sharper.

On benchmarks, the paper reports state-of-the-art results on all three task families. In classical super-resolution trained on the DIV2K dataset, SwinIR's largest gain over prior methods was 0.26 dB of peak signal-to-noise ratio (PSNR, a pixel-level fidelity score in decibels) on Manga109 at 4x, and up to 0.47 dB more when trained on DIV2K plus Flickr2K. It beat IPT while using 11.8 million parameters instead of 115.5 million. In lightweight super-resolution it gained up to 0.53 dB at a similar size to competitors. In JPEG artifact reduction it gained at least 0.11 dB and 0.07 dB on two test sets over DRUNet with 11.5 million parameters against DRUNet's 32.7 million. The abstract summarizes the gains as 0.14 to 0.45 dB with up to 67% fewer parameters.

These gains came with costs. The paper reports that on a 1,024 by 1,024 image, the CNN model RCAN took about 0.2 seconds, SwinIR about 1.1 seconds and IPT about 4.5 seconds. The SwinIR repository gives a closer comparison on Manga109 at 4x: SwinIR scored 31.67 dB against RCAN's 31.22 dB with fewer parameters (11.9 million against 15.6 million) and slightly fewer operations, but ran about three times slower on a 256 by 256 input (0.539 against 0.180 seconds) and used more memory. Attention over windows is less hardware-friendly than plain convolution, so fewer parameters does not mean faster inference.

SwinIR also shares the limits of all restoration models. Each model is trained for one task and one degradation level, such as 4x upscaling or noise level 25, and does poorly on inputs that do not match. PSNR rewards blurry averages, so the highest-scoring models can look soft, while GAN-trained real-world models look sharper but can invent textures that were never in the scene. That makes upscaled images unsuitable as evidence of fine detail, for example in forensic or medical settings. Later analysis in the HAT paper (2022) found that window-based super-resolution transformers use only a limited spatial range of the input, which motivated designs that widen it.

In practice SwinIR is easy to use. The official code and pretrained models are released under the Apache 2.0 license, and the repository reports training a classical model in about 1.8 days on eight Nvidia RTX 2080 Ti GPUs for 500,000 iterations. For most people the simplest route is a tool that bundles it, such as the AUTOMATIC1111 web UI's upscaler menu, which lists SwinIR and Swin2SR alongside Real-ESRGAN and ESRGAN.

04工作示例

Tracing a 4x upscale through SwinIR

  1. 从一个 64 x 64 像素的彩色图像开始,该图像应变为 256 x 256。

  2. 3 x 3 卷积将 3 个颜色通道转换为 180 个特征通道,尺寸仍为 64 x 64。

  3. 将 64 x 64 的特征图分割为 8 x 8 的窗口:共 64 个窗口,每个窗口包含 64 个 token,注意力在每个窗口内计算。

  4. 在下一层中,在分割前将地图平移 4 个像素,使得原本位于窗口边缘的 token 现在与其邻居共享同一个窗口。

  5. 经过 6 个块(每个块 6 层)后,通过长跳跃连接将浅层特征加回。

  6. 亚像素卷积将额外的通道重新排列为像素,生成一个 256 x 256 像素、具有 3 个颜色通道的图像。

  7. 使用 PSNR 将结果与真实的高分辨率图像进行比较,并通过肉眼检查边缘和文本。

它显示了什么

学习者可以看到 SwinIR 如何在 64 个 token 的窗口中工作以保持注意力计算的低成本,平移如何连接这些窗口,以及上采样仅在最后发生。比双三次插值更高的 PSNR 证实模型正在恢复细节,而视觉检查则显示这些细节是否合理。

现实世界的实施

创意工具中的照片放大:AUTOMATIC1111 Stable Diffusion Web UI 在其“Extras”选项卡中将 SwinIR 及其继任者 Swin2SR 列为神经网络放大器,用于放大生成的图像。

真实世界超分辨率:SwinIR 仓库提供了用于真实照片的 4 倍 GAN 训练模型,使用 BSRGAN 退化模型进行训练,该模型模拟了真实低质量图像中常见的模糊、噪声和压缩。

JPEG 清理:SwinIR 的伪影减少模型已针对 JPEG 质量级别 10、20、30 和 40 发布,支持灰度和彩色,使用 7 x 7 注意力窗口,这是因为 JPEG 的 8 x 8 块结构。

去噪:单独的 SwinIR 模型可去除级别为 15、25 和 50 的高斯噪声,论文报告称在 Urban100 测试集上,其性能比更大的 DRUNet 模型高出最多 0.3 dB。

研究基准:后续的复原网络,如 Swin2SR(ECCV 2022 研讨会)和 HAT(CVPR 2023),将其结果与 SwinIR 进行对比,使其成为标准的参考点。

SwinIR 变压器恢复的未来

SwinIR's design was quickly extended. Swin2SR, posted in September 2022 by Marcos Conde and colleagues including SwinIR coauthor Radu Timofte, swapped in Swin Transformer V2 to address training instability and data hunger, reported faster convergence and better results than SwinIR, and placed among the top five entries in the AIM 2022 challenge on super-resolution of compressed images and video. HAT, posted in May 2022 and accepted to CVPR 2023, combined channel attention with window attention and an overlapping cross-attention module, and reported gains of more than 1 dB over the prior state of the art. Open problems remain. Restoration models trained on synthetic degradations still struggle when real damage differs from the training recipe, and there is no single metric that captures both fidelity and perceived sharpness: PSNR favors smooth results, while GAN-based and diffusion-based restorers favor plausible detail that may not be real. Running window-attention models at high resolution on phones and in real-time video is still harder than running CNNs of similar quality. The balance between faithful reconstruction and realistic invention remains an active research question rather than a settled one.

付诸实践

为什么这很重要

  • 速度与规模. 视觉人工智能可以大规模自动化检查、检测和标记任务。
  • 构建选择. 创意团队可以通过更少的手动修改更快地构建概念原型。
  • 团队与工作流程. 操作可以使用以前难以处理的图像和视频信号。

留意

  • 如果出处不明,肖像权和同意可能会成为法律风险。
  • 模型性能可能因光照、人口统计和环境的不同而有所不同。
  • 除非监控置信阈值,否则误报可能会被忽视。

后续步骤

  1. 定义精确度、召回率和错误成本的接受标准。
  2. 使用符合实际生产条件的数据进行测试。
  3. 为低置信度或高影响力的预测添加人工审核。
  4. 跟踪模型漂移并在相机或数据集更改后重新验证。

资料来源与延伸阅读

  1. arXivSwinIR:使用 Swin Transformer 进行图像复原
  2. GitHubSwinIR 官方仓库
  3. arXivSwin Transformer:使用移位窗口的分层视觉 Transformer
  4. arXiv (ECCV 2022 Workshops)Swin2SR:用于压缩图像超分辨率和复原的 SwinV2 Transformer
  5. arXiv (CVPR 2023)激活图像超分辨率变换器中的更多像素
  6. GitHubStable Diffusion web UI

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

参加 SwinIR 变换器恢复测验

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

SwinIR 变换器恢复是什么?

SwinIR 是来自苏黎世联邦理工学院的图像恢复网络,发表于 2021 年 8 月,使用 Swin 变换器的移位窗口注意力来放大、降噪并去除 JPEG 图像中的伪影。它之所以重要,是因为它展示了一个约 1200 万参数的紧凑变换器,能够在标准恢复基准上击败更大的卷积和变换器模型,并成为常用的放大器和后续工作的基准。

SwinIR 基于什么变压器架构?

SwinIR 采用 Swin Transformer 的分层、基于窗口的设计来进行图像恢复。

SwinIR的核心注意力机制是什么?

SwinIR 在本地窗口内使用自注意力机制,在层之间切换以混合跨窗口的信息。

SwinIR 的深层功能块叫什么?

深度特征提取阶段堆叠了 Residual Swin Transformer 块,每个块都有 Swin 层、一个卷积和一个残差连接。

为什么基于窗口的注意力比全局注意力更有效?

在固定大小的窗口内计算注意力使得成本与图像区域成线性比例,避免了全局注意力的二次爆炸。

SwinIR 的恢复架构有哪三个主要阶段?

SwinIR 论文描述了浅层特征提取、使用 RSTB 的深层特征提取以及重建模块。