This repository provides implementations of both few-shot and zero-shot anomaly detection using CLIP embeddings.
AISystem-2402
├── fewshot-clip/
├── zeroshot-clip/
├── .gitignore
├── LICENSE
└── README.md
Training Dataset
└──── ./train
├──── {class_name}/
| ├──── 0000.jpg
| ├──── ...
| └──── 0000.jpg
├──── {class_name}/
| ├──── 0000.jpg
| ├──── ...
| └──── 0000.jpg
Test (Validation) Dataset
└──── ./test
├──── anomaly/
| ├──── 0000.jpg
| ├──── ...
| └──── 0000.jpg
├──── normal/
| ├──── 0000.jpg
| ├──── ...
| └──── 0000.jpg
The dataset for anomaly detection is organized to facilitate both few-shot and zero-shot approaches with CLIP embeddings.
Dataset can be downloaded here.(Last updated on November 24, 2024)
For Preliminary Competition (for personal practice)
- Training Data: 6 classes, 5
normalimages per class. - Validation Data: 6 classes, 200
anomalyand 200normalimages for each class.
For Main Competition (for project)
- Training Data: 10 classes (excluding the 6 classes from the preliminary competition), 5 normal images per class.
- Validation Data: No validation dataset will be given.
Each class within the anomaly dataset contains at least one example of an anomaly, such as dots, cuts, or other class-specific defects like below. This design encourages exploration of anomaly detection within constrained data conditions.
- Clone the Repository
git clone https://github.com/PiLab-CAU/AISystem-2402.git
- Set up the Conda Environment
conda create -n cauclip python=3.xx
The Recommended Python version is 3.8 or above 😉
conda activate cauclip
- Navigate to the Cloned Folder
cd AISystem-2402
- Install Dependencies
pip install -r requirements.txt
Once the dependencies are installed, we are ready to detect anomalies! 😀
To run the sample code for Few-Shot CLIP Embedding, execute:
python fewshot-clip/main.py
To run the sample code for Zero-Shot CLIP Embedding, execute:
python zeroshot-clip/main.py
The Performance of sample codes is shown in the tables below.
| Metric | Value |
|---|---|
| Train Loss (Epoch 1) | 0.7279 |
| Train Accuracy (Epoch 1) | 52.86% |
| Test Accuracy (Epoch 1) | 63.08% |
| Best Model Path | saved_models/best_model.pth (Accuracy: 63.08%) |
| Overall Test Accuracy | 32.31% |
| Total Time Taken | 18.42 seconds |
| Average Time per Image | 0.2834 seconds |
| Class | Correct | Total | Accuracy | Normal Similarity | Anomaly Similarity |
|---|---|---|---|---|---|
| Normal | 21 | 21 | 100.00% | - | - |
| Anomaly | 0 | 44 | 0.00% | - | - |
| Metric | Value |
|---|---|
| Total Images | 65 |
| Correct Predictions | 35 |
| Overall Accuracy | 53.85% |
| Class | Total | Correct | Incorrect | Accuracy | Avg Anomaly Score | Avg Normal Similarity | Avg Anomaly Similarity |
|---|---|---|---|---|---|---|---|
| Normal | 21 | 21 | 0 | 100.00% | 0.288 | 0.921 | 0.634 |
| Anomaly | 44 | 14 | 30 | 31.82% | 0.234 | 0.862 | 0.627 |
| Metric | Value |
|---|---|
| Precision | 100.00% |
| Recall | 31.82% |
| F1 Score | 48.28% |
Metrics saved in ./results/metrics_{datetime}_{time}.json. Results can be found in the ./results directory.
For additional details on each module, check out the specific README files:
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or further information, please contact leessoit@gmail.com or use the issue tab to report any problems or suggestions.

