sy00n / DL_paper_review

issues에 논문 요약
0 stars 0 forks source link

[7] WinCLIP: Zero-/Few-Shot Anomaly Classification and Segmentation #7

Open sy00n opened 1 year ago

sy00n commented 1 year ago

paper link : https://arxiv.org/pdf/2303.14814v1.pdf

Visual Anomaly Classification & Segmentation task의 Challenge

Visual Anomaly Classification(AC) & Segmentation(AS) task는 제조 산업에서 이상을 분류하고 localize하여 이미지나 픽셀이 정상인지 비정상인지 예측한다. Visual Inspection은 long tail 문제인데 object와 defect의 종류가 매우 다양하다. 따라서 두 메인 callenge로 이어진다.

image

문제 1) Defects는 넓은 범위의 variations로 인해 학습 시 anomaly sample의 representation이 부족하다.

image

문제 2) 이전 연구들은 각각의 visual inspection task에 specific한 model을 학습하는 데 중점을 두었는데, 이는 여러 task의 long-tail문제로 확장할 수 없다. (여기서 말하는 task는 제조업이나 회로 기판, 나무 크랙 탐지 등과 같은 도메인을 말하는 것 같음. )

본 논문에서의 접근

이 논문은 zero-shot , few-normal-shot에 초점을 두고 다음과 같이 가설을 세운다.
'Language is perhaps even more important for zero-shot/few-normal-shot anomaly classification and segmentation.' 그 이유는 아래와 같다.

  1. "정상"과 "비정상"은 상황에 따라 달라지는 state 이며 Language는 이러한 state를 명확히 하는 데 도움이 된다. ex) 옷감의 구멍은 이상일 수도 있고 패션을 위해 만든 구멍이라면 정상일 수도 있음. Language는 이러한 맥락과 특수성을 광범위한 정상, 비정상 상태로 다룰 수 있다.

  2. Language는 defect를 정상으로부터 허용 가능한 편차(acceptable deviation)와 구별하기 위한 추가적인 정보를 제공할 수 있다. image fig2에서 Language는 soldering defect에 대한 정보를 제공하지만 배경에서의 사소한 긁힘/얼룩은 허용된다. 이러한 장점에도 불구하고 anomaly segmentation/classification에서 vision-language model을 쓰는 연구가 많이 진행되지 않았다.

그런데 CLIP을 그냥 쓰게 되면 몇개의 문제가 있다.

  1. naive prompt는 효과적이지 않다. (table3 참고) 그래서 우리는 state-level word ensemble을 통해 normal/anomalous states를 더 잘 설명한다.
  2. CLIP은 이미지와 텍스트의 global embedding에서만 cross-modal alignment를 수행하도록 학습한다. 그러나 anomaly segmentation을 위해 pixel-level의 분류를 수행하고 dense visual feature를 얻기는 쉽지 않다. 따라서 vision-language alignment를 보장하면서 multi-level feature를 추출하고 aggregate하는 새로운 window 기반의 clip(WinCLIP)을 제안한다.

Contribution 요약

  1. naive CLIP 기반 zero-shot classification보다 zero-shot anomaly classification을 개선한 compositional prompt ensemble을 소개한다.
  2. we propose Win-CLIP, that efficiently extract and aggregate multi-scale spatial features aligned with language for zero-shot anomaly segmentation. As far as we know, we are the first to explore language-guided zero-shot anomaly classification and segmentation.
  3. We propose a simple reference association method, which is applied to multi-scale feature maps for image based few-shot anomaly segmentation. WinCLIP+ combines the language-guided and vision-only methods for few-normal-shot anomaly recognition.
  4. We show via extensive experiments on MVTec-AD and VisA benchmarks that our proposed methods Win-CLIP/WinCLIP+ outperform the state-of-the-art methods in zero-/few-shot anomaly classification and segmentation with large margins. (+붙은게 few-shot, 안붙은게 zero-shot)

Method

image 전체적인 작동 방식은 fig4와 같다. various state/template로부터 정상과 이상에 대해 각 average state vector를 구한다. (class protytpe을 구한다고 볼 수 있음.) 이 text 정보를 가지고 image encoder에서 multi scale feature와 association 한다. 만약 few-shot 이미지가 있는 경우 아래처럼 normal reference를 추가로 활용한다. 이 때 multi-level window로 각각 anomaly score map을 생성하고 aggregate 되는데 zero-shot의 경우는 language-guided score map 만으로 scoring을 하고 few-shot의 경우는 vison-based와 language-guided anomaly score map을 모두 활용해서 scoring한다. image classification task에서는 patch embedding만 활용해서 scoring하고 image segmentation task에서는 multi scale을 모두 aggregate해서 scoring 한다.

Two-class design

