Preliminary knowledge
1. Image segmentation task
- definition: category 혹은 instance membership으로 pixel을 group하는 것
- image segmentation task 종류는 대표적으로 3가지가 있음
- semantic segmentation
- panoptic segmentation
- instance segmentation
![](https://velog.velcdn.com/images/sshinohs/post/8719698b-51da-4ef4-8023-689251a1780d/image.png)
2. Per-pixel vs mask classification
![](https://velog.velcdn.com/images/sshinohs/post/fff11aa5-3d1f-4d7d-9516-6347b405c92a/image.png)
- image segmentation task를 위한 분류 방법으로 두 가지가 있음
- per-pixel classification
- mask classification
- 각 task 별 주요 분류 방법
- semantic segmentation
- FCN 이전 → mask classification 우세
- FCN → per-pixel classification 우세
- panoptic segmenation, instance segmentation은 mask classification 사용
- MaskFormer 이전에는 3가지 task 각각 개별적으로 특화된 architecture들이 개발되어 왔음
- MaskFormer, Mask2Former는 3가지 task를 모두 해결하는 universal architecture이며, mask classification을 사용함
1. Key insight
- mask classification은 semantic- instance-level segmentation 둘 다 해결할 수 있을 만큼 충분히 general 하므로 둘 다 동일한 model, loss, training procedure로 해결할 수 있는 방법을 찾아보자
- Per-pixel classification → Mask classification
![](https://velog.velcdn.com/images/sshinohs/post/fff11aa5-3d1f-4d7d-9516-6347b405c92a/image.png)
2. From Per-Pixel to Mask Classification
- H×W image에서 각 pixel이 가질 수 있는 K개의 category에 대한 확률 분포를 예측하는 것
- probability distribution
- y={pi∣pi∈ΔK}i=1H⋅W
- ΔK: K-dimensional probability simplex
- ground truth category labels
- ygt={yigt∣yigt∈{1,...,K}}i=1H⋅W
- cross-entropy (negative log-likelihood)
- Lpixel_cls(y,ygt)=∑i=1H⋅W−logpi(yigt)
- binary masks
- {mi∣mi∈[0,1]H×W}i=1N
- set of N probability-mask pairs
- z={(pi,mi)}i=1N
- pi∈ΔK+1 (No object도 포함해야 하므로 K+1)
- ground truth
- zgt={(cigt,migt)∣cigt∈{1,...,K},migt∈{0,1}H×W}i=1Ngt
- 일반적으로 set ∣z∣=N과 set ∣zgt∣=Ngt가 다르므로, N≥Ngt로 가정하고 ground truth에 padding을 "no object" token 으로 채움
- semantic segmentation의 경우 N=K (fixed matching) 가능
- bipartite matching-based assigment를 사용하여 zi, zjgt matching함
- −pi(cjgt)+Lmask(mi,mjgt)
- Lmask: binary mask loss
- 3가지 부분으로 구성되어 있음
- Transformer module
- Pixel-level module
- Segmentation module
![](https://velog.velcdn.com/images/sshinohs/post/165c6dfb-c9d1-49ec-a10e-a517d1277095/image.png)
Pixel-level module
- low-resolution의 image feature map F 생성
- F∈RCF×SW×SW
- CF: 채널 수
- S: stride 수
- pixel decoder에서 upsample 하여 per-pixel embedding 생성
εpixel∈RCε×H×W
- Cε: embedding dimension
- cross entropy 적용
- Lmask−cls(z,zgt)=∑j=1N[−logpσ(j)(cjgt)+1cjgt=∅Lmask(mσ(j),mjgt)]
- standard Transformer decoder 사용
- 입력: image features F, learnable positional embeddings (즉, query) N
- 출력: N개의 per-segment embeddings Q∈RCQ×N
- global information을 encode함
Segmentation module
- N class predictions: Q에 대해 softmax activation과 함께, linear classifier 적용 {pi∈ΔK+1}i=1N
- N mask embeddings: MLP 적용, εmask
- N mask prediction: εpixel과 εmask를 dot product하여 구함
2.4 Mask-classification inference
- General inference는 panoptic 혹은 semantic output format
- Semantic inference는 semantic 전용
General inference
- argmaxi:ci=∅pi(ci)⋅mi[h,w]
- most likely class label ci=argmaxc∈{1,...,K,∅}pi(c)
- 직관적으로 각 pixel에서 가장 확률 높은 class로 할당
- semantic segmentation의 경우 동일 class에 대해 merge 됨
- instance-level segmentation task의 경우 index i가 다르면 구분됨
- panoptic segmentation에서 false positive rate를 줄이기 위해서, previous inference strategy를 사용 ?
- low-confidence prediction을 사전에 제거함
- 많이 occluded 된 부분도 처리함
Semantic inference
- "no object" category(∅)이 없는 경우 사용
- 경험적으로 general inference보다 성능이 좋음
- argmaxc∈{1,...,K}∑i=1Npi(c)⋅mi[h,w]
- However, we observe that directly maximizing per-pixel class likelihood leads to poor performance. We hypothesize, that gradients are evenly distributed to every query, which complicates training.??
3. Experiments
Datasets
- ADE20K
- COCO
- Mapillary Vistas
- ...
Evaluation metrics
Baseline models
- PerPixelBaseline
- PerPixelBaseline+
![](https://velog.velcdn.com/images/sshinohs/post/a2acdb3a-ad8d-44cf-adf6-d9c21119e1e9/image.png)
3.1 Implementation details
Backbone
Pixel decoder
Segmentation module
- MLP
- 2 hidden layers
- 256 channels
Loss weights
- mask loss에 focal loss, mask loss 사용
- Lmask(m,mgt)=λfocalLfocal(m,mgt)+λdiceLdice(m,mgt)
![](https://velog.velcdn.com/images/sshinohs/post/79949f44-b642-438a-99c6-0631bb42151d/image.png)
- MaskFormer는 specialized architecture의 성능을 능가하지 못했음
- Mask2Former는 능가함
![](https://velog.velcdn.com/images/sshinohs/post/a3c7cc8d-1bb5-4ad0-8fb0-7b014ebdc317/image.png)
- Transformer decoder 제안
- cross-attention을 foreground region 내부로 제한함
- multi-scale
2.1.1 Masked attention
- Standard cross-attention
Xl=softmax(QlKlT)Vl+Xl−1
- 변형
Xl=softmax(Ml−1+QlKlT)Vl+Xl−1
2.1.2 High-resolution features
2.2.3 Optimization improvements
- masked attention, self-attention 순서를 변경하여 최적화
2.2 Improving training efficiency
- loss 계산 시 mask 대신에 sampled point 사용하여 훈련 효율 상승