|
|
--- |
|
|
license: apache-2.0 |
|
|
tags: |
|
|
- anomaly-detection |
|
|
- deep-svdd |
|
|
- computer-vision |
|
|
- pytorch |
|
|
datasets: |
|
|
- cifar10 |
|
|
- cifar100 |
|
|
metrics: |
|
|
- accuracy |
|
|
- precision |
|
|
- recall |
|
|
- f1 |
|
|
library_name: pytorch |
|
|
--- |
|
|
|
|
|
# Deep SVDD Anomaly Detection Model |
|
|
|
|
|
A Deep Support Vector Data Description (Deep SVDD) model trained for anomaly detection on natural images. |
|
|
|
|
|
## Model Description |
|
|
|
|
|
This model uses a ResNet-based encoder to learn a hypersphere representation of normal data. Images are classified as anomalies based on their distance from the center of this hypersphere. |
|
|
|
|
|
**Training Data:** |
|
|
- CIFAR-10 (50,000 images) |
|
|
- CIFAR-100 (50,000 images) |
|
|
- STL-10 (100,000 images) |
|
|
|
|
|
**Architecture:** |
|
|
- ResNet-based encoder with residual blocks |
|
|
- Latent dimension: 512 |
|
|
- Input size: 128x128x3 |
|
|
|
|
|
## Performance |
|
|
|
|
|
Evaluated on CIFAR-10 (normal) vs MNIST (anomaly): |
|
|
|
|
|
| Metric | Value | |
|
|
|--------|-------| |
|
|
| Accuracy | 87.00% | |
|
|
| Precision | 80.33% | |
|
|
| Recall | 98.00% | |
|
|
| F1 Score | 88.29% | |
|
|
|
|
|
**Anomaly Score Separation:** 6.15x (anomalies score ~6x higher than normal images) |
|
|
|
|
|
## Usage |
|
|
|
|
|
### Quick Start |
|
|
|
|
|
```python |
|
|
from model import DeepSVDDAnomalyDetector |
|
|
|
|
|
# Load model |
|
|
detector = DeepSVDDAnomalyDetector.from_pretrained('.') |
|
|
|
|
|
# Predict on image |
|
|
score, is_anomaly = detector.predict('test.jpg') |
|
|
print(f"Anomaly Score: {score:.6f}") |
|
|
print(f"Is Anomaly: {is_anomaly}") |
|
|
``` |
|
|
|
|
|
### Download from Hugging Face |
|
|
|
|
|
```python |
|
|
from huggingface_hub import snapshot_download |
|
|
|
|
|
# Download model |
|
|
model_path = snapshot_download(repo_id="ash12321/deep-svdd-anomaly-detection") |
|
|
|
|
|
# Load |
|
|
detector = DeepSVDDAnomalyDetector.from_pretrained(model_path) |
|
|
``` |
|
|
|
|
|
### Threshold Options |
|
|
|
|
|
The model supports three threshold presets: |
|
|
|
|
|
```python |
|
|
# Optimal F1 (default, recommended) |
|
|
detector.set_threshold('optimal') # threshold = 0.001618 |
|
|
|
|
|
# 95th percentile (balanced) |
|
|
detector.set_threshold('95th') # threshold = 0.008501 |
|
|
|
|
|
# 99th percentile (conservative, fewer false positives) |
|
|
detector.set_threshold('99th') # threshold = 0.015922 |
|
|
``` |
|
|
|
|
|
**Threshold Comparison:** |
|
|
|
|
|
| Threshold | Accuracy | Precision | Recall | Use Case | |
|
|
|-----------|----------|-----------|--------|----------| |
|
|
| Optimal (0.0016) | 87% | 80% | 98% | **Recommended** - Best F1 | |
|
|
| 95th (0.0085) | 75% | 95% | 53% | Few false alarms | |
|
|
| 99th (0.0159) | 68% | 100% | 35% | Zero false alarms | |
|
|
|
|
|
## Training Details |
|
|
|
|
|
- **Framework:** PyTorch 2.9.1+cu128 |
|
|
- **Precision:** bfloat16 mixed precision |
|
|
- **Optimizer:** Fused AdamW |
|
|
- **Hardware:** NVIDIA H200 |
|
|
- **Epochs:** 50 |
|
|
- **Batch Size:** 1536 |
|
|
|
|
|
## Model Files |
|
|
|
|
|
- `deepsvdd_model.pth` - Model weights and hypersphere parameters |
|
|
- `thresholds.pkl` - All threshold configurations |
|
|
- `thresholds.json` - Thresholds in JSON format |
|
|
- `config.json` - Model configuration |
|
|
- `model.py` - Inference code |
|
|
- `requirements.txt` - Python dependencies |
|
|
|
|
|
## Citation |
|
|
|
|
|
```bibtex |
|
|
@misc{deep-svdd-anomaly-detection, |
|
|
title={Deep SVDD Anomaly Detection Model}, |
|
|
author={ash12321}, |
|
|
year={2024}, |
|
|
publisher={Hugging Face}, |
|
|
url={https://huggingface.co/ash12321/deep-svdd-anomaly-detection} |
|
|
} |
|
|
``` |
|
|
|
|
|
## License |
|
|
|
|
|
Apache 2.0 |
|
|
|
|
|
## Limitations |
|
|
|
|
|
- Trained on natural images (CIFAR-10/100, STL-10) |
|
|
- Best suited for detecting distribution shift in natural images |
|
|
- May not generalize well to very different domains |
|
|
- Requires RGB images, resized to 128x128 |
|
|
|
|
|
## Intended Use |
|
|
|
|
|
**Primary Use:** Anomaly detection in natural image datasets |
|
|
|
|
|
**Good for:** |
|
|
- Quality control in image datasets |
|
|
- Detecting out-of-distribution samples |
|
|
- Filtering unusual/corrupted images |
|
|
- Content moderation |
|
|
|
|
|
**Not recommended for:** |
|
|
- Critical safety systems without human review |
|
|
- Domains very different from natural images |
|
|
|