Deep Learning/Paper Review

[Super Resolution] SwinIR / SwinFIR

omocomo 2022. 9. 19. 22:19

Image Restoration은 low-quality 이미지로부터 high-quality 이미지를 복원하는 문제이다.

그 예로 super-resolution, denoising, JPEG compression artifact reduction 등이 있다.

이번에 참가하는 super-resolution 대회에 아이디어를 얻고자 SwinIR / SwinFIR 논문을 읽어보았다.

SwinIR

1. Introduction

1.1 CNN

Image Restoration 분야에서 오랫동안 사용되고 있는 CNN-based 방법들은 residual learning, dense connection 등을 사용해 더 좋은 구조를 만들고 있지만, 몇 가지 단점이 존재한다.

1) images와 convolutional kernels 간의 상호작용이 content-independent 하다.

image의 모든 다른 영역에 같은 kernel이 사용(shared parameters)되는데 이 방법이 좋지 않을 수 있다.

왜? content에 의존하지 않아서 중요한 contexts를 잃을 수 있다.

may lose some important contexts and further limit fusion performance (SwinFuse)

2) not effective for long-range dependency modeling

일반적으로 사용하는 cnn은 local만 볼 수 있는 구조이기 때문에 long-range dependency 문제가 있다.

(Non local Neural Network)

1.2 Transformer

이런 CNN의 문제를 해결할 수 있는 대안으로, Transformer는 self-attention mechanism을 이용해 global한 정보를 이용한다. Image Restoration에 Vision Transformer를 적용한 몇 가지 논문들이 있는데, 여기서는 이미지를 고정된 크기의 patch로 자르고, 각 patch를 독립적으로 처리해 또 다른 문제가 발생한다.

1) border pixels이 neighbouring pixels을 이용하지 못한다.

2) patch 주변에 border artifacts가 생길 수 있다.

→ 이는 patch overlapping으로 어느 정도 완화할 수 있지만, 추가적인 computation이 발생한다.

(여기서 말하는 독립적인 patch들은 patch 간 attention을 수행하는 ViT와는 다른게 맞나?)

1.3 Swin Transformer

최근에는 CNN과 Transformer의 장점을 통합한 Swin Transformer를 사용한 방법이 좋은 전망을 보였다.

local attention mechanism을 사용하여 큰 이미지도 처리하는 CNN의 장점과

long-range dependency(with the shifted window scheme)를 갖는 Transformer의 장점

 

+ ViT vs SwinT

Swin Transformer 논문

여기서 잠깐! Swin Transformer(SwinT)와 지난 리뷰에서 다룬 ViT가 뭐가 다르고 shifted window가 뭔지 간단하게 알아보고 가려고 한다.

SwinT의 특징은 Hierarchical feature maps, Window-based Self-attention이다.

Hierarchical feature maps: 계층적인 정보를 활용할 수 있다. (FPN, U-Net 처럼)

Window-based Self-attention: 연산량을 줄일 수 있다. (ViT가 해상도에 대해 quadratic한 연산량을 가졌다면, SwinT는 선형 계산 복잡도를 갖는다.)

1) 기존 ViT에서 고정된 크기의 patch를 사용했다면, SwinT에서는 위의 왼쪽 그림에서도 볼 수 있듯이 window내의 여러 patch를 사용하고, patch merging을 통해 그 크기를 키워나간다.

2) SwinT는 각 window 내에서만 self-attention을 계산하는데, 이를 transformer에 inductive bias를 가한 것이라 해석해 볼 수도 있다.

3) 그렇다면 다른 window와의 attention은 전혀 고려하지 않을까? 이를 해결한 게 shifted window이고, 이를 통해 window 간의 공유도 어느정도 가능하다. 그리고 이 연산을 위해 아래의 cyclic shift와 mask를 사용했다.

 

Shifted Window

ViT에서 연산량은 크게 줄이면서 성능의 저하는 최소한으로 만든 것이 SwinT라고 볼 수 있다. 또한, SwinT는 다양한 크기의 patch를 이용해 hierarchical한 구조를 가지고 있어, object detection이나 semantic segmentation과 같은 multi-scale information이 중요한 task에서 좋은 성능을 보인다. 

SwinT를 Image Restoration에 적용하여 SwinIR을 제시한다. 크게 다음 3개의 모듈로 이루어져 있다.

1) Shallow feature extraction module

2) Deep feature extraction module

3) High-quality image reconstruction module

 

2. Method

2.1 Shallow feature extraction module

low quality input에 3x3 convolutional layer를 사용하여 shallow feature를 뽑아낸다.

visual processing 초반에 conv layer를 사용하는 것이 더 안정적인 optimization과 더 나은 결과를 얻을 수 있으며,

(Early convolutions help transformers see better - Our results indicate that injecting a small dose of convolutional inductive bias into the early stages of ViTs can be hugely beneficial.)

input image를 간단하게 고차원 feature space로 mapping 할 수 있는 방법이기 때문에 초반에 shallow feature를 뽑기 위해 CNN을 사용한다.

2.2 Deep feature extraction module

앞서 나온 shallow feature를 input으로 K개의 Residual Swin Transformer blocks(RSTB)와 3x3 convolutional layer를 통해 deep feature를 뽑아낸다.

conv layer를 마지막에 사용하면, Transformer-based network에 conv의 inductive bias를 가져오는 효과가 있다. 그리고 나중에 shallow + deep feature를 할 때 더 나은 기반을 마련한다.

 

+ RSTB (Residual Swin Transformer blocks)

RSTB는 SwinT block에 residual connection과 convolutional layer를 추가한 구조이다.

이러한 구조는 두 가지 장점을 가진다.

1) spatially invariant filters(같은 kernel 사용)를 갖는 convolutional layer translation equivariance를 향상시킨다.

2) residual connection을 통해 다른 levels(blocks)의 features를 aggregation할 수 있도록 한다.

 

2.3 High-quality image reconstruction module

마지막 reconstruction module은 shallow features와 deep features를 aggregate한다.

shallow features는 low-frequencies를 담고 있고, deep features는 손실된 high-frequencies를 복원하는데 집중한다.

skip connection을 통해 low-frequencies 정보들도 직접 reconstruction module에 전달하기 때문에, deep feature extraction module에서는 high-frequencies 정보와 안정적인 학습에 집중할 수 있다.

image reconstruction module은 task에 따라 그 구조가 달라질 수 있는데,

upsample이 필요한 super-resolution의 경우 sub-pixel convolution layer를 사용한다.

(그 외의 denoising, JPEG compression에서는 single convolutional layer를 사용)

2.4 Loss Function

super-resolution task에서는 L1 pixel loss를 사용한다.

(denoising, JPEG compression에서는 Charbonnier loss를 사용)

classical and lightweight image SR에서는 naive L1 pixel loss를 사용했지만

real-world image SR에서는 퀄리티를 높이기 위해 combination of pixel loss, GAN loss and perceptual loss를 사용했다.

 

3. Experiments

결론적으로 SwinIR이 Super-resolution, Denoising, JPEG Compression task에서 더 적은 parameters로 더 좋은 성능을 달성했다. 다른 내용은 논문을 참고하는 것으로 하고, 여기서는 Super-resolution과 관련해 참고할만한 내용들만 간단히 살펴보려고 한다.

3.1 Ablation Study and Discussion

Impact of channel number, RSTB number and STL number.

늘릴수록 성능이 높아진다.

Impact of patch size and training image number; model convergence comparison.

patch size를 크게 하고, training image 수를 늘릴수록 성능이 높아진다.

기존의 Transformer-based models은 CNN 모델보다 더 큰 training data를 필요로 한다고 알려져 있는데,

SwinIR은 같거나 더 적은 데이터셋으로도 더 높은 성능을 보여준다.

CNN-based method (RCAN)보다 더 빠르게 수렴한다.

Impact of residual connection and convolution layer in RSTB.

residual connection을 사용했을 때 약간의 성능 향상이 있다.

1x1 conv는 3x3 conv가 갖는 local neighbouring information을 추출하지 못하기 때문에 성능이 약간 더 낮다.

three 3x3 conv는 parameter 수를 줄일 수 있지만 성능도 살짝 떨어졌다.

 

3.2 Results on Image SR

Classical image SR.

SwinIR can restore high-frequency details and alleviate the blurring artifacts, resulting in sharp and natural edges. In
contrast, most CNN-based methods produces blurry images or even incorrect textures.

Real-world image SR.

we re-train SwinIR by using the same degradation model as BSRGAN for low-quality image synthesis.

BSRGAN:Designing a Practical Degradation Model for Deep Blind Image Super-Resolution

SwinIR Github

(Degradation과 관련하여 BSRGAN도 한 번 봐야겠다..)

 

SwinFIR

위에서 다룬 SwinIR 내용을 바탕으로 간단하게만 다루려고 한다.

1. Introduction

이 논문의 contribution을 정리하자면 다음과 같다.

- SR task에서 global information을 활용할 수 있도록 설계한 Spatial Frequency Block (SFB)을 이용한 SwinFIR을 제시한다. SFB는 more comprehensive, detailed, and stable features를 추출하는 Fast Fourier Convolution(FFC)에 기반한 구조이다. spatial model, frequency model 이렇게 두 개의 branch로 구성되어 있다.

- data augmentation(channel shuffle, mixup 등) 방법

- 새로운 ensemble 전략 feature ensemble, 여러 trained model을 training/testing time 증가 없이 통합할 수 있는 방법

 

2. Method

2.1 Model design

SwinIR에서 RSTB와 Deep feature extraction module의 마지막 conv layer를 SFB로 바꾼 것이 전부다.

SFB의 frequency module에서는 2-D Fast Fourier Transform(FFT)를 이용해 conventional spatial features를 frequency domain으로 바꾸고 global information을 추출한다. 마지막에 spatial, frequency를 concat해 conv layer를 통과한다.

(더 구체적인 설명은 논문 참고.. 나중에 추가할지도..)

(2D FFT에 대한.. 유튜브 영상 2D FFT의 작동 원리, 2D 푸리에 변환-예제)

+ spatial domain vs frequency domain (더 알아봐야 함)

2.2 Loss Function

여기서는 Charbonnier loss가 가장 좋은 성능을 보였다고 한다. SwinIR에서는 super-resolution 이외의 task에 이 loss를 사용해 넘어갔는데, Penalty term(ϵ)을 넣어 Outlier에 robust한 특징이 있다.

2.3 Data Augmentation

Image super-resolution에서 spatial transformation(rotation, flip) 뿐 아니라 pixel-domain(RGB channel shuffle, Mixup, Blend, CutMix and Cut-Mixup) 등의 data augmentation 효과를 살펴본다.

visual continuity를 destroy하는 CutMix and Cut-Mixup을 제외한 다른 방법들을 data augmentation에 사용했고 성능의 향상이 있었다.

training data 늘리기, window size 늘리기, pre-trained model 사용은 이전 연구들에서 충분히 입증된 것들이다.

2.4 Feature Ensemble

기존에 SR에서 Multi-model ensemble과 self-ensembles가 주로 사용되었다.

Multi-model ensemble: combines the inference results from various models

self-ensembles: averages the transformed outputs from one model and input image

이 방법들은 inference time이 증가한다는 단점이 있다.

이 논문에서 제시한 Feature ensemble 방법은 validation set에 대해 잘 동작하는 다수의 모델을 선택해 trained model의 parameter를 weighted average해 ensemble 하는 것이다.

3. Conclusion

Reference

# 논문

SwinIR: Image Restoration Using Swin Transformer

SwinFIR: Revisiting the SwinIR with Fast Fourier Convolution and Improved Training for Image Super-Resolution

An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale

Swin Transformer: Hierarchical Vision Transformer using Shifted Windows

 

# 강의

딥러닝논문읽기모임 Swin Transformer 논문 리뷰

 

# 블로그

인공지능 스터디룸 [논문 리뷰] SwinIR

CNN의 stationarity와 locality