File size: 3,628 Bytes
0e9dcc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | ---
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
|