본문 바로가기

deep learning

PaDiM: a Patch Distribution Modeling Framework for Anomaly Detection and Localization 리뷰

 

computer vision에서 anomaly detection은 이미지에 대한 anomaly score를 주는 것으로 구성된다. anomaly localization은 각 픽셀, 또는 각 픽셀들의 패치에 anomaly score를 할당하여 anomaly map을 출력하는 더 복잡한 태스크다. 따라서 anomaly localization은 더 정확하고 해석 가능한 결과를 생성한다. anomaly detection은 normal과 anomalous classes 사이에 binary classification이다.

anomaly 예가 부족하기 때문에 이 태스크에서 full supervision으로 model을 학습하는 것은 사실상 가능하지 않다. 게다가 anomalies는 예상되지 않는 패턴을 가질 수 있다. 따라서 anomaly detection model은 종종 one-class learning 설정에서 estimate되어야 한다. 예를 들어, 학습 데이터셋이 오직 normal class의 이미지들을 포함하고 anomalious 예는 학습 동안 이용할 수 없을 때, 테스트 시간에서 일반 학습 데이터셋과 다른 예는 anomalous로 분류된다.

anomaly detection에서 두 가지 방법을 사용할 수 있다. 무거울 수 있는 deep neural network training을 요구하거나, 테스트 시간에서 전체 학습 데이터셋에 대한 k-nearest-neighbor(K-NN) 알고리즘을 사용하는 것이다. KNN algorithm의 경우 linear complexity는 학습 데이터셋의 크기가 커짐으로 시간 및 공간 복잡도가 증가한다. 두 확장성 문제는 산업 context에서 anomaly localization 알고리즘의 개발에 문제가 될 수 있다.

 

Approach

앞서 언급한 문제점을 완화하기 위해 patch distribution modeling을 위한 new anomaly detection과 localization 접근을 제안하다. PaDiM은 embedding extraction을 위해 preteained convolutional neural network를 이용하며, 다음 두 속성을 따른다.

  • Each patch position is described by a multivariate Gaussian distribution
  • PaDiM takes into account the correlations between different semantic levels of a pretraind CNN

 

Introduction

PaDiM은 MVTec AD와 STC datasets에서 anomaly detection과 localization 모두 state-of-the-art 접근을 능가한다. state-of-the-art performance를 보임에도 불구하고 낮은 복잡도로 많은 산업 응용에서 적합하다.

PaDim은 one-class learning 설정에서 image의 anomalies를 detect, localize 할 수 있는 patch distribution modeling을 위한 새로운 뼈대의 작업이다. patch embedding에 pretrained convolutional nueral network를 사용하고, 일반 클래스의 probabilistic representation을 얻기 위해 multivariate Gaussian distributions을 사용한다. 이 때 semantic levels 사이의 correlation을 이용해 더 향상된 localize가 가능하다.

PaDiM은 anomaly localization을 위해 patch embeddings를 생성한다. 일반 클래스는 사용되는 pretrained cnn model의 semantic levels 사이에 correlations이 모델링되는 Gaussian distribution의 set을 통해 설명된다. pretrained cnns는 anomaly detection에 대해 relevant features를 얻을 수 있다. patch embedding vectors를 생성하기 위해 pretrained cnn을 사용함으로서 ponderous neural network optimization을 피하기 위해 선택한다.

 

Patch distribution modeling

a. embedding extraction

다른 layer의 activation vector를 연결하여 서로 다른 semantic levels 및 resolutions의 정보를 전달하는 embedding vector를 가져와 세분화되고 global context를 encode 한다. activation map은 입력 이미지보다 resolution이 낮기 때문에 많은 pixels는 같은 embeddings을 가지며 원본 이미지 resolution에 겹치지 않는 pixel patches를 형성한다.

따라서, input image는 grid of (i, j) ∈ [1, W] × [1, H]로 나눠질 수 있다. 여기서 W*H는 embeddings를 generate하기 위해 사용되는 가장 큰 activation map의 resolution이다. 최종적으로, grid에서 각 patch position (i, j)는 위에서 설명된 것과 같이 계산된 embedding vector xij에 관여된다.

PaDiM 팀은 생성된 patch embedding vectors는 중복된 정보를 옮길 수 있으므로, 경험적으로 그것의 크기를 줄일 수 있는 가능성에 대해 연구했다. 랜덤하게 적은 dimensions를 선택하는 것이 classic principal component analysis 알고리즘보다 더 효율적이다. PaDiM은 간단한 랜덤 dimentionality reduction은 state-of-the-art performance를 유지하면서 training and testing time 모두에 복잡성을 크게 줄인다.

결과적으로 테스트 이미지의 patch embedding vectors는 일반 클래스의 학습된 parametric representation의 도움으로 anomaly map을 출력하는 데 사용된다.

b. learning of the normality

position (i,j)에서 일반 이미지 특징을 학습하기 위해, 우선 N 일반 학습 이미지의 (i, j), Xij = {xk ij , k ∈ [[1, N]]}에서 patch embedding vectors의 set을 계산한다. 이 집합이 전달하는 정보를 요약하기 위해 Xij가 multivariable gaussian distribution N (µij , Σij )에 의해 생성된다고 가정하자. 여기서 µij는 Xij의 sample mean이고 sample covariance Σij는 다음과 같이 추정된다.

patch embedding vectors는 다른 semantic levels의 정보를 옮긴다. 따라서, 각 estimated multivariate Gaussian distribution N (µij , Σij )은 다른 levels의 정보를 capture 하고, inter-level correlations 간 correlations이 포함된다.

c. inference

Mahalanobis distance M(xij)를 사용하여 test iamge의 위치 (i,j)에 있는 patch에 anomaly score를 부여한다. M(xij)는 xij를 포함하는 test patch와 learned distribution N (µij , Σij) 사이의 distance로 해석될 수 있다. 여기서 M(xij)는 다음과 같이 계산된다.

map에서 high scores는 anomalous areas를 나타낸다. 전체 이미지의 최종 anomaly score는 anomaly map M의 최댓값이다. K-NN을 어떻게 사용하는가?? 마지막으로, 테스트 시간에 PaDiM은 K-NN 기반 방법의 scalability 문제가 없다. 왜냐! patch의 anomaly score를 얻기 위해 많은 양의 거리 값을 계산하고 정렬할 필요가 없기 때문이다.

 

Experiments

a. dataset and metrics

Metrics. localization performance를 평가하기 위해 두 개의 threthold independent metrics를 계산한다. true positive rate가 anomalous로 올바르게 분류된 픽셀의 퍼센티지인 Area Under the Receiver Operating Characteristic curve (AUROC)를 사용한다. AUROC는 큰 anomalies를 선호하기 때문에 per-region-overlap score (PRO-score)도 사용한다. 이는 연결된 각 구성 요소에 대해 0과 0.3 사이의 false positive rate의 함수로 올바르게 분류된 pixel rates의 curve of the mean values를 plotting 하는 것으로 구성된다. PRO-score는 이 cure의 normalized integral이다. 높은 PRO-score는 크고 작은 anomalies이 모두 well-localized를 의미한다.

Datasets. object는 transistor 및 capsule class에 대해 figure 1에서 볼 수 있는 것과 같이 데이터셋 전체에서 항상 동일한 방식으로 중심에 있고 정렬된다. 원래 데이터셋에 더하여, 더 realistic context에서 anomaly localization model의 performance를 평가하기 위해 RdMVTecAD라고 하는 MVTec AD의 수정된 버전을 생성하고 여기서 random rotation(-10, +10) 및 random crop (from 256256 to 224224)을 적용한다. (학습 셋과 테스트 셋 모두에 대해)

 

Results

a. abalative studies

Inter-layer correlation. Gaussian 모델링과 Mahalanobis distance의 combination은 이미 이전 연구에서 adversarial attacks를 detection하고, 이미지 level에서 anomaly detection을 위해 사용되었다.

layer 3을 사용하면 세 layer 중 AUROC 측면에서 가장 좋은 결과를 얻을 수 있다. 이는 layer 3이 normality를 더 잘 설명하는 데 도움이 되는 higher semantic level information을 전달하기 때문이다. 그러나 Layer 3은 Layer 2보다 약간 더 나쁜 PRO-score를 가지고 있으며 이는 Layer 2의 lower resolution으로 설명할 수 있으며, 이는 anomaly localization의 accuracy에 영향을 준다. table 1의 마지막 두 행에서 볼 수 있듯이 서로 다른 layer의 정보를 aggregating하면, high semantic informaion과 high resolution 사이의 trade-off issue를 해결할 수 있다.

layer 3을 사용하면 세 layer 중 AUROC 측면에서 가장 좋은 결과를 얻을 수 있다. 이는 layer 3이 normality를 더 잘 설명하는 데 도움이 되는 higher semantic level information을 전달하기 때문이다. 그러나 Layer 3은 Layer 2보다 약간 더 나쁜 PRO-score를 가지고 있으며 이는 Layer 2의 lower resolution으로 설명할 수 있으며, 이는 anomaly localization의 accuracy에 영향을 준다. table 1의 마지막 두 행에서 볼 수 있듯이 서로 다른 layer의 정보를 aggregating하면, high semantic informaion과 high resolution 사이의 trade-off issue를 해결할 수 있다.

Dimentionality reduction. PaDiM-R18은 각각 448개 dimensions의 patch embedding vectors set에서 multivariate Gaussian distributions을 추정한다. embedding vector size를 줄이면 model의 computational and memory complexity가 줄어든다.

첫 번째는 PCA (Principal Component Analysis) 알고리즘을 적용하여 vector size를 100 또는 200 dimensions로 줄이는 것이다. 두 번째 방법은 학습 전에 features를 무작위로 선택하는 랜덤으로 선택된 features다. 이 경우 10개의 다른 모델을 학습하고, average scores를 얻는다. 평균 AUROC에 대한 standard error mean (SEM)은 항상 10-4에서 10-7 사이이므로 무작위성은 다른 seed 간의 결과를 반영하지 않는다.

Table 2에서 동일한 dimentions에 대해 random dimentionality reduction (Rd)가 모든 MVTec AD class에서 PCA보다 AUROC에서 최소 1.3p.p, PRO-score에서 1.2p.p를 능가한다는 것을 알 수 있다. 이는 PCA가 anomalous class와 normal class를 구별하는 데 도움이 되지 않는 highest variance를 선택한다는 사실로 설명할 수 있다.

또한 table 2에서 embedding vector size를 100 dimensions로 무작위로 줄이는 것은 anomaly localization performance에 거의 영향을 미치지 않음을 알 수 있다. 결과를 AUROC에서 0.4p.p, PRO-score에서 0.3p.p만 떨어진다. 이 간단하면서도 효과적인 dimentionality reduction method은 section V-D에 표시되는 것처럼 PaDiM time and space complexity를 크게 줄인다.

일반 MVTec AD에서 얻은 결과와 비교할 때 (refer to table III). AUROC 결과는 PaDiM-WR50-Rd550의 경우 VAE 및 SPADE의 경우 각각 12.2p.p 및 8.8p.p 감소에 비해 5.3p.p 감소한다. 따라서 PaDiM 방법은 기존 및 existing and tested works보다 non-aligned images에 더 튼튼하다고 결론을 내릴 수 있다.

memory complexity.

대부분의 reconstruction-based models과 유사한 VAE의 구현은 fastest model이지만 simple model PaDiM-R18-Rd100은 inference time에 대해 동일한 크기를 가진다. 복잡도는 비슷하지만 PaDiM은 VAE 방법을 훨씬 능가한다. (see Section V-B).

Section IV-B에서 설명된대로 입력 이미지 resolution이 후자의 데이터셋에서 더 높기 때문에 PaDiM 공간 복잡도가 MVTec AD에서 STC로 증가한다.