CLIP을 adapting해서 binary zero-shot anomaly classification framework CLIP-AC를 도입한다. 이 때 정상과 비정상을 모두 사용해서 two-class로 학습한다. 우리는 two-class design이 one-class dseign보다 성능이 더 좋음을 실험적으로 확인했다. 이를 통해 다음과 같은 점들을 알 수 있다.

  1. large web dataset에서 pre-train 된 clip이 anomaly task에 대한 text와 image사이의 align을 잘 해서 좋은 representation으로 이어진다.
  2. 좋은 성능을 위해서는 anomaly에 대한 특정 정의가 필요하다.

Compositional prompt ensemble (CPE)

object level classifiers와 달리 CLIP-AC는 주어진 object의 two state, 즉 task에 따라 다양하고 주관적인 정의를 가지는 정상 또는 이상 사이의 분류를 수행한다. (ex) "missing transistor"는 circuit board에 대한 anomaly state이고 "cracked"는 wood에 대한 anomaly state임. )

이 때 object의 두 가지 abstract states를 더 잘 정의하기 위해 우리는 abstracted state를 자유롭게 정의하는 대신 (a) state words per label , (b) text template 의 pre-defined lists 조합을 생성하는 compositional prompt ensemble을 제안한다.

아래 그림은 ViSA dataet에 대 state words per labels 예시이다. 두 class에 대해서만 예시로 첨부하였지만, task-specific state가 굉장히 구체적이다. image

image

위 그림과 같이 state와 template의 모든 조합을 가져온 후 레이블 당 평균 텍스트 임베딩을 계산하여 정상 및 비정상 클래스를 나타낸다. CPE는 object label(ex. Cat)을 설명하지 않고 오직 trial-and-error로 select 된 template을 augment한다(ex. a Cartoon [c]). 따라서 CPE는 CLIP의 joint embedding space에서 더 잘 align된다. (한마디로 object level이 아닌 state/template level로 supervision을 주니까 더 좋다는 뜻)

Remark

two-class design with CPE는 기존에 one-class 접근법과 비교했을 때 anomaly을 정의하는 새로운 접근 방식이다. Anomaly detection은 open-ended nature로 인한 ill-posed problem이다. 이전 방법들은 정상에서 벗어난 것은 모두다 이상으로 간주하여 정상 이미지만으로 모델링한다. 이러한 방법은 정상에서 허용 가능한 편차와 실제 이상을 구별하기 어렵다. (ex. ”scratch on circuit” vs. ”tiny yet acceptable scratch”.) 그러나 language는 구체적인 단어로 state를 정의할 수 있다.

4.2 WinCLIP for zero-shot AS

WinCLIP의 수행 방식은 아래와 같다. window를 만들때 binary mask로 scale을 조정해주는 방식이다. (MAE처럼 마스킹 된 부분을 reconstruction하는게 아니라 그냥 scale조정 용도로 마스킹을 하는 것임.) image

fig3을 보면 CLIP image encoder를 통한 멀티 스케일 feature extraction을 보여주고 있다.

또 추가로 natural dense representation candidate인 penultimate feature map을 쓴다. 풀링하기 전에 특히 fig3 상단에 있는 ViT 기반 CLIP의 patch embedding map의 경우 segmentation을 위해 ascore0을 적용한다. 그러나 patch-level features가 language space에 잘 align되지 않아 dense prediction이 좋지 않음을 발견했다. 이러한 원인이 CLIP에서 language signal로 directly supervise되지 않았기 때문일 것이라고 추측한다. 또한 이러한 patch features는 이미 self -attention에서 global context가 aggregated 되었기 때문에 segmentation을 위한 local details 캡쳐를 방해한다.

image

Penultimate features와 비교했을 때 WinCLIP으로 얻은 dense features가 language에 더 잘 align된다. 또 sliding window를 통해 feature가 local details에 더 집중할 수 있다. 마지막으로 WinCLIP은 특히 ViT 아키텍쳐를 사용하여 효율적으로 연산할 수 있다. (2)번 식의 계산은 마스킹 된 오토인코더와 유사한 방식으로 전달하기 전에 마스킹된 패치를 모두 삭제함으로써 효율적인 연산을 할 수 있다. (reference : MAE)

Harmonic aggregation of windows

각 local window에 대해 zero-shot anomaly score은 window featrue와 (CPE에서 구한) text embeddding의 similiarity이다. 이 점수는 local window의 모든 픽셀에 대해 계산된다. 그리고 각각의 pixel에서 overlapping window에서 여러 점수를 aggregate해서 harmonic averaging으로 segmentation을 개선하고 score에 정규성 예측(0값)에 더 많은 가중치를 부여한다. 식은 (3)과 같다. image

Multi-scale aggregation

Kenel size k는 WinCLIP feature(2) 연산에서 각 위치에 대한 주변 컨텍스트의 양에 해당한다. segmentation에서 local details와 global information 사이의 벨런스를 조절하는 역할을 한다. small 부터 large scale까지 다양한 크기의 defects를 캡쳐하기 위해서 우리는 multi-scale feature로 prediction을 aggregate한다.
(ex. (a) small-scale (2 × 2 in patch scales of ViT; corresponds to 32×32 in pixels), (b) mid-scale (3×3 in ViT; 48×48), and (c) image-scale feature (ViT class token capturing image context due to self-attention. )
이 때, harmonic averaging 방식으로 aggregation 한다. (fig 3에서 멀티 스케일 보여주고 있음.)

4.3 WinCLIP + with few-normal-shots

포괄적인 anomaly classification 및 segmentation의 경우 특정 defect은 텍스트가 아닌 visual reference만으로만 정의할 수 있으므로 language-guided zero-shot approach는 충분하지 않다. (MVTec AD의 Metalnut에는 flipped upside down이라는 이상 유형이 있으며 이는 일반 이미지에서만 상대적으로 식별 가능하다. ) anomaly state를 보다 정확하게 정의하고 인식하기 위해 K개의 normal reference 이미지를 통합해서 WinCLIP, WinCLIP로의 확장을 제안한다.
image

먼저, cosine similiarity를 기반으로 D의 memory features를 간단히 저장하고 검색할 수 있는 given reference images를 통합하는 핵심 모듈로 reference assosiation을 제안한다. 이러한 모듈에 대해 쿼리 이미지 feature F가 주어지면 anomaly semgnetation 예측 M은 아래 식과 같다. image 그 다음 assosiation module을 multiple scale의 feature map에 적용한다. 3개의 reference memory를 얻으면 (Rz, Rm, Rp) 주어진 쿼리에 대한 multi scale prediction을 평균낸다. image 그 다음 language guided prediction M-와 합친다.

anomaly classification을 수행하기 위해 Mw의 maximum value, zero-shot classification score를 결합한다. 두 score는 서로 보완되는 정보를 가진다. (few shot reference로부터의 spatial features + CLIP knowledge retrieved via language) image

anomaly segmentation 시에도 역시 zero shot에서 구한 score map이랑 few shot segmentation을 합쳐서 구한다. (image only + language supervision 합쳐줌)

Experiments

image

table 1에서 비교하는 CLIP-AC는 original CLIP zero-shot classification with labels of the form {“normal [c]”, “anomalous [c]”} 이다. 그리고 CLIP-AC with the prompt ensemble from engineered for imageNet과 비교한다. 제로샷 ,퓨샷에서 모두 WinCLIP의 성능이 기존 연구들보다 개선되었다. 또기존 연구들과 비교했을 때 제로샷 성능이 견줄만 함을 보여주고 있음.

image table 4는 segmentation 성능, 나머지는 ablation study 이다.

image 정량평가 결과이다.

추가적인 ablation study이다. small-scale, mid-scale, penultimate feautre(global context) 활용 정도에 대한 ablation도 있다.

image

Conclusion and Discussion

image 개인적으로 느낀 점은, 기존 연구들은 대부분 few-shot task정도까지는 다루었으나 (patchcore같은 경우에도 메모리뱅크를 활용하는 방식이다보니 zero-shot까지의 확장은 불가능한 구조였다.) 본 논문에서는 zero-shot task, few-shot task 모두 가능한 anomaly detection inference 방법론 최초로 제안했다는 점에서 의의가 있다고 생각한다. 그리고 segmentation 성능을 높이기 위해 multi-scale로 이미지를 feed해주기 위한 window-based 방법론을 사용해서 이미지와 랭귀지를 잘 align시키고 계산효율적인 점 또한 장점이라고 생각한다.

한계를 꼽자면, 개인적으로 task-specific prompt를 보면 이미지의 정보를 너무 많이 노출하고 있다는 생각이다. 거의 위치정보(edge, corner 등)까지 state로 날려주고 있기에 (코드 공개는 안되어있지만 CVPR conference base code에서 state를 제공하고 있음) 과연 zero-shot task로 봐도 될지는 잘 모르겠음.

그리고 그렇게 구체적인 state를 날려준거에 비해 성능 개선 폭이 매우 뚜렷하지 않았던 점도 아쉬움. table 7을 보면 PCB같이 state의 효과가 컸던 class들만 보여주고 있고 전체 class에 대한 성능은 supplymentary에서도 찾아볼 수 없는데, 전체 평균 성능 향상 폭에 비해 특정 class의 성능 향상 폭이 훨씬 크므로 어떤 class들에 대해서는 구체적인 state가 오히려 성능 저하를 야기했을 것으로 보임. 그래서 과연 이 논문에서 제시하는 prompt engineering이 anomaly detection에 매우 효과적인 방법론일지는 조금 의구심이 들음.

또한, 구체적인 prompt를 사용하는거에 비해 CLIP 방법론과 동일하게 모든 class별 임베딩을 평균내버려서 클래스 당 하나의 평균 prototype vector를 구해서 이 representation vector로 similarity를 구해가기 때문에 구체적인 prompt를 잘 활용하고 있지 못하는 것으로 보임. 그래서 차라리 앞단에서 바로 평균내지 말고, 좀더 다양한 조합으로 similarity를 구하고 나서 뒤쪽에서 통합하는 방식으로 실험해보는 것도 성능 개선에 도움이 되지 않을까? 하는 생각이다. (물론 연산량은 매우 많아질듯)