|
--- |
|
datasets: |
|
- quandao92/ad-clip-dataset |
|
metrics: |
|
- f1 |
|
base_model: |
|
- openai/clip-vit-base-patch32 |
|
--- |
|
<div style='text-align: center; font-size: 28px; font-weight: bold'>CLIP ๊ธฐ๋ฐ ์ ํ ๊ฒฐํจ ํ์ง ๋ชจ๋ธ ์นด๋</div> |
|
|
|
## ๋ชจ๋ธ ์ธ๋ถ์ฌํญ |
|
|
|
### ๋ชจ๋ธ ์ค๋ช
|
|
|
|
AnomalyCLIP์ ํน์ ๊ฐ์ฒด์ ์์กดํ์ง ์๋ ํ
์คํธ ํ๋กฌํํธ๋ฅผ ํ์ตํ์ฌ ์ด๋ฏธ์ง ๋ด์ ์ ๊ฒฝ ๊ฐ์ฒด์ ์๊ด์์ด ์ผ๋ฐ์ ์ธ ์ ์ ๋ฐ ๋น์ ์ ํจํด์ ํฌ์ฐฉํ๋ ๊ฒ์ ๋ชฉํ๋ก ํฉ๋๋ค. |
|
์ด ๋ชจ๋ธ์ CLIP ๊ธฐ๋ฐ ์ด์ ํ์ง ๊ธฐ๋ฒ์ ํ์ฉํ์ฌ ์ ํ ๊ฒฐํจ์ ํ์งํฉ๋๋ค. |
|
์ฌ์ ํ์ต๋ CLIP ๋ชจ๋ธ์ ํ์ธํ๋(Fine-tuning)ํ์ฌ ์ ํ ์ด๋ฏธ์ง์์ ๊ฒฐํจ์ ์๋ณํ๋ฉฐ, ์ด๋ฅผ ํตํด ์์ฐ ๋ผ์ธ์ ํ์ง ๊ด๋ฆฌ ๋ฐ ๊ฒฐํจ ํ์ง ์์
์ ์๋ํํ ์ ์์ต๋๋ค. |
|
|
|
- **Developed by:** ์ค์๋ฏผ |
|
- **Funded by:** SOLUWINS Co., Ltd. (์๋ฃจ์์ค) |
|
- **Referenced by:** zhou2023 anomalyclip [[github](https://github.com/zqhang/AnomalyCLIP.git)] |
|
- **Model type:** CLIP (Contrastive Language-Image Pretraining) - Domain-Agnostic Prompt Learning Model |
|
- **Language(s):** Python |
|
- **License:** Apache 2.0, MIT, OpenAI |
|
|
|
### ๊ธฐ์ ์ ์ ํ์ฌํญ |
|
|
|
- ๋ชจ๋ธ์ ๊ฒฐํจ ํ์ง๋ฅผ ์ํ ์ถฉ๋ถํ๊ณ ๋ค์ํ ํ๋ จ ๋ฐ์ดํฐ๋ฅผ ํ์๋ก ํฉ๋๋ค. ํ๋ จ ๋ฐ์ดํฐ์
์ด ๋ถ์กฑํ๊ฑฐ๋ ๋ถ๊ท ํํ ๊ฒฝ์ฐ, ๋ชจ๋ธ์ ์ฑ๋ฅ์ด ์ ํ๋ ์ ์์ต๋๋ค. |
|
- ์ค์๊ฐ ๊ฒฐํจ ๊ฐ์ง ์ฑ๋ฅ์ ํ๋์จ์ด ์ฌ์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง ์ ์์ผ๋ฉฐ, ๋์ ํด์๋์์ ๊ฒฐํจ์ ํ์งํ๋ ์ ํ๋๊ฐ ๋จ์ด์ง ์ ์์ต๋๋ค. |
|
- ๊ฒฐํจ์ด ๋ฏธ์ธํ๊ฑฐ๋ ์ ํ ๊ฐ ์ ์ฌ์ฑ์ด ๋งค์ฐ ๋์ ๊ฒฝ์ฐ, ๋ชจ๋ธ์ด ๊ฒฐํจ์ ์ ํํ๊ฒ ํ์งํ์ง ๋ชปํ ์ ์์ต๋๋ค. |
|
|
|
## ํ์ต ์ธ๋ถ์ฌํญ |
|
|
|
### Hardware |
|
- **CPU:** Intel Core i9-13900K (24 Cores, 32 Threads) |
|
- **RAM:** 64GB DDR5 |
|
- **GPU:** NVIDIA RTX 4090Ti 24GB |
|
- **Storage:** 1TB NVMe SSD + 2TB HDD |
|
|
|
### Software |
|
- **OS:** Windows 11 64 bit/ Ubuntu 20.04LTS |
|
- **Python:** 3.8 (anaconda) |
|
- **PyTorch:** 1.9.0 |
|
- **OpenCV:** 4.5.3 |
|
- **Cuda Toolkit:** 11.8 |
|
- **CudDNN:** 9.3.0.75 for cuda11 |
|
|
|
### ๋ฐ์ดํฐ์
์ ๋ณด |
|
|
|
์ด ๋ชจ๋ธ์ ์ ํ์ ์ ์ ์ด๋ฏธ์ง์ ๊ฒฐํจ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ จ๋ฉ๋๋ค. |
|
์ด ๋ฐ์ดํฐ๋ ์ ํ์ ์ด๋ฏธ์ง, ๊ฒฐํจ ์์ญ์ ๋ํ ground truth ์ ๋ณด, ๊ทธ๋ฆฌ๊ณ ๊ธฐํ ๊ด๋ จ ํน์ฑ์ ํฌํจํ๊ณ ์์ต๋๋ค. |
|
์ด๋ฏธ์ง๋ CLIP ๋ชจ๋ธ์ ์
๋ ฅ ํ์์ ์ ํฉํ๋๋ก ์ ์ฒ๋ฆฌ๋๋ฉฐ, ๊ฒฐํจ ์์ญ์ ํ๊ฐ๋ฅผ ์ํด ground truth ๋งํน์ด ํฌํจ๋ฉ๋๋ค. |
|
|
|
- **๋ฐ์ดํฐ ์์ค:** https://huggingface.co/datasets/quandao92/ad-clip-dataset |
|
- **๋ฐ์ดํฐ ์์ง ์ฅ๋น:** |
|
- ์์ง H/W: jetson orin nano 8GB |
|
- ์นด๋ฉ๋ผ: BFS-U3-89S6C Color Camera |
|
- ๋ ์ฆ: 8mm Fiexd Focal Length Lens |
|
- ์กฐ๋ช
: LIDLA-120070 |
|
- ๋ฐ์ดํฐ ํ์: .bpm, .jpg |
|
- **๋ฐ์ดํฐ ๋ฒ์ ๊ด๋ฆฌ:** |
|
- **1์ฐจ : 20240910_V0_๊ฐ์ด ํ๊ฒฝ ๋ฐ์ดํฐ ์์ง** |
|
๋ฐ์ดํฐ ๋ฒ์ ๋ฐ ์ฌ์ฉ ์ด๋ ฅ |
|
- V01: ์ ์ฒ๋ฆฌ ์ ๋ฐ์ดํฐ ์๋ณธ -> ๋ฐ์ดํฐ ์์ง ์๋ณธ: 7ea |
|
- V02: ๋ฐ์ดํฐ ๋ถ๋ฅ -> ์ ์/๋ถ๋ ๋ถ๋ฅ: 4ea/3ea |
|
- V03: ๋ฐ์ดํฐ ๋ถ๋ฅ, ๋ฐ์ดํฐ ํ์ -> ์ด๋ฏธ์ง ์ฆ๊ฐ_45/90/135๋๋ก ํ์ _28ea |
|
<div style="text-align: center;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/6kvzgbH81jJrHJECaEspY.png" height="500" width="100%"> |
|
<p>Ground Truth Marking</p> |
|
</div> |
|
|
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/_fkcI52_BTcqvQyrJ4EXl.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>PCA ๋ถํฌ ์๊ฐํ</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/biaWPJtbm6iwNf7ZqnW5O.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>Isolation Forest๋ก ์ด์๊ฐ ์๋ณ ๊ฒฐ๊ณผ</p> |
|
</div> |
|
</div> |
|
|
|
- **2์ฐจ : 20240920_V1_ํ์ฐ์ง ๋ด ์ด๋ฏธ์ง ์์ง** |
|
๋ฐ์ดํฐ ๋ฒ์ ๋ฐ ์ฌ์ฉ ์ด๋ ฅ |
|
- V01: ์ ์ฒ๋ฆฌ ์ ๋ฐ์ดํฐ ์๋ณธ -> ๋ฐ์ดํฐ ์์ง ์๋ณธ: 16ea |
|
- V02: ๋ฐ์ดํฐ ๋ถ๋ฅ -> ์ ์/๋ถ๋ ๋ถ๋ฅ: 14ea/2ea |
|
- V03: ๋ฐ์ดํฐ ๋ถ๋ฅ, ๋ฐ์ดํฐ ํ์ -> ์ด๋ฏธ์ง ์ฆ๊ฐ__64ea |
|
<div style="text-align: center;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/YsP7UwejFabUFp2Im0xWj.png" height="500" width="100%"> |
|
<p>Ground Truth Marking</p> |
|
</div> |
|
|
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/CNFdse5mHQY1KkMb5BYpb.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>PCA ๋ถํฌ ์๊ฐํ</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/nRO00DJFT0-B1EJYf8lzK.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>Isolation Forest๋ก ์ด์๊ฐ ์๋ณ ๊ฒฐ๊ณผ</p> |
|
</div> |
|
</div> |
|
|
|
- **3์ฐจ : 20241002_V2_์ค๋น ๋ด ๋ฐ์ดํฐ ์์ง** |
|
๋ฐ์ดํฐ ๋ฒ์ ๋ฐ ์ฌ์ฉ ์ด๋ ฅ |
|
- V01: ์ ์ฒ๋ฆฌ ์ ๋ฐ์ดํฐ ์๋ณธ -> ์ด๋ฏธ์ง ์์ง_49๊ฐ |
|
- V02: ๋ฐ์ดํฐ ๋ถ๋ฅ -> ์ ์/๋ถ๋ ๋ถ๋ฅ ์ํ_error/normal |
|
- V03: ๋ฐ์ดํฐ ๋ถ๋ฅ, ๋ฐ์ดํฐ ํ์ -> ์ด๋ฏธ์ง ์ฆ๊ฐ ์ํ_์ด๋ฏธ์ง ํ์ ์ ํตํด ์ด๋ฏธ์ง ๊ฐ์ 102๊ฐ |
|
<div style="text-align: center;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/MFyVWaqr4GDNs8W2mWzGZ.png" height="500" width="100%"> |
|
<p>Ground Truth Marking</p> |
|
</div> |
|
|
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/Kc3EMbY05frUFQh5HbVHn.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>PCA ๋ถํฌ ์๊ฐํ</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/SP4R5LjGo2M1Zvby1Bar_.png" height="80%" width="90%" style="margin-right:5px;"> |
|
<p>Isolation Forest๋ก ์ด์๊ฐ ์๋ณ ๊ฒฐ๊ณผ</p> |
|
</div> |
|
</div> |
|
|
|
- **Data Configuration:** |
|
- **์ด๋ฏธ์ง ํฌ๊ธฐ ์กฐ์ ๋ฐ ์ ๊ทํ:** |
|
- ์ด๋ฏธ์ง๋ ์ผ์ ํ ํฌ๊ธฐ(์: 518x518)๋ก ๋ฆฌ์ฌ์ด์ฆ๋๋ฉฐ, CLIP ๋ชจ๋ธ์ ์
๋ ฅ์ผ๋ก ์ ํฉํ๊ฒ ์ฒ๋ฆฌ๋ฉ๋๋ค. |
|
- ์ ๊ทํ๋ฅผ ํตํด ํฝ์
๊ฐ์ [0, 1] ๋ฒ์๋ก ๋ณํํฉ๋๋ค. |
|
- **Ground Truth ๋งํน:** |
|
- ๊ฒฐํจ์ด ์๋ ์ด๋ฏธ์ง์ ๋ํด ๊ฒฐํจ ์์ญ์ bounding box ํ์ ๋๋ binary mask๋ก ํ์ํฉ๋๋ค. |
|
- ๋งํน๋ ๋ฐ์ดํฐ๋ฅผ JSON ๋๋ CSV ํ์์ผ๋ก ์ ์ฅํ์ฌ ๋ชจ๋ธ ํ๊ฐ ์ ์ฌ์ฉํฉ๋๋ค. |
|
|
|
<div style="text-align: center;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/k8GQgaTK7JfQExNpCYpzz.png" height="500" width="100%" style="margin-right:5px;"> |
|
<p>Ground Truth Marking</p> |
|
</div> |
|
|
|
- **๋ฐ์ดํฐ ๋ถ๋ฅ:** |
|
- Normal: ๊ฒฐํจ์ด ์๋ ์ ์ ์ ํ์ ์ด๋ฏธ์ง. |
|
- Error: ๊ฒฐํจ์ด ์๋ ์ ํ์ ์ด๋ฏธ์ง. ๊ฒฐํจ ์์น์ ๊ด๋ จ ์ ๋ณด๊ฐ ํฌํจ๋ฉ๋๋ค. |
|
<div style="display: flex;justify-content: space-between;"> |
|
<div style="text-align: center;margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/5pGwZ-sptjWjf7WpHifyJ.jpeg" height="400" width="450""> |
|
</div> |
|
<div style="text-align: center;justify-content: space-between; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/3iihck7VfkXKw9VcIl06x.jpeg" height="400" width="450""> |
|
</div> |
|
<div style="text-align: center;justify-content: space-between;margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/tjsmiXq9pp0K6KSuS1iOS.jpeg" height="400" width="450""> |
|
</div> |
|
</div> |
|
<p style="text-align: center;">Normal Product Images</p> |
|
|
|
<div style="display: flex;justify-content: space-between;"> |
|
<div style="text-align: center;margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/Qv01zDzEM5u8cQYdALrSU.jpeg" height="400" width="450""> |
|
</div> |
|
<div style="text-align: center;justify-content: space-between; margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/B5q_FKiTVXkuElTSlUc4s.jpeg" height="400" width="450""> |
|
</div> |
|
<div style="text-align: center;justify-content: space-between;margin-right: 5px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/3pro8oEqMTiEwiwFKcACn.jpeg" height="400" width="450""> |
|
</div> |
|
</div> |
|
<p style="text-align: center;">Error Product Images</p> |
|
|
|
### ๋ฐ์ดํฐ ๋ผ๋ฒจ๋ง ๊ฐ์ด๋ |
|
๋ณธ ๋ฐ์ดํฐ ๋ผ๋ฒจ๋ง ๊ฐ์ด๋๋ AnomalyDetection ๊ธฐ๋ฐ ๋ชจ๋ธ ํ์ต์ ์ํด ์์ง๋ ๋ฐ์ดํฐ๋ฅผ ๋ผ๋ฒจ๋งํ๋ ๊ธฐ์ค๊ณผ ํ๋ก์ธ์ค๋ฅผ ๋ช
ํํ ์ ์ํฉ๋๋ค. |
|
๋ฐ์ดํฐ๋ ์ฃผ๋ก ์ ์(normal) ๋ฐ์ดํฐ๋ฅผ ์ค์ฌ์ผ๋ก ๊ตฌ์ฑ๋๋ฉฐ, ์ต์ํ์ ๋น์ ์(anomaly) ๋ฐ์ดํฐ๋ฅผ ํฌํจํฉ๋๋ค. |
|
๋ณธ ๊ฐ์ด๋๋ ๋ฐ์ดํฐ์ ํ์ง์ ์ ์งํ๊ณ ๋ชจ๋ธ ํ์ต ๋ฐ ํ
์คํธ๋ฅผ ์ต์ ํํ๋ ๋ฐ ๋ชฉํ๋ฅผ ๋ก๋๋ค. |
|
- **๋ผ๋ฒจ๋ง ๋ฒ์** |
|
|
|
1. **์ ์(normal) ๋ฐ์ดํฐ**: |
|
- ์ ์ฒด ๋ฐ์ดํฐ์ ์ฝ **95% ์ด์**์ ์ฐจ์ง. |
|
- ๋ค์ํ ํ๊ฒฝ ์กฐ๊ฑด์์ ์์ง๋ ๋ฐ์ดํฐ๋ฅผ ํฌํจ (์กฐ๋ช
, ๊ฐ๋, ๋ฐฐ๊ฒฝ ๋ฑ). |
|
- ์ ์์ ์ธ ์ํ์ ๊ธ์ ํ๋ฉด, ์ ๋ฐํ ๊ตฌ์กฐ, ๊ท ์ผํ ๊ดํ์ ๊ฐ์ง ๋ฐ์ดํฐ. |
|
2. **๋น์ ์(anomaly) ๋ฐ์ดํฐ**: |
|
- ์ ์ฒด ๋ฐ์ดํฐ์ ์ฝ 5**% ์ดํ**๋ก ์ ํ. |
|
- ๊ฒฐํจ ์ ํ: |
|
- **Scratch**: ์คํฌ๋์น. |
|
- **Contamination**: ์ผ๋ฃฉ ๋๋ ์ด๋ฌผ์ง. |
|
- **Crack**: ํ๋ฉด ๊ท ์ด. |
|
- **๊ฒฐํจ ์ด๋ฏธ์ง ์์** |
|
- **๋ฐ์ดํฐ ๋ผ๋ฒจ๋ง ๊ธฐ์ค** |
|
|
|
-**1. ํ์ผ ๋ค์ด๋ฐ ๊ท์น** |
|
|
|
- ๋ฐ์ดํฐ ๋ฒ์ ๋ณ ํ์ผ๋ช
์ ๋ฒ์ ๋ณ๋ก ์์ดํจ. |
|
- ๊ฐ ๋ฒ์ ์ ๋ฐ์ดํฐ ๊ด๋ฆฌ ๋ฌธ์ ์ฐธ๊ณ |
|
- ๋ฐ์ดํฐ ํด๋๋ช
์ **`<์์ง๋
์์ผ>_<V๋ฒ์ >_<๊ฐ๋จํ ์ค๋ช
>`** ํ์์ผ๋ก ์์ฑ. |
|
- ์์:20240910_V0_๊ฐ์ด ํ๊ฒฝ ๋ฐ์ดํฐ ์์ง |
|
|
|
- **2. ๋ผ๋ฒจ ๋ฉํ๋ฐ์ดํฐ** |
|
|
|
๋ผ๋ฒจ ๋ฉํ๋ฐ์ดํฐ๋ csv ํ์์ผ๋ก ์ ์ฅํ๋ฉฐ, ๊ฐ ๋ฐ์ดํฐ์ ๋ผ๋ฒจ ๋ฐ ์ค๋ช
์ ํฌํจ. |
|
|
|
- **ํ์ ํ๋**: |
|
- `image_id`: ์ด๋ฏธ์ง ํ์ผ๋ช
. |
|
- `label`: ์ ์(`normal`) ๋๋ ๋น์ ์(`anomaly`) ์ฌ๋ถ. |
|
- `description`: ์์ธ ์ค๋ช
(์: ๊ฒฐํจ ์ ํ). |
|
|
|
- **์์:** |
|
```ruby |
|
{ |
|
"image_id": "normal_20241111_001.jpg", |
|
"label": "normal", |
|
"description": "๋งค๋๋ฌ์ด ํ๋ฉด์ ๊ฐ์ง ์ ์์ ์ธ ๊ธ์ ๋ถํ, ๊ดํ์ด ๊ท ์ผํจ." |
|
} |
|
{ |
|
"image_id": "abnormal_20241111_002.jpg", |
|
"label": "error", |
|
"description": "ํ๋ฉด์ ์ ํ ์คํฌ๋์น๊ฐ ๋ฐ๊ฒฌ๋จ." |
|
} |
|
``` |
|
|
|
|
|
# AD-CLIP Model Architecture |
|
AD-CLIP ๋ชจ๋ธ์ CLIP (ViT-B-32)์ ๋ฐฑ๋ณธ์ผ๋ก ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ํน์ง์ ์ถ์ถํ๊ณ , ๋์กฐ ํ์ต์ ํตํด ์ด์์ ํ์งํฉ๋๋ค. |
|
์ต์ข
์ถ๋ ฅ์ ์ด๋ฏธ์ง๊ฐ ๋น์ ์์ธ์ง ์ ์์ธ์ง๋ฅผ ํ๋ณํ๋ ์ด์ ์ ์์ ๊ฐ ํด๋์ค์ ํ๋ฅ ์ ์ ๊ณตํฉ๋๋ค. |
|
<div style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/62sYcSncxxzqGjQAa0MgQ.png" height="500" width="70%"> |
|
<p>CLIP-based Anomaly Detection Model Architecture</p> |
|
</div> |
|
|
|
- **model:** |
|
- ์
๋ ฅ ๊ณ์ธต (Input Layer): |
|
- ์
๋ ฅ ์ด๋ฏธ์ง: ๋ชจ๋ธ์ ํฌ๊ธฐ [640, 640, 3]์ ์ด๋ฏธ์ง๋ฅผ ์
๋ ฅ๋ฐ์ต๋๋ค. ์ฌ๊ธฐ์ 640x640์ ์ด๋ฏธ์ง์ ๊ฐ๋ก์ ์ธ๋ก ํฌ๊ธฐ์ด๋ฉฐ, 3์ RGB ์์์ ์ฑ๋ ์๋ฅผ ๋ํ๋
๋๋ค. |
|
- ๊ธฐ๋ฅ: ์ด ๊ณ์ธต์ ์
๋ ฅ๋ ์ด๋ฏธ์ง๋ฅผ ์ฒ๋ฆฌํ๊ณ ๋ชจ๋ธ์ ๋๋จธ์ง ๋ถ๋ถ์ ๋ง๋ ํ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ค๋นํ๋ ์ญํ ์ ํฉ๋๋ค. |
|
- backbone: |
|
- CLIP (ViT-B-32): ๋ชจ๋ธ์ CLIP์ Vision Transformer (ViT-B-32) ์ํคํ
์ฒ๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ํน์ง์ ์ถ์ถํฉ๋๋ค. ViT-B-32๋ ์ด๋ฏธ์ง๋ฅผ ์ดํดํ๋ ๋ฐ ํ์ํ ๊ณ ๊ธ ํน์ฑ์ ์ถ์ถํ ์ ์๋ ๋ฅ๋ ฅ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. |
|
- ํํฐ: ํํฐ ํฌ๊ธฐ [32, 64, 128, 256, 512]๋ ๊ฐ ViT ๋ ์ด์ด์์ ์ฌ์ฉ๋๋ฉฐ, ์ด๋ฏธ์ง์ ๊ฐ ๋ ๋ฒจ์์ ์ค์ํ ์ ๋ณด๋ฅผ ์ถ์ถํ์ฌ ํน์ง์ ํ์ตํฉ๋๋ค. |
|
- neck: |
|
- ์ด์ ํ์ง ๋ชจ๋ (Anomaly Detection Module): ์ด ๋ชจ๋์ CLIP์์ ์ถ์ถ๋ ํน์ง์ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๋ถ์ํ๊ณ ์ด์ ์ฌ๋ถ๋ฅผ ํ๋จํฉ๋๋ค. ์ด ๋จ๊ณ์์๋ ์ด๋ฏธ์ง ๋ด์์ ์ ์๊ณผ ๋น์ ์ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ณํ๊ธฐ ์ํ ์ค์ํ ์ฒ๋ฆฌ๊ฐ ์ด๋ฃจ์ด์ง๋๋ค. |
|
- ๋์กฐ ํ์ต (Contrastive Learning): ๋์กฐ ํ์ต ๋ฐฉ๋ฒ์ ์ ์ ์ด๋ฏธ์ง์ ๋น์ ์ ์ด๋ฏธ์ง ๊ฐ์ ์ฐจ์ด๋ฅผ ํ์ตํ์ฌ, ์ด๋ฏธ์ง์ ์ด์ ์ฌ๋ถ๋ฅผ ๋์ฑ ๋ช
ํํ๊ฒ ๊ตฌ๋ถํ ์ ์๊ฒ ๋์์ค๋๋ค. |
|
- head: |
|
- ์ด์ ํ์ง ํค๋ (Anomaly Detection Head): ๋ชจ๋ธ์ ๋ง์ง๋ง ๋ถ๋ถ์ผ๋ก, ์ด ๊ณ์ธต์ ์ด๋ฏธ์ง๊ฐ ๋น์ ์์ ์ธ์ง ์ ์์ ์ธ์ง๋ฅผ ๊ฒฐ์ ํฉ๋๋ค. |
|
- outputs: |
|
- ์ด์ ์ ์ (Anomaly Score): ๋ชจ๋ธ์ ์ด๋ฏธ์ง๊ฐ ์ด์์ธ์ง ์๋์ง๋ฅผ ๋ํ๋ด๋ ์ ์(์: 1์ ์ด์, 0์ ์ ์)๋ฅผ ์ถ๋ ฅํฉ๋๋ค. |
|
- ํด๋์ค ํ๋ฅ (Class Probabilities): ๋ชจ๋ธ์ ๊ฐ ํด๋์ค์ ๋ํ ํ๋ฅ ์ ์ถ๋ ฅํ๋ฉฐ, ์ด ํ๋ฅ ์ ํตํด ๊ฒฐํจ์ด ์๋์ง ์๋์ง์ ์ฌ๋ถ๋ฅผ ํ๋จํฉ๋๋ค. |
|
|
|
# Optimizer and Loss Function |
|
- **training:** |
|
- optimizer: |
|
- name: AdamW # AdamW ์ตํฐ๋ง์ด์ (๊ฐ์ค์น ๊ฐ์ ํฌํจ) |
|
- lr: 0.0001 # ํ์ต๋ฅ |
|
- loss: |
|
- classification_loss: 1.0 # ๋ถ๋ฅ ์์ค (๊ต์ฐจ ์ํธ๋กํผ) |
|
- anomaly_loss: 1.0 # ๊ฒฐํจ ํ์ง ์์ค (์ด์ ํ์ง ๋ชจ๋ธ์ ๋ํ ์์ค) |
|
- contrastive_loss: 1.0 # ๋์กฐ ํ์ต ์์ค (์ ์ฌ๋ ๊ธฐ๋ฐ ์์ค) |
|
|
|
# Metrics |
|
- **metrics:** |
|
- Precision # ์ ๋ฐ๋ (Precision) |
|
- Recall # ์ฌํ์จ (Recall) |
|
- mAP # ํ๊ท ์ ๋ฐ๋ (Mean Average Precision) |
|
- F1-Score # F1-์ ์ (๊ท ํ ์กํ ํ๊ฐ ์งํ) |
|
|
|
# Training Parameters |
|
**ํ์ดํผํ๋ผ๋ฏธํฐ ์ค์ ** |
|
- Learning Rate: 0.001. |
|
- Batch Size: 8. |
|
- Epochs: 200. |
|
|
|
# Pre-trained CLIP model |
|
| Model | Download | |
|
| --- | --- | |
|
| ViT-B/32 | [download](https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt) | |
|
| ViT-B/16 | [download](https://openaipublic.azureedge.net/clip/models/5806e77cd80f8b59890b7e101eabd078d9fb84e6937f9e85e4ecb61988df416f/ViT-B-16.pt) | |
|
| ViT-L/14 | [download](https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt) | |
|
| ViT-L/14@336px | [download](https://openaipublic.azureedge.net/clip/models/3035c92b350959924f9f00213499208652fc7ea050643e8b385c2dac08641f02/ViT-L-14-336px.pt) | |
|
|
|
# Evaluation Parameters |
|
- F1-score: 90%์ด์. |
|
|
|
|
|
|
|
# ํ์ต ์ฑ๋ฅ ๋ฐ ํ
์คํธ ๊ฒฐ๊ณผ |
|
|
|
- **ํ์ต์ฑ๋ฅ ๊ฒฐ๊ณผ๊ณผ ๊ทธ๋ํ**: |
|
<div style="display: flex; justify-content: space-between; margin-bottom: 10px;"> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/7Q1RzKyia-WNSCJHnk2-d.png" height="80%" width="100%" style="margin-right:5px;"> |
|
</div> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/9PyBtPZMACgN1lJOqlVbG.png" height="80%" width="100%" style="margin-right:5px;"> |
|
</div> |
|
</div> |
|
<p style="text-align: center;">ํ์ต ๊ณผ์ ์์</p> |
|
|
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/_lUD77x-yueXycuIn7jya.png" height="80%" width="100%" style="margin-right:5px;"> |
|
<p>1์ฐจ ํ์ต ์ฑ๋ฅ</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/NHDH9N94cI-KqP8k-ASUN.png" height="80%" width="100%" style="margin-right:5px;"> |
|
<p>2์ฐจ ํ์ต ์ฑ๋ฅ</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/6n0DnnQjXD8Ql-p3Owxan.png" height="80%" width="100%" style="margin-right:5px;"> |
|
<p>3์ฐจ ํ์ต ์ฑ๋ฅ</p> |
|
</div> |
|
</div> |
|
|
|
- **ํ
์คํธ ๊ฒฐ๊ณผํ**: |
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/u1DQHjXM41DMq1JIUOGlp.png" height="100%" width="100%" style="margin-right:5px;"> |
|
</div> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/ndQ60TKlheW8hmOrMBELU.png" height="100%" width="100%" style="margin-right:5px;"> |
|
</div> |
|
</div> |
|
|
|
- **ํ
์คํธ ๊ฒฐ๊ณผ**: |
|
<div style="display: flex; justify-content: space-between;"> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/A91V0GdrcUcX01cC-biG9.png" height="600" width="1000" style="margin-right:5px;"> |
|
<p>Anomaly Product</p> |
|
</div> |
|
<div style="text-align: center; margin-right: 20px;"> |
|
<img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/PxleIhphzViTGCubVhWn7.png" height="600" width="1000" style="margin-right:5px;"> |
|
<p>Normal Product</p> |
|
</div> |
|
</div> |
|
|
|
|
|
|
|
# ์ค์น ๋ฐ ์คํ ๊ฐ์ด๋ผ์ธ |
|
|
|
์ด ๋ชจ๋ธ์ ์คํํ๋ ค๋ฉด Python๊ณผ ํจ๊ป ๋ค์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค: |
|
|
|
- **ftfy==6.2.0**: ํ
์คํธ ์ ๊ทํ ๋ฐ ์ธ์ฝ๋ฉ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **matplotlib==3.9.0**: ๋ฐ์ดํฐ ์๊ฐํ ๋ฐ ๊ทธ๋ํ ์์ฑ์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **numpy==1.24.3**: ์์น ์ฐ์ฐ์ ์ํ ํต์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **opencv_python==4.9.0.80**: ์ด๋ฏธ์ง ๋ฐ ๋น๋์ค ์ฒ๋ฆฌ์ฉ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **pandas==2.2.2**: ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ์กฐ์์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **Pillow==10.3.0**: ์ด๋ฏธ์ง ํ์ผ ์ฒ๋ฆฌ ๋ฐ ๋ณํ์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **PyQt5==5.15.10**: GUI ์ ํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐ์ ์ํ ํ๋ ์์ํฌ. |
|
- **PyQt5_sip==12.13.0**: PyQt5์ Python ๊ฐ์ ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **regex==2024.5.15**: ์ ๊ท ํํ์ ์ฒ๋ฆฌ๋ฅผ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **scikit_learn==1.2.2**: ๊ธฐ๊ณ ํ์ต ๋ฐ ๋ฐ์ดํฐ ๋ถ์์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **scipy==1.9.1**: ๊ณผํ ๋ฐ ๊ธฐ์ ๊ณ์ฐ์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **setuptools==59.5.0**: Python ํจํค์ง ๋ฐฐํฌ ๋ฐ ์ค์น๋ฅผ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **scikit-image**: ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ฐ ๋ถ์์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **tabulate==0.9.0**: ํ ํํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **thop==0.1.1.post2209072238**: PyTorch ๋ชจ๋ธ์ FLOP ์๋ฅผ ๊ณ์ฐํ๋ ๋๊ตฌ. |
|
- **timm==0.6.13**: ๋ค์ํ ์ต์ ์ด๋ฏธ์ง ๋ถ๋ฅ ๋ชจ๋ธ์ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **torch==2.0.0**: PyTorch ๋ฅ๋ฌ๋ ํ๋ ์์ํฌ. |
|
- **torchvision==0.15.1**: ์ปดํจํฐ ๋น์ ์์
์ ์ํ PyTorch ํ์ฅ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **tqdm==4.65.0**: ์งํ ์ํฉ์ ์๊ฐ์ ์ผ๋ก ํ์ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
- **pyautogui**: GUI ์๋ํ๋ฅผ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. |
|
|
|
- Install Python libraries |
|
``` |
|
pip install -r requirements.txt |
|
``` |
|
|
|
|
|
## ๋ชจ๋ธ ์คํ ๋จ๊ณ: |
|
|
|
### โ
Dataset configuration |
|
|
|
- Dataset configuration as example below |
|
``` |
|
โโโ data/ |
|
โ โโโ COMP_1/ |
|
โ โ โโโ product_1/ |
|
โ โ โ โโโgrouth_truth |
|
โ โ โ โ โโโanomaly_1 |
|
โ โ โ โ โโโanomaly_2 |
|
โ โ โ โ |
|
โ โ โ โโโtest/ |
|
โ โ โ โ โโโgood |
|
โ โ โ โ โโโanomaly_1 |
|
โ โ โ โ โโโanomaly_2 |
|
โ โ โ โ |
|
โ โ โ โโโtrain/ |
|
โ โ โ โ โโโgood |
|
โ โ โ โ โโโanomaly_1 |
|
โ โ โ โ โโโanomaly_2 |
|
โ โ โ โ |
|
โ โ โโโ product_2/ |
|
โ โ โ โ |
|
โ โ โโโ meta.json |
|
โ โ โ |
|
โ โโโ COMP_2/ |
|
โ โ |
|
``` |
|
|
|
- Generate JSON file storing all the above information of dataset ( -> meta_train.json, meta_test.json) |
|
```ruby |
|
cd dataset_config |
|
python dataset_get_json.py |
|
``` |
|
|
|
- Making all grouth_truth (only anomaly mask) by hand |
|
```ruby |
|
cd dataset_config |
|
python image_ground_truth.py |
|
``` |
|
|
|
- Dataset configuration for train and test |
|
```ruby |
|
cd training_libs |
|
python dataset.py |
|
``` |
|
|
|
โ _ _init_ _ ๋ฉ์๋๋ ๋ฐ์ดํฐ์
์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ, ๋ณํ ํจ์, ๋ฐ์ดํฐ์
์ด๋ฆ, ๋ชจ๋๋ฅผ ์
๋ ฅ์ผ๋ก ๋ฐ์ |
|
โ ๋ฉํ ์ ๋ณด๋ฅผ ๋ด์ JSON ํ์ผ (meta_train.json)์ ์ฝ์ด์ ํด๋์ค ์ด๋ฆ ๋ชฉ๋ก๊ณผ ๋ชจ๋ ๋ฐ์ดํฐ ํญ๋ชฉ์ ๋ฆฌ์คํธ์ ์ ์ฅ |
|
โ generate_class_info ํจ์๋ฅผ ํธ์ถํ์ฌ ํด๋์ค ์ ๋ณด๋ฅผ ์์ฑํ๊ณ ํด๋์ค ์ด๋ฆ์ ํด๋์ค ID์ ๋งคํ |
|
โ _ _len_ _ ๋ฉ์๋๋ ๋ฐ์ดํฐ์
์ ์ํ ์๋ฅผ ๋ฐํ |
|
โ _ _getitem_ _ ๋ฉ์๋๋ ์ฃผ์ด์ง ์ธ๋ฑ์ค์ ์ํ ๋ฐ์ดํฐ๋ฅผ ๋ฐํ |
|
โ ์ด๋ฏธ์ง ๊ฒฝ๋ก๋ฅผ ํตํด ์ด๋ฏธ์ง๋ฅผ ์ฝ๊ณ , ์ด์ ์ฌ๋ถ์ ๋ฐ๋ผ ๋ง์คํฌ ์ด๋ฏธ์ง๋ฅผ ์์ฑ |
|
โ ํ์์ ์ด๋ฏธ์ง์ ๋ง์คํฌ์ ๋ณํ ํจ์๋ฅผ ์ ์ฉ |
|
โ ์ด๋ฏธ์ง, ๋ง์คํฌ, ํด๋์ค ์ด๋ฆ, ์ด์ ์ฌ๋ถ, ์ด๋ฏธ์ง ๊ฒฝ๋ก, ํด๋์ค ID๋ฅผ ํฌํจํ ๋์
๋๋ฆฌ๋ฅผ ๋ฐํ |
|
|
|
|
|
### โ
Image pre-processing (transformation) for train and test |
|
```ruby |
|
training_libs/utils.py |
|
``` |
|
```ruby |
|
AnomalyCLIP_lib/transform.py |
|
``` |
|
- **Data Processing Techniques:** |
|
- normalization: |
|
description: "์ด๋ฏธ์ง ํฝ์
๊ฐ์ ํ๊ท ๋ฐ ํ์คํธ์ฐจ๋ก ํ์คํ" |
|
method: "'Normalize' from 'torchvision.transforms'" |
|
- max_resize: |
|
description: "์ด๋ฏธ์ง์ ์ต๋ ํฌ๊ธฐ๋ฅผ ์ ์งํ๋ฉฐ, ๋น์จ์ ๋ง์ถ๊ณ ํจ๋ฉ์ ์ถ๊ฐํ์ฌ ํฌ๊ธฐ ์กฐ์ " |
|
method: "Custom 'ResizeMaxSize' class" |
|
- random_resized_crop: |
|
description: "ํ๋ จ ์ค์ ์ด๋ฏธ์ง๋ฅผ ๋๋ค์ผ๋ก ์๋ฅด๊ณ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํ์ฌ ๋ณํ์ ์ถ๊ฐ" |
|
method: "'RandomResizedCrop' from 'torchvision.transforms'" |
|
- resize: |
|
description: "๋ชจ๋ธ ์
๋ ฅ์ ๋ง๊ฒ ์ด๋ฏธ์ง๋ฅผ ๊ณ ์ ๋ ํฌ๊ธฐ๋ก ์กฐ์ " |
|
method: "'Resize' with BICUBIC interpolation" |
|
- center_crop: |
|
description: "์ด๋ฏธ์ง์ ์ค์ ๋ถ๋ถ์ ์ง์ ๋ ํฌ๊ธฐ๋ก ์๋ฅด๊ธฐ" |
|
method: "'CenterCrop'" |
|
- to_tensor: |
|
description: "์ด๋ฏธ์ง๋ฅผ PyTorch ํ
์๋ก ๋ณํ" |
|
method: "'ToTensor'" |
|
- augmentation (optional): |
|
description: "๋ฐ์ดํฐ ์ฆ๊ฐ์ ์ํด ๋ค์ํ ๋๋ค ๋ณํ ์ ์ฉ, 'AugmentationCfg'๋ก ์ค์ ๊ฐ๋ฅ" |
|
method: "Uses 'timm' library if specified" |
|
|
|
### โ
Prompt generating |
|
```ruby |
|
training_lib/prompt_ensemble.py |
|
``` |
|
๐ **Prompts Built in the Code** |
|
1. Normal Prompt: *'["{ }"]'* |
|
โ Normal Prompt Example: "object" |
|
2. Anomaly Prompt: *'["damaged { }"]'* |
|
โ Anomaly Prompt Example: "damaged object" |
|
|
|
๐ **Construction Process** |
|
1. *'prompts_pos (Normal)'*: Combines the class name with the normal template |
|
2. *'prompts_neg (Anomaly)'*: Combines the class name with the anomaly template |
|
|
|
### โ
Initial setting for training |
|
|
|
- Define the path to the training dataset and model checkpoint saving |
|
```ruby |
|
parser.add_argument("--train_data_path", type=str, default="./data/", help="train dataset path") |
|
parser.add_argument("--dataset", type=str, default='smoke_cloud', help="train dataset name") |
|
parser.add_argument("--save_path", type=str, default='./checkpoint/', help='path to save results') |
|
``` |
|
|
|
### โ
Hyper parameters setting |
|
|
|
- Set the depth parameter: depth of the embedding learned during prompt training. This affects the model's ability to learn complex features from the data |
|
```ruby |
|
parser.add_argument("--depth", type=int, default=9, help="image size") |
|
``` |
|
|
|
- Define the size of input images used for training (pixel) |
|
```ruby |
|
parser.add_argument("--image_size", type=int, default=518, help="image size") |
|
``` |
|
|
|
- Setting parameters for training |
|
```ruby |
|
parser.add_argument("--epoch", type=int, default=500, help="epochs") |
|
parser.add_argument("--learning_rate", type=float, default=0.0001, help="learning rate") |
|
parser.add_argument("--batch_size", type=int, default=8, help="batch size") |
|
``` |
|
|
|
- Size/depth parameter for the DPAM (Deep Prompt Attention Mechanism) |
|
```ruby |
|
parser.add_argument("--dpam", type=int, default=20, help="dpam size") |
|
|
|
1. ViT-B/32 and ViT-B/16: --dpam should be around 10-13 |
|
2. ViT-L/14 and ViT-L/14@336px: --dpam should be around 20-24 |
|
``` |
|
```ruby |
|
โ DPAM is used to refine and enhance specific layers of a model, particularly in Vision Transformers (ViT). |
|
โ Helps the model focus on important features within each layer through an attention mechanism |
|
โ Layers: DPAM is applied across multiple layers, allowing deeper and more detailed feature extraction |
|
โ Number of layers DPAM influences is adjustable (--dpam), controlling how much of the model is fine-tuned. |
|
โ If you want to refine the entire model, you can set --dpam to the number of layers in the model (e.g., 12 for ViT-B and 24 for ViT-L). |
|
โ If you want to focus only on the final layers (where the model usually learns complex features), you can choose fewer DPAM layers. |
|
``` |
|
|
|
### โ
Test process |
|
|
|
๐ **Load pre-trained and Fine tuned (Checkpoints) models** |
|
1. Pre-trained mode (./pre-trained model/): |
|
```ruby |
|
โ Contains the pre-trained model (ViT-B, ViT-L,....) |
|
โ Used as the starting point for training the CLIP model |
|
โ Pre-trained model helps speed up and improve training by leveraging previously learned features |
|
``` |
|
2. Fine-tuned models (./checkpoint/): |
|
```ruby |
|
โ "epoch_N.pth" files in this folder store the model's states during the fine-tuning process. |
|
โ Each ".pth" file represents a version of the model fine-tuned from the pre-trained model |
|
โ These checkpoints can be used to resume fine-tuning, evaluate the model at different stages, or select the best-performing version |
|
``` |
|
|
|
|
|
# ๋ชจ๋ธ ๊ณต๊ฒฉ ์ทจ์ฝ์ ๋ถ์ |
|
๋ณธ ๋ฌธ์๋ AnomalyCLIP ๋ชจ๋ธ์ ์ทจ์ฝ์ ๋ถ์ ๋ฐ ์ ๋์ ๊ณต๊ฒฉ(Adversarial Attacks)์ ๋ํ ๋ฐฉ์ด ๋์ฑ
์ ์ฒด๊ณ์ ์ผ๋ก ์๋ฆฝํ๊ธฐ ์ํด ์์ฑ๋์์ต๋๋ค. |
|
๋ชจ๋ธ์ ์ ๋ขฐ์ฑ๊ณผ ์์ ์ฑ์ ํ๋ณดํ๊ณ ๋ฐ์ดํฐ ๋ฌด๊ฒฐ์ฑ์ ์ ์งํ๊ธฐ ์ํด, ๋ฐ์ดํฐ ๋ฐ ๋ชจ๋ธ ์์ค์ ๋ฐฉ์ด ์ ๋ต์ ๊ตฌํํ๊ณ ์ฑ๋ฅ์ ํ๊ฐํ ๊ฒฐ๊ณผ๋ฅผ ํฌํจํฉ๋๋ค. |
|
## **1. ์ทจ์ฝ์ ๋ถ์** |
|
- ### ** ์ ๋์ ๊ณต๊ฒฉ ์๋๋ฆฌ์ค** |
|
1. **Adversarial Examples:** |
|
- **์ค๋ช
:** ์
๋ ฅ ๋ฐ์ดํฐ์ ์์ ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ์ฌ ๋ชจ๋ธ์ ์์ธก์ ์๊ณก. |
|
- **์:** ์ ์ ์ด๋ฏธ์ง๋ฅผ ๊ฒฐํจ ์ด๋ฏธ์ง๋ก ์์ธกํ๋๋ก ์ ๋. |
|
2. **Data Poisoning:** |
|
- **์ค๋ช
:** ํ์ต ๋ฐ์ดํฐ์ ์
์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์
ํ์ฌ ๋ชจ๋ธ ํ์ต์ ์๊ณก. |
|
- **์:** ๋น์ ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ ๋ฐ์ดํฐ๋ก ํ์ต์ํค๋ ๊ฒฝ์ฐ. |
|
3. **Evasion Attacks:** |
|
- **์ค๋ช
:** ์ถ๋ก ์ ๋ชจ๋ธ์ ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ์กฐ์. |
|
- **์:** ๊ฒฐํจ ๋ฐ์ดํฐ๋ฅผ ์ ์์ผ๋ก ์์ธกํ๋๋ก ์ ๋. |
|
|
|
- ### **๋ชจ๋ธ ๋ฐ ๋ฐ์ดํฐ์
์ํฅ** |
|
- **์ฑ๋ฅ ์ ํ:** ์ ๋์ ์ํ ์
๋ ฅ ์ ๋ชจ๋ธ์ ์ ํ๋ ๊ฐ์. |
|
- **๋ฌด๊ฒฐ์ฑ ์์:** ๋ฐ์ดํฐ ๋ณ์กฐ๋ก ์ธํด ํ์ต๋ ๋ชจ๋ธ์ด ์ค์ ํ๊ฒฝ์์ ์ ๋ขฐ์ฑ์ ์์ค. |
|
- **์
์์ ํ์ฉ ๊ฐ๋ฅ์ฑ:** ๋ชจ๋ธ์ ์์ฌ๊ฒฐ์ ์ด ์ค์๋ํ์ฌ ์์ฐ ํ์ง ๊ด๋ฆฌ ์คํจ ๊ฐ๋ฅ์ฑ ์ฆ๊ฐ. |
|
|
|
## **2. ๋์ ๋ฐฉ์** |
|
|
|
- ### ** ๋ฐ์ดํฐ ์์ค ๋ฐฉ์ด ๋์ฑ
** |
|
1. **๋ฐ์ดํฐ ์ ์ :** |
|
- ํ๋ฆฟํ๊ฑฐ๋ ์๋ฆฐ ์ด๋ฏธ์ง ์ ๊ฑฐ. |
|
- ๋ฐ์ดํฐ ๋
ธ์ด์ฆ ์ ๊ฑฐ ๋ฐ ๊ฒฐํจ ๋ณต๊ตฌ. |
|
- **๊ฒฐ๊ณผ:** ๋ฐ์ดํฐ ํ์ง ๊ฐํ๋ก ์ ๋์ ๋
ธ์ด์ฆ ํจ๊ณผ ๊ฐ์. |
|
2. **๋ฐ์ดํฐ ์ฆ๊ฐ(Data Augmentation):** |
|
- ๋๋ค ํ์ , ํฌ๊ธฐ ์กฐ์ , ๋ฐ๊ธฐ ๋ฐ ๋๋น ์กฐ์ . |
|
- Gaussian Noise ๋ฐ Salt-and-Pepper Noise ์ถ๊ฐ. |
|
- **๊ฒฐ๊ณผ:** ๋ฐ์ดํฐ ๋ค์์ฑ ํ๋ณด ๋ฐ ๋ชจ๋ธ ์ผ๋ฐํ ์ฑ๋ฅ ๊ฐํ. |
|
3. **๋ฐ์ดํฐ ๋ฌด๊ฒฐ์ฑ ๊ฒ์ฆ:** |
|
- ๊ฐ ๋ฐ์ดํฐ ํด์๊ฐ(MD5) ์ ์ฅ ๋ฐ ์๋ณ์กฐ ์ฌ๋ถ ํ์ธ. |
|
- **๊ฒฐ๊ณผ:** ๋ฐ์ดํฐ์
์ ๋ขฐ์ฑ ๋ฐ ๋ฌด๊ฒฐ์ฑ ๋ณด์ฅ. |
|
|
|
- ### **๋ชจ๋ธ ์์ค ๋ฐฉ์ด ๋์ฑ
** |
|
1. **Adversarial Training:** |
|
- FGSM ๊ธฐ๋ฐ์ ์ ๋์ ์ํ์ ํ์ต ๋ฐ์ดํฐ์ ํฌํจ. |
|
- **๊ฒฐ๊ณผ:** ์ ๋์ ์ํ์์๋ ํ๊ท ์ ํ๋ 5% ํฅ์. |
|
2. **Gradient Masking:** |
|
- ๊ทธ๋๋์ธํธ๋ฅผ ์จ๊ฒจ ๋ชจ๋ธ์ด ์ ๋์ ๊ณต๊ฒฉ์ ๋
ธ์ถ๋์ง ์๋๋ก ๋ฐฉ์ด. |
|
3. **Temperature Scaling:** |
|
- ๋ชจ๋ธ์ ์์ธก ํ๋ฅ ์ ์กฐ์ ํ์ฌ ์ ๋์ ์ํ ๋ฏผ๊ฐ๋ ์ํ. |
|
|
|
- ### **์์คํ
์์ค ๋ฐฉ์ด ๋์ฑ
** |
|
1. **์ค์๊ฐ ํ์ง ๋ฐ ๋์:** |
|
- ์
๋ ฅ ๋ฐ์ดํฐ์ ์ด์ ํจํด์ ์ค์๊ฐ์ผ๋ก ํ์งํ๋ ์์คํ
๊ตฌ์ถ. |
|
- **๊ฒฐ๊ณผ:** ์ ๋์ ๊ณต๊ฒฉ ๋ฐ์ ์ ์ฆ๊ฐ์ ์ธ ๊ฒฝ๊ณ ๋ฐ ๋์ ๊ฐ๋ฅ. |
|
2. **์๋ํ๋ ๋ฐฉ์ด ๋๊ตฌ:** |
|
- Adversarial Examples ์์ฑ ๋ฐ ๋ฐฉ์ด ํ
์คํธ ์๋ํ. |
|
|
|
## **3. ์คํ ๊ฒฐ๊ณผ** |
|
|
|
- ### **ํ๊ฐ ๋ฐ์ดํฐ** |
|
|
|
- **๋ฐ์ดํฐ์
๊ตฌ์ฑ:** |
|
- ์ ์ ๋ฐ์ดํฐ: 110๊ฑด |
|
- ๊ฒฐํจ ๋ฐ์ดํฐ: 10๊ฑด |
|
- ์ ๋์ ๋ฐ์ดํฐ(FGSM ๊ณต๊ฒฉ): 100๊ฑด |
|
|
|
- ### **์ฃผ์ ์ฑ๋ฅ ์งํ** |
|
๋ฉํธ๋ฆญ | ๊ธฐ๋ณธ ๋ฐ์ดํฐ | ์ ๋์ ๋ฐ์ดํฐ | ๋ณํ์จ |
|
-----------------|-------------|---------------|-------- |
|
Accuracy | 98% | 92% | -6% |
|
F1 Score | 0.935 | 0.91 | -2.5% |
|
False Positive | 2% | 5% | +3% |
|
False Negative | 3% | 7% | +4% |
|
|
|
## **4. ํฅํ ๊ณํ** |
|
1. **๋ค์ํ ๊ณต๊ฒฉ ๊ธฐ๋ฒ ํ
์คํธ:** |
|
- PGD, DeepFool ๋ฑ ์๋ก์ด ๊ณต๊ฒฉ ๊ธฐ๋ฒ ์ ์ฉ ๋ฐ ํ๊ฐ. |
|
2. **๋ชจ๋ธ ๊ฐ์ :** |
|
- Contrastive Learning ๋ฐ ์์๋ธ ํ์ต์ ํตํ ๊ฒฌ๊ณ ์ฑ ๊ฐํ. |
|
3. **์ค์๊ฐ ๋ฐฉ์ด ์์คํ
๊ตฌ์ถ:** |
|
- ๋ชจ๋ธ์ ์ค์๊ฐ ์์ธก ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ์ ๋์ ์
๋ ฅ ํ์ง ๋ฐ ์ฐจ๋จ. |
|
|
|
|
|
|
|
# References |
|
- AnomalyCLIP: Object-agnostic Prompt Learning for Zero-shot Anomaly Detection [[github](https://github.com/zqhang/AnomalyCLIP.git)] |