Hierarchically structured Transformer encoder 구조
: multiscale features를 내뱉음. positional encoding이 필요 없기 때문에 학습 이미지와 다른 해상도의 테스트 이미지의 positional code를 interpolation 할 필요가 없음.
Lightweight 디자인의 MLP decoder
: Complex decoder가 필요 없음. MLP로 다른 층들의 information을 aggregate하고 local attention과 global attention을 combining함으로써 powerful representation을 얻음.
Introduction
기존 Segmentation은 두 방법에 의해 연구되어 옴.
특징을 잘 추출하기 위해 Encoder, 즉 backbone을 개선하여 성능 향상시키는 방법
이미지 내의 context 정보를 효율적으로 추출하기 위한 모듈과 연산을 추가하여 성능을 향상시키는 방법
이후 ViT의 등장으로 ViT를 encoder에, CNN을 Decoder에 사용하는 방식으로 좋은 성능을 내는 SETR이 등장함.
하지만 ViT의 Limitations 존재
1) multi-scale이 아닌 single-scale low-resolution features를 반환
2) Large image에 대해서 high computation cost
(ViT는 이미지의 크기가 커지면 패치가 그만큼 늘어나게 되고, 모든 패치들과의 유사도를 계산하는 self-attention의 특성상 연산량이 제곱배로 늘어나게 됨)
이러한 한계 극복을 위해 pyramid vision transformer(PVT)를 제안해서 VIT를 피라미드 구조로 확장하기도 하였다. 또다른 방법으로 Swin Transformer나 Twins가 등장했지만, 이런 방법론들은 주로 Transformer encoder에 초점을 두고 있고 decoder의 추가 개선을 위한 contribution은 neglecting한다는 한계가 있었음. 반면 SegFormer는 encoder와 decoder를 모두 re-design함.
본 연구에서 제안하는 인코더는 inference시에 학습 데이터와 다른 해상도를 가지는 이미지의 positional code를 interpolate하지 않아도 됨.
결과적으로 성능에 영향을 미치지 않으면서 임의의 테스트 해상도에 쉽게 adapt 될 수 있음.
또한 hierarchical 부분은 인코더가 high-resolution fine features와 low-resolution coarse features 둘 다 생성할 수 있도록 함. 이는 고정된 해상도의 single raw resolution feature map만 생성 가능한 ViT와 다른 점임.
Lightweight MPL decoder의 핵심 아이디어는 Transformer-induced features의 장점을 활용해서 lower layers의 attention은 local, highest layer는 highly non-local하다는 특성을 활용함.
즉, local하고 global한 문맥 정보를 모두 잘 활용할 수 있음.
결과적으로 간단하고 직관적인 디코더로 powerful representation을 만들 수 있음.
model size, run-time, accuracy면에서 장점을 demonstrate함. (데이터셋은 ADE20k, Cityscapes, COCO-Stuff)
Method
가장 큰 특징 두가지
Hierarchical Transformer encoder
: 고해상도의 coarse한 특징들과 저해상도의 Fine-grained 특징들을 추출함. 특히 PE(Positional Encoding)를 사용하지 않았기 때문에 inference 시에 다른 크기의 이미지를 사용해도 성능 저하 적음.
경량화된 Decoder
: 더 적은 연산량을 가지며 인코더에서 얻은 모든 특징들을 모두 활용해서 최종출력을 얻어냄
먼저 이미지를 4x4 크기의 패치로 나눔. ViT는 패치 크기 16x16으로 나누었지만 dense prediction task에서는 더 작은 패치 크기가 낫기 때문.
(하지만 패치 크기가 작아진 만큼 self attention 시에 패치 수의 제곱만큼의 연산량이 증가할 것임. 따라서 이를 어떻게 효율적으로 접근할 수 있을지 또한 중요, 뒤에 나옴.)
그리고 이 패치들은 hierarchical Transformer encoder의 input이 되어서 오리지널 이미지 해상도의 1/4, 1/8, 1/16, 1/32 크기의 multi-level features를 얻음
이 multi-level features를 ALL-MLP decoder에 넣어서 H/4 x W/4 X N_cls resolution의 segmentation mask를 예측함.
ViT는 single-resolution feature map만 만들 수 있는 반면 이 모듈의 목표는 CNN-like multi-level features를 만들어서 high-resolution coarse features, low-resolution fine grained features를 모두 만들어서 semantic segmentation의 성능을 끌어올리는 것임.
더 정확히는, HxHx3 크기의 이미지가 주어지면, patch merging을 통해서 hierarchical feature map F_i를 만듦.
기존 ViT에서는 NxNx3 패치를 1x1xC의 벡터형태로 합침. 이를 기반으로 2x2xCi의 패치를 1x1xCi+1의 벡터 형태로 변환시켜 hierarchical feature map을 얻게 됨.
하지만 기존 non-overlapping image/feature patches의 경우 local contiuity를 보존하지 못함.
따라서 patch size K, adjacent patches 간의 stride S, padding size P를 정해서 overlapping patch merging을 수행함. (K=7, S=4, P=3/ K=3, S=2, P=1로 해서 같은 크기의 feature를 만듦.)
즉, convolution network를 사용하여 overlap 되는 patch를 sampling 함.
ex. CNN 커널 사용할 때 overlap해서 계산되듯이 패치 머징을 할때도 padding을 하나를 주고 stride 2를 주면 1/2로 merge 될 수 있음.
Efficient Self-Attention
Encoder의 연산량이 가장 많은 곳은 Self-attention layer 부분임.
기존의 multi-head self attention process는 Q,K,V가 모두 NxC의 같은 차원을 가짐. (N=HXW)
Computational complexity가 O(N^2)이 되어서 큰 이미지 해상도의 경우 문제가 됨.
Segformer의 인코더는 4x4 크기의 패치를 쓰기 때문에 ViT 보다 패치 수가 많아지고 self-attention 연산이 매우 복잡해짐.
따라서 sequence reduction process를 통해 reduction ration R만큼 시퀀스 길이를 줄임.
Linear layer를 거쳐서 지정한 output channel demension 크기의 텐서를 반환함.
따라서 결과적으로 계산 복잡도가 O(N^2/R)로 줄어들음.
본 논문에서는 R을 [64, 16, 4, 1]로 설정함.
간단히 생각하면 linear layer로 channel 수를 줄인 다음 multi-head self attention을 수행한다는 뜻인듯 함.
Mix-FFN
ViT 에서는 positional encoding으로 location information을 주지만, positional encoding의 resolution이 고정되기 때문에 학습 이미지와 다른 해상도가 테스트 시에 나타나게 되면 positional code가 interpolated 되어야 하고 종종 성능 저하로 이어짐.
이를 막기 위해 CPVT에서는 3x3 convolution을 PE와 함께 써서 data-driven PE를 구현함.
하지만 semantic segmentation에서는 positional encoding이 꼭 필요한 것은 아님. 대신에 Mix-FFN을 통해서 location information을 leak하기 위해 zero padding을 이용해서 PE를 대체함.
Feed-forward network(FFN)에 3x3 conv를 쓰는 형태임.
이 3x3 conv 연산이 positional encoding을 대체함.
또한 Depth-wise conv를 사용해서 파라미터 수 줄이고 효율성 증가시킴
Lightweight ALL-MPL Decoder
오직 MLP 층으로만 구성된 lightweight decoder을 통해 다른 방법론들에서 전형적으로 쓰이는 hand-crafted, computationally demanding components를 피함.
이렇게 간단한 디코더가 가능했던 이유는 Hierarchical Transformer encoder가 traditional CNN encoder보다 large effective receptive field(ERF)를 가지기 때문임.
MiT 인코더에서 나온 multi-level feature을 MLP layer에 넣어서 channel 차원을 동일하게 통합함.
feature를 원본이미지의 1/4로 upsample하고 concat함.
concat하면 채널이 4배 증가되었기 때문에 MLP층 거쳐서 원래 채널 차원으로 projection
fused feature로 predict (카테고리 수만큼의 demension으로)
Effective Receptive Field Analysis
Deeplab V3+의 receptive field를 살펴보면 Segformer 보다 상대적으로 작다.
Segformer는 빈 부분 없이 골고루 인식하며 encoder만으로도 global context 또한 잘 인식할 수 있다.
CNN의 제한된 receptive field로 인해 ASPP같은 무거운 모듈을 사용해야 했다면 Segformer는 MiT Encoder의 ERF 덕분에 간단한 decoder 만으로도 넓은 receptive field를 가짐.
Relationship to SETR
SETR과 달리 더 작은 imagenet-1k로 사전학습함
encoder가 계층적 구조를 가지기 때문에 고해상도의 coarse한 특징과 저해상도의 fine한 특징을 잘 얻을 수 있음.
Positional embedding을 사용하지 않아 inference 시에 다른 크기의 이미지를 사용해도 성능 저하 적음.
가벼운 decoder로 더 적은 연산량을 지님.
Experiments
Table 1은 모델 규모에 따른 성능 비교임. 인코더 크기, 디코더 MLP 차원, PE vs Mix-FFN, CNN과의 비교를 하고 있음. 디코더 MLP demension은 256을 디폴트로 함. 특히 Mix-FFN의 경우 두 가지 해상도에 대해 실험을 진행했는데, inference image의 크기가 극단적으로 다를 경우 mIoU가 PE에 비해 확실히 좋은 것을 확인할 수 있음. 또 1d를 보면 CNN based encoder랑 MLP decoder를 coupling하게 되면 확실히 transformer encoder보다 accuracy가 떨어진는 것을 볼 수 있음. 이는 직관적으로 CNN이 Transformer보다 작은 receptive field를 가지기 때문에 decoder가 충분힌 global representation을 얻지 못했을 것으로 해석하고 있음.
Table 3은 동일한 deocder에 대해 두 개의 인코더(ViT, Swin)와 비교하고 있음. 본 연구에서 제안하는 MiT 인코더가 Swin,ViT보다 나은 결과를 보임.
Table2는 SOTA method와의 비교실험임. (FLOPS, latency, accuracy 비교)
모든 데이터셋에 대해 mIoU가 outperform하는 결과를 보임.
Table 5는 자율주행을 위한 데이터셋에 대한 실험 결과인데 corruption, perturbation에 얼마나 robustness한지를 평가하기 위함임. Citiscapes-C는 Cityspaces의 validation dataset임. 그 결과, CNN-based 방법론보다 확실히 좋은 성능을 보였으며 여러 환경에서도 robust한 결과를 보임. (이 실험은 zero-shot 실험이라고 주장하는 것 같은데 살짝 애매함. 본문에는 없고 결론에서 zero-shot이라고 함...하지만 개인적으로는 zero-shot으로 볼 수 있을것같다는 생각)
Conclusion
간단하고 깔끔하지만 강력한 semantic segmentation method인 Segformer 제안함.
Abstract
Hierarchically structured Transformer encoder 구조 : multiscale features를 내뱉음. positional encoding이 필요 없기 때문에 학습 이미지와 다른 해상도의 테스트 이미지의 positional code를 interpolation 할 필요가 없음.
Lightweight 디자인의 MLP decoder : Complex decoder가 필요 없음. MLP로 다른 층들의 information을 aggregate하고 local attention과 global attention을 combining함으로써 powerful representation을 얻음.
Introduction
기존 Segmentation은 두 방법에 의해 연구되어 옴.
이후 ViT의 등장으로 ViT를 encoder에, CNN을 Decoder에 사용하는 방식으로 좋은 성능을 내는 SETR이 등장함.
하지만 ViT의 Limitations 존재
1) multi-scale이 아닌 single-scale low-resolution features를 반환
2) Large image에 대해서 high computation cost
(ViT는 이미지의 크기가 커지면 패치가 그만큼 늘어나게 되고, 모든 패치들과의 유사도를 계산하는 self-attention의 특성상 연산량이 제곱배로 늘어나게 됨)
이러한 한계 극복을 위해 pyramid vision transformer(PVT)를 제안해서 VIT를 피라미드 구조로 확장하기도 하였다. 또다른 방법으로 Swin Transformer나 Twins가 등장했지만, 이런 방법론들은 주로 Transformer encoder에 초점을 두고 있고 decoder의 추가 개선을 위한 contribution은 neglecting한다는 한계가 있었음. 반면 SegFormer는 encoder와 decoder를 모두 re-design함.
Method
가장 큰 특징 두가지
Hierarchical Transformer encoder : 고해상도의 coarse한 특징들과 저해상도의 Fine-grained 특징들을 추출함. 특히 PE(Positional Encoding)를 사용하지 않았기 때문에 inference 시에 다른 크기의 이미지를 사용해도 성능 저하 적음.
경량화된 Decoder : 더 적은 연산량을 가지며 인코더에서 얻은 모든 특징들을 모두 활용해서 최종출력을 얻어냄
1. Hierarchical Transformer Encoder (Mix Transformer, MIT)
Hierarchical Feature Representation
Overlapped Patch Merging
Efficient Self-Attention
Segformer의 인코더는 4x4 크기의 패치를 쓰기 때문에 ViT 보다 패치 수가 많아지고 self-attention 연산이 매우 복잡해짐.
Mix-FFN
Effective Receptive Field Analysis
Relationship to SETR
Experiments
Table 1은 모델 규모에 따른 성능 비교임. 인코더 크기, 디코더 MLP 차원, PE vs Mix-FFN, CNN과의 비교를 하고 있음. 디코더 MLP demension은 256을 디폴트로 함. 특히 Mix-FFN의 경우 두 가지 해상도에 대해 실험을 진행했는데, inference image의 크기가 극단적으로 다를 경우 mIoU가 PE에 비해 확실히 좋은 것을 확인할 수 있음. 또 1d를 보면 CNN based encoder랑 MLP decoder를 coupling하게 되면 확실히 transformer encoder보다 accuracy가 떨어진는 것을 볼 수 있음. 이는 직관적으로 CNN이 Transformer보다 작은 receptive field를 가지기 때문에 decoder가 충분힌 global representation을 얻지 못했을 것으로 해석하고 있음. Table 3은 동일한 deocder에 대해 두 개의 인코더(ViT, Swin)와 비교하고 있음. 본 연구에서 제안하는 MiT 인코더가 Swin,ViT보다 나은 결과를 보임.
Table2는 SOTA method와의 비교실험임. (FLOPS, latency, accuracy 비교) 모든 데이터셋에 대해 mIoU가 outperform하는 결과를 보임.
Table 5는 자율주행을 위한 데이터셋에 대한 실험 결과인데 corruption, perturbation에 얼마나 robustness한지를 평가하기 위함임. Citiscapes-C는 Cityspaces의 validation dataset임. 그 결과, CNN-based 방법론보다 확실히 좋은 성능을 보였으며 여러 환경에서도 robust한 결과를 보임. (이 실험은 zero-shot 실험이라고 주장하는 것 같은데 살짝 애매함. 본문에는 없고 결론에서 zero-shot이라고 함...하지만 개인적으로는 zero-shot으로 볼 수 있을것같다는 생각)
Conclusion