iad-explainable-hf / config.py
Parikshit Rathode
initial commit
c5732cc
"""
Configuration settings for the anomaly detection project.
This module contains all configurable parameters including thresholds,
model mappings, and other constants used throughout the application.
"""
# Model directory mapping
MODEL_TO_DIR = {
"patchcore": "Patchcore",
"efficientad": "EfficientAd",
}
# MVTec AD dataset categories
MVTEC_CATEGORIES = [
"bottle", "cable", "capsule", "carpet", "grid",
"hazelnut", "leather", "metal_nut", "pill", "screw",
"tile", "toothbrush", "transistor", "wood", "zipper"
]
# Precomputed thresholds for each model and category
# These thresholds are computed at the 95th percentile of normal training scores
THRESHOLDS = {
"patchcore": {
"bottle": 0.3218444108963013,
"cable": 0.34408192038536073,
"capsule": 0.5454285681247711,
"carpet": 0.3088440954685211,
"grid": 0.25913039445877073,
"hazelnut": 0.10068576037883759,
"leather": 0.2726534068584442,
"metal_nut": 0.34413049668073653,
"pill": 0.26968240439891816,
"screw": 0.49187072515487673,
"tile": 0.3581161931157112,
"toothbrush": 0.3721309259533882,
"transistor": 0.45495494604110714,
"wood": 0.1711873710155487,
"zipper": 0.4981046631932258
},
"efficientad": {
"bottle": 0.49928921461105347,
"cable": 0.4673861160874367,
"capsule": 0.5370000839233399,
"carpet": 0.49847708493471143,
"grid": 0.5295769184827804,
"hazelnut": 0.5202932059764862,
"leather": 0.504090940952301,
"metal_nut": 0.5047085165977478,
"pill": 0.5043391764163971,
"screw": 0.7167768508195878,
"tile": 0.5030474990606308,
"toothbrush": 0.5439804702997207,
"transistor": 0.5076832294464111,
"wood": 0.5024313390254974,
"zipper": 1.0
}
}
# Hugging Face repository ID for checkpoints
HF_REPO_ID = "micguida1/mvtec-anomaly-checkpoints"
# Image size for model input
IMAGE_SIZE = 256
# Threshold multiplier for sensitivity adjustment
# Lower value = more sensitive (more anomalies detected)
THRESHOLD_MULTIPLIER = 0.85
# Visualization parameters
HEATMAP_ALPHA = 0.5
OVERLAY_ALPHA = 0.5
# PatchCore specific parameters
PATCHCORE_BINARY_THRESHOLD = 0.60
PATCHCORE_MIN_CONTOUR_AREA = 100
PATCHCORE_MAX_INTENSITY_THRESHOLD = 0.75
PATCHCORE_BLUR_KERNEL = (7, 7)
PATCHCORE_MORPH_KERNEL = (5, 5)
PATCHCORE_FG_THRESHOLD = 15
PATCHCORE_FG_MORPH_KERNEL = (9, 9)
# EfficientAD specific parameters
EFFICIENTAD_BINARY_THRESHOLD = 0.5
EFFICIENTAD_MIN_CONTOUR_AREA = 5