- Anomaly Detection 설명 – 정의, 특성, 활용 방안, 연구 흐름
- [One Class Classification 방식의 Anomaly Detection]
- [18′ ICML] Deep SVDD : Deep One-Class Classification
- [20′ ICLR] DEEP SEMI-SUPERVISED ANOMALY DETECTION (Deep SAD) 핵심 리뷰
- [20′ ACCV] Patch SVDD : Patch-level SVDD for Anomaly Detection and Segmentation
- [21′ ICLR] EXPLAINABLE DEEP ONE-CLASS CLASSIFICATION (FCDD) 핵심 리뷰
- [Reconstruction 방식의 Anomaly Detection]
- [17′ IPMI] AnoGAN : Unsupervised Anomaly Detection with Generative Adversarial Networks to Guide Marker Discovery
- [18′ ACCV] GANomaly : Semi-Supervised Anomaly Detection via Adversarial Training
- [20′ ECCV] Attention Guided Anomaly Localization in Images (CAVGA) 핵심 리뷰
- [21′ ICCV] Devide and Assemble : Learning Block-wise Memory for Unsupervised Anomaly Detection 핵심 리뷰
- [21′ ICCV] Learning Unsupervised Metaformer for Anomaly detection 핵심 리뷰
- [22′ CVPR] SSPCAB : Self-Supervised Predictive Convolutional Attentive Block for Anomaly Detection 핵심 리뷰
- [Pretrained Feature Matching 방식의 Anomaly Detection]
- [20′ Arxiv] SPADE : Sub-Image Anomaly Detection with Deep Pyramid Correspondences
- [20′ ICPR] Mahalanobis AD : Modeling the Distribution of Normal Data in Pre-Trained Deep Features for Anomaly Detection
- [21′ ICPR] PaDiM : a Patch Distribution Modeling Framework for Anomaly Detection and Localization
- [22′ CVPR] PatchCore : Towards Total Recall in Industrial Anomaly Detection
- [Normalizing Flow 방식의 Anomaly Detection]
- [20′ NIPS] Why Normalizing Flows Fail to Detect Out-of-Distribution Data 핵심 리뷰
- [21′ WACV] Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows 핵심 리뷰
- [22′ WACV] CFLOW-AD: Real-Time Unsupervised Anomaly Detection with Localization via Conditional Normalizing Flows 핵심 리뷰
- [22′ WACV] Fully Convolutional Cross-Scale-Flows for Image-based Defect Detection (CS-Flow) 핵심 리뷰
- [21′ arxiv] FastFlow: Unsupervised Anomaly Detection and Localization via 2D Normalizing Flows 핵심 리뷰
- [Self Supervised Learning 방식의 Anomaly Detection]
- [18′ NIPS] Deep Anomaly Detection Using Geometric Transformations (GEOM) 핵심 리뷰
- [19′ NIPS] SSL-AD : Using Self-Supervised Learning Can Improve Model Robustness and Uncertainty 핵심 리뷰
- [20′ ICLR] CLASSIFICATION-BASED ANOMALY DETECTION FOR GENERAL DATA (GEOD) 핵심 리뷰
- [20′ NIPS] CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instances
- [21′ ICLR] SSL-OCC : Learning and evaluating representations for deep one class classification 핵심 리뷰
- [21′ ICCV] Hierarchical Transformation AD : A Hierarchical Transformation-Discriminating Generative Model for Few Shot Anomaly Detection 핵심 리뷰
- [21′ ICLR] SSD: A UNIFIED FRAMEWORK FOR SELFSUPERVISED OUTLIER DETECTION 핵심 리뷰
- [Knowledge Distillation 방식의 Anomaly Detection]
- [20′ CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings
- [21′ Arxiv] Student Teacher AD : Student-Teacher Feature Pyramid Matching for Unsupervised Anomaly Detection
- [21′ CVPR] Multiresolution Knowledge Distillation for Anomaly Detection
- [22′ CVPR] Reverse Distillation AD : Anomaly Detection via Reverse Distillation from One-Class Embedding
- [Synthetic Anomaly 방식의 Anomaly Detection]
- [21′ ICCV] DRAEM : A discriminatively trained reconstruction embedding for surface anomaly detection
- [21′ CVPR] CutPaste: Self-Supervised Learning for Anomaly Detection and Localization
내용 요약
Uninformed Students는 Knowledge Distillation을 사용하는 Anomaly Detection 방법입니다. Teacher 네트워크는 ImageNet Patch를 학습합니다. 이때 Knowledge Distillation Loss, Self Supervised Learning Loss, Compactness Loss 등을 사용합니다. 학습이 완료된 Teacher 네트워크는 Student 네트워크에 정상 이미지를 학습합니다. MNIST, CIFAR10, mvTec 데이터셋에서 기존 방법들보다 성능이 좋음을 보였습니다.
1. 들어가며
이번 글에서는 2020년 CVPR에 발표된 Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 논문을 리뷰합니다. Anomaly Detection에 관한 기본적인 내용은 Anomaly Detection에 관한 모든 것 글을 참고해주세요.
본격적으로 들어가기 전, 제목의 의미를 통해 저자들이 강조하고자 한 내용을 유추해 보겠습니다.
제목에서는 크게 두 가지 포인트를 찾을 수 있습니다.
첫 번째는 Student-Teacher 구조의 Knowledge Distillation을 사용하는 Anomaly Detection 방법이라는 것입니다.
두 번째는 이렇게 학습한 Latent Embedding의 구분 능력을 사용한다는 것입니다. 이를 통해 Knowledge Distillation 방법으로 학습한 Latent Embedding을 사용하여 Anomaly를 구분하는 방법이라는 점을 유추할 수 있습니다.
본문에서 하나씩 자세한 내용을 살펴보겠습니다.
이번 글의 순서는 다음과 같습니다.
첫 번째로 기존 Anomaly Detection 방법인 Reconstruction 방법의 문제점을 살펴봅니다.
두 번째로 제안 방법을 살펴봅니다. 먼저 큰 그림을 살펴본 뒤 Teacher와 Student 네트워크 학습 방법을 각각 살펴봅니다.
세 번째로 성능 실험을 통해 제안 방법의 효과를 살펴봅니다.
2. 기존 방법의 문제점
먼저 기존 방법의 문제점을 살펴보겠습니다.
해당 논문이 발표될 당시 Anomaly Detection의 대세 방법은 Reconstruction 방식이었습니다. Reconstruction 방식의 Anomaly Detection 방법의 철학은 이렇습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 1 그림1.Reconstruction 방식의 Anomaly Detection](https://blog.kakaocdn.net/dn/ztMWS/btr4G71tc7t/QjtxKHGcpNrNx27tBftMy0/img.png)
정상 이미지를 그대로 Reconstruction 하도록 네트워크를 학습하는 겁니다. 그럼 이 네트워크는 정상 이미지에 대해서만 Reconstruction을 학습했기에 비정상 부분은 Reconstruction 하지 못할 겁니다. 따라서 Reconstuction 된 이미지와 원본 이미지의 차이를 근거로 Anomaly Score를 측정하는 방법입니다. 이 둘의 차이가 클수록 비정상으로 판단하는 것이죠.
문제는 실제 상황에서는 의도한 대로 네트워크가 반응하지 않는다는 것입니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 2 그림2.기존 방법의 문제점](https://blog.kakaocdn.net/dn/b5SZGB/btr4vpW4Hd5/6FHZI8VrdMzmqnrZ32tPvk/img.png)
위 그림은 Reconstruction 방식의 Anomaly Detection Network의 Feature 공간을 표현한 그림입니다.
왼쪽은 의도한 시나리오를, 오른쪽은 실제 시나리오를 표현하고 있습니다. 왼쪽 그림을 보면 정상 이미지는 Reconstruction 된 Feature와 원본 Feature가 가까이 있는 모습을 볼 수 있습니다.반면 비정상 이미지의 Feature는 Reconstruction 된 Feature와 멀리 떨어져 있는 모습이죠.
하지만 실제로는 의도와는 다른 상황이 펼쳐졌는데요. 오른쪽 그림을 보면 정상 이미지에서는 의도한 대로 Feature들이 분포하고 있습니다. 반면 비정상 이미지도 정상 이미지에서와 동일하게 원본 Feature와 Reconstruction 된 Feature가 가깝게 분포하고 있죠. 따라서 생각만큼 비정상 이미지를 구분하는 성능이 좋지 않았습니다.
3. 제안 방법
이러한 이유로 이번 논문에서는 다른 방법을 제안합니다.
Knowledge Distillation을 사용하는 것이죠. Distillation는 증류라는 뜻입니다. 따라서 Knowledge Distillation은 지식을 증류한다는 의미이죠. 아주 많은 지식을 학습한 Teacher 네트워크의 지식을 아무것도 모르는 Student 네트워크에 전수해 주는 방식입니다.
3-1. 큰 그림
먼저 저자들의 큰 그림을 살펴보겠습니다.
Knowledge Distillation 방식에는 기본적으로 Teacher 네트워크와 Student 네트워크가 존재합니다. Teacher 네트워크는 아주 많은 지식을 가지고 있음을 가정합니다. 이 지식을 Student 네트워크에 전수해 주는 것이죠. 보통 Teacher 네트워크는 ImageNet처럼 큰 데이터셋을 학습한 모델을 사용합니다. Student 모델은 가중치 초기화를 한 상태에서 Teacher의 지식을 전수받죠. 이번 논문에서는 한 개의 Teacher 네트워크와 다수의 Student 네트워크를 사용합니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 3 그림3.Teacher와 다수의 Student 네트워크](https://blog.kakaocdn.net/dn/smBht/btr4zc98zGl/fM7fAX9wrMdkkNE2C90EsK/img.png)
Teacher 네트워크는 ImageNet Patch Level 지식을 갖고 있습니다. Student 네트워크는 정상 데이터셋에 대해 Teacher 네트워크의 지식을 전수받을 겁니다. 이렇게 학습된 Teacher와 Student 네트워크는 정상/비정상 이미지에 대해 어떻게 반응할까요?
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 4 그림4.scoring 방법](https://blog.kakaocdn.net/dn/d972iy/btr4LFKl0s8/ktSLukrwX7H7P9UNPNDlWK/img.png)
우선 정상 이미지에 대해서 생각해 보죠.
정상 이미지에 대해서는 Teacher 네트워크와 Student 네트워크의 반응이 비슷할 겁니다. 왜냐하면 Student 네트워크는 Teacher 네트워크로부터 정상 이미지에 대해 배웠으니까요.
하지만 비정상 이미지라면 얘기가 다릅니다. Student 네트워크는 비정상 이미지에 대해서는 학습한 바가 없죠. 반면 Teacher 네트워크는 ImageNet 등을 학습했으므로 비정상 이미지에 대한 나름의 판단을 갖고 있을 겁니다. 따라서 비정상 이미지에 대한 반응은 Teacher 네트워크와 Student 네트워크가 크게 다를 겁니다. 뿐만 아니라 Student 네트워크끼리에서의 반응도 많이 다르겠죠. 배운 바가 없으니 각자의 판단이 모두 다르지 않겠어요?
이러한 큰 그림을 갖고 이번 논문의 전체 구조를 보면 다음과 같습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 5 img](https://blog.kakaocdn.net/dn/bO8po0/btr4yjuw3Fd/C1KudTecl5Z0MLy8i4uPJ1/img.png)
가장 왼쪽에는 Teacher와 Student 네트워크가 있죠. Student 네트워크는 M개로 구성되어 있습니다. Teacher 네트워크는 정상 이미지에 대해 Student를 가르치죠. 이제 Inference 단계에서는 이 두 네트워크로부터 나온 Latent Embedding을 사용하여 Anomal Score를 측정할 겁니다. 가운데에는 정상과 비정상 이미지의 Latent Embedding 분포를 볼 수 있습니다. 오른쪽에서는 비정상 이미지에 대한 Heatmap을 볼 수 있습니다.
이제 하나씩 자세히 살펴보죠.
3-2. Teacher 네트워크 학습하기
먼저 Teacher 모델 제작 방법을 살펴보겠습니다.
Teacher 모델은 ImageNet으로 학습한 모델을 사용할 겁니다. 그런데 그대로 사용하는 것이 아닌 Patch Descriptor로써 작동할 수 있도록 학습해 줄 겁니다. 왜냐하면 우리가 풀고 싶은 문제는 Anomaly Detection인데요. Anomaly Detection에서는 이미지 전체를 보는 것보다는 Patch 단위로 자세히 보는 것이 더 유리하기 때문입니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 6 img](https://blog.kakaocdn.net/dn/FU6Of/btr4xLLuly7/uzbkYRKxM0KoBXcJ6IwtHk/img.png)
따라서 위의 그림과 같이 총 3개의 Loss로 Teacher 모델을 학습해 줄 겁니다.
첫 번째는 knowledge distillation loss입니다.
수식으로는 이렇게 표현됩니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 7 img](https://blog.kakaocdn.net/dn/Bjbuj/btr4t7WF6qv/AfdmmR5CckL5ivkgTaqG60/img.png)
- P : imagenet pretrained model
- T^ : teacher model
- D : fully connected network
첫 번째 항은 Teacher 네트워크가 바라보는 Patch를 의미합니다. Fully Connected 연산을 통해 Student 네트워크의 Output과 Dimension을 맞춰주는 모습입니다.
두 번째 항은 ImageNet으로 학습한 모델이 바라보는 Patch를 의미하죠. 따라서 Distillation Loss로 학습하면 Teacher 네트워크가 ImageNet Patch에 대한 관점을 학습하게 됩니다.
두 번째는 Metric Learning Loss입니다.
이 방법은 ImageNet으로 학습한 모델을 사용할 수 없을 때 사용합니다. Self Supervised Learning 방법으로 ImageNet을 학습하는 거죠. 수식으로는 이렇게 표현됩니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 8 img](https://blog.kakaocdn.net/dn/t30t0/btr4vIaVq9i/d1AAdOPreevyHc5SucPZnk/img.png)
- T^ : teacher model
- P+ : 나와 비슷한 Patch
- P- : 나와 다른 Patch
수식으로는 복잡하게 표현했지만 말로 설명하면 간단합니다.
“나랑 비슷한 Patch(P+)는 가까워지도록, 나와 다른 Patch(P-)는 멀어지도록 학습하자”입니다.
P+와 P-는 다음 그림을 보면 쉽게 이해할 수 있습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 9 그림9.패치에 따른 학습](https://blog.kakaocdn.net/dn/dj8mVK/btr4FmErOqg/kNTFTCMCIHcK8dDUbnoG4k/img.png)
P+는 Anchor Patch 기준으로 나와 거의 동일한 Patch를 의미합니다. 약간의 좌우 이동이 있거나 확대된 정도의 Patch 말이죠.
반면 P-는 Anchor Patch 기준으로 완전히 다른 Patch를 의미합니다. 위 그림처럼 Anchor는 고양이 눈인데, P-는 고양이 코인 것처럼 말이죠.
세 번째는 Descriptor Compactness Loss입니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 10 img](https://blog.kakaocdn.net/dn/Y9KPb/btr4wFEZWo7/wGnojfaX4dS75n5LKTkyhK/img.png)
- c : correlation matrix computed cover all descriptors
이는 현재의 미니 배치에서 추출한 모든 Feature의 Compactness를 증가시키는 역할을 합니다.
최종 Loss는 위의 세 Loss를 모두 합하여 구성해 줍니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 11 img](https://blog.kakaocdn.net/dn/cWNvpa/btr4LGvvwxM/RmQwCiwzfaW89yc2dk6KO0/img.png)
3-3. Student 네트워크 학습하기
위의 내용까지가 Teacher 모델을 만드는 방법입니다. 이제 Student 모델을 만드는 방법을 살펴보겠습니다.
먼저 Student 모델은 M개의 모델을 앙상블 하여 사용할 겁니다. 한 학생의 대답보다는 여러 학생의 대답을 들어보고 결정하는 게 낫겠다는 생각인 거죠. 모든 M개의 Student 모델은 이제 ImageNet이 아닌 Anomaly Detection 데이터셋만 학습할 겁니다. Anomaly Detection 데이터셋의 정상 이미지만 학습하는 거죠.
Student 네트워크는 Teacher 네트워크의 지식을 학습한다고 했습니다. 그럼 정상 이미지에 대해 Teacher의 관점과 동일한 관점을 갖도록 학습하면 되겠죠? 따라서 정상 데이터에 대해 Teacher 네트워크의 Feature와 Student 네트워크의 Feature가 가까워지도록 학습합니다. 수식으로는 다음과 같습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 12 img](https://blog.kakaocdn.net/dn/rdLcd/btr4LHVt4kh/kfgFUReAqxXgta3qnPTMZK/img.png)
- r, c : 픽셀 위치
- S : student 모델
- T : teacher 모델
- 𝜇 : feature들의 평균 벡터
- 𝜎 : feature들의 standard deviation
- y : 추출한 feature 벡터
3-4. Anomal Score 측정하기
학습을 완료한 뒤 Anomal Score를 계산하는 방법을 살펴보겠습니다.
총 두 가지 관점에서 Anomal Score를 측정할 겁니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 13 그림13.불량 패치의 특징](https://blog.kakaocdn.net/dn/cGrwi1/btr4LGvKxp7/JY9JcFixlKwwVo06qSo5R0/img.png)
위 그림은 비정상 이미지 Feature의 특징을 표현하고 있습니다. 비정상 이미지 Feature는 크게 두 가지 특징을 갖습니다.
첫 번째는 Teacher 네트워크와 Student 네트워크의 반응이 다르다는 겁니다.
Teacher는 ImageNet으로 다양한 이미지를 학습했습니다. 따라서 비정상 이미지와 비슷한 데이터들을 학습했겠죠. 따라서 나름의 판단을 할 것입니다. 반면 Student 네트워크는 비정상 이미지를 한 번도 본 적이 없죠. 따라서 Teacher 네트워크와는 아주 다른 반응을 보일 겁니다. 이러한 점에 착안하여 Regression Error로 Anomal Score를 측정합니다. Teacher 네트워크의 Feature와 Student 네트워크의 Feature가 얼마나 멀리 떨어져 있는지를 측정하는 것이죠. 수식으로는 다음과 같습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 14 img](https://blog.kakaocdn.net/dn/sCdF5/btr4LHBbaif/u1eISdF1hB2Byg3UMfcIXK/img.png)
두 번째는 Student 네트워크들의 반응도 크게 다르다는 겁니다.
Student 네트워크는 비정상 이미지를 학습한 적이 없죠. 따라서 비정상 이미지에 대한 반응은 각각의 Student 네트워크들마다 상이할 겁니다. 이러한 점에 착안하여 Uncertainty로 Anomal Score를 측정합니다. Student 네트워크 Feature들이 얼마나 멀리 떨어져 있는지를 측정하는 것이죠. 수식으로는 다음과 같습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 15 img](https://blog.kakaocdn.net/dn/bhMm3n/btr4LELdPwB/p36v1a4y8ppW6vlPW3uM7k/img.png)
최종 score는 위의 두 가지 값을 Normalization 하여 더해줍니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 16 img](https://blog.kakaocdn.net/dn/bnzu7W/btr4zchM7uE/9sROc2j3RS2cenoXMMukRk/img.png)
3-4. Multi Scale 모델 만들기
그런데 만약 Anomal Patch가 학습한 Receptive Field Size보다 훨씬 작으면 어떻게 될까요?
우리 모델은 잘 구분하지 못하겠죠. 처음 보는 데이터와 마찬가지니까요. 따라서 우리 모델은 다양한 사이즈의 Receptive Field Size로 학습해야 합니다. 총 L가지의 다른 사이즈로 학습했다고 생각해 보겠습니다. 이때의 Anomal Segmentation Score는 L개 Score 합으로 구해줍니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 17 img](https://blog.kakaocdn.net/dn/GJgcC/btr4vhEEcEE/x0Cku3scGKvOQcDvnirbKK/img.png)
4. 효과
이번에는 성능 실험 결과를 통해 제안 방법의 효과를 살펴보겠습니다.
4-1. MNIST and CIFAR10
먼저 MNIST와 CIFAR10 데이터셋에 대한 One Class Novelty Detection 성능을 살펴보겠습니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 18 img](https://blog.kakaocdn.net/dn/rHDTz/btr4zbJVev5/8oYvFw0U1ng9CPHwtufZEk/img.png)
우선 비교 방법들 중 가장 좋은 성능을 보입니다. 특이하게 Metric Learning을 하지 않았을 때가 성능이 더 좋은 모습을 보입니다.
4-2. MVTec
다음은 MVTec 데이터셋에 대한 성능입니다.
![[20' CVPR] Uninformed Students: Student–Teacher Anomaly Detection with Discriminative Latent Embeddings 19 img](https://blog.kakaocdn.net/dn/bVYEEF/btr4yjnJDQh/NS1L3HsnklptWqKUDq2VrK/img.png)
주로 Reconstruction 방식의 Anomaly Detection 방법들과 성능을 비교하고 있는데요. 이중에서는 가장 좋은 성능을 보이고 있습니다. 기존 Reconstruction 방법들과 마찬가지로 Texture 클래스의 성능이 Object 클래스 성능보다 대체로 안 좋은 모습입니다.
5. 결론
Knowledge Distillation을 사용하는 Anomaly Detection 방법론인 Uninformed Students 논문을 살펴봤습니다.
Uninformed Students는 최초의 Knowledge Distillation을 사용한 Anomaly Detection 방법이라는 의의가 있습니다. 뿐만 아니라 이후 Multi Resolution Knowledge Distillation, Student Teacher AD등 Knowledge Distillation을 사용하는 Anomaly Detection 방법들에 영감을 주었습니다.
하지만 실제로 활용하기에는 성능이 낮다는 한계가 있습니다. 또한 Teacher 네트워크도 따로 학습해야 하고 다수의 Student 네트워크를 학습해야 하는 번거로움도 한계로 지적됩니다.