File size: 766 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
"""
Example usage of Deep SVDD Anomaly Detection Model
"""

from model import DeepSVDDAnomalyDetector
from huggingface_hub import snapshot_download

# Download model from HuggingFace
print("Downloading model...")
model_path = snapshot_download(repo_id="ash12321/deep-svdd-anomaly-detection")

# Load model
print("Loading model...")
detector = DeepSVDDAnomalyDetector.from_pretrained(model_path)

# Example: Predict on image
score, is_anomaly = detector.predict('test.jpg')
print(f"Score: {score:.6f}")
print(f"Anomaly: {is_anomaly}")

# Try different thresholds
for threshold in ['optimal', '95th', '99th']:
    detector.set_threshold(threshold)
    score, is_anomaly = detector.predict('test.jpg')
    print(f"{threshold}: Score={score:.6f}, Anomaly={is_anomaly}")