Note: BASE REPO
Dataset source files and public model checkpoints are listed in the collapsible download section below.
Install Python using Conda
conda create -n AD python==3.9.18 -y
conda activate AD
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidiagit clone https://github.com/rashidrao-pk/AD_MultiPointThreshold
conda activate AD
pip install -r requirements.txtThe project uses external datasets and pretrained checkpoints. They are not stored directly in this repository because of file size limitations.
2.1 Install download tools
Install the Kaggle and Hugging Face CLIs:
pip install -U kaggle huggingface_hub
# or using conda
# conda install -c conda-forge huggingface_hubhf --helpFor Kaggle downloads, make sure your Kaggle API token is configured. Download kaggle.json from your Kaggle account settings and place it in:
mkdir -p ~/.kaggle
cp kaggle.json ~/.kaggle/kaggle.json
chmod 600 ~/.kaggle/kaggle.json2.2 Download datasets from Kaggle
Supported public Kaggle datasets:
| Dataset | Kaggle URL | Suggested Local Folder |
|---|---|---|
| Robotics Hazards | https://www.kaggle.com/datasets/rashidrao/robotics-hazards | data/Robotics_Hazards |
| Cobots Synthetic / DistriMuSe UniGra | https://www.kaggle.com/datasets/rashidrao/cobots-synthetic/ | data/Cobots_Synthetic |
Download and unzip:
mkdir -p data
kaggle datasets download -d rashidrao/robotics-hazards \
-p data/Robotics_Hazards \
--unzip
kaggle datasets download -d rashidrao/cobots-synthetic \
-p data/Cobots_Synthetic \
--unzipRecommended folder structure:
data/
├── Robotics_Hazards/
├── Cobots_Synthetic/
└── MVtec/
Set the dataset root path:
export DATA_ROOT=$(pwd)/data2.3 Download pretrained checkpoints from Hugging Face
Pretrained model checkpoints are available here:
| Checkpoint Repository | Dataset / Use Case |
|---|---|
| https://huggingface.co/rashidrao/AD_Cobots_Synthetic | Cobots Synthetic / DistriMuSe UniGra |
| https://huggingface.co/rashidrao/AD_Robotics_Hazards | Robotics Hazards |
| https://huggingface.co/rashidrao/AD_MVTec | MVTec AD |
Download all checkpoint repositories:
mkdir -p checkpoints
hf download rashidrao/AD_Cobots_Synthetic \
--local-dir checkpoints/AD_Cobots_Synthetic
hf download rashidrao/AD_Robotics_Hazards \
--local-dir checkpoints/AD_Robotics_Hazards
hf download rashidrao/AD_MVTec \
--local-dir checkpoints/AD_MVTecor
pip install -U huggingface_hubfrom huggingface_hub import snapshot_download
snapshot_download(
repo_id="rashidrao/AD_Cobots_Synthetic",
local_dir="checkpoints/AD_Cobots_Synthetic"
)from huggingface_hub import snapshot_download
snapshot_download(
repo_id="rashidrao/AD_Robotics_Hazards",
local_dir="checkpoints/AD_Robotics_Hazards"
)from huggingface_hub import snapshot_download
snapshot_download(
repo_id="rashidrao/AD_MVTec",
local_dir="checkpoints/AD_MVTec"
)Expected checkpoint structure:
checkpoints/
├── AD_Cobots_Synthetic/
│ ├── model_PLeft_64.pt
│ ├── model_PRight_64.pt
│ ├── model_RoboArm_64.pt
│ └── model_ConvBelt_64.pt
├── AD_Robotics_Hazards/
└── AD_MVTec/
2.4 Verify downloaded checkpoints
List available models:
python utils/scripts/model_loader.py --listInspect a checkpoint and test a forward pass:
python utils/scripts/model_loader.py \
--model_path checkpoints/AD_Cobots_Synthetic/model_RoboArm_64.pt \
--show_summary \
--test_forward \
--device auto2.5 Quick inference with pretrained checkpoints
Example with the Cobots Synthetic / DistriMuSe UniGra RoboArm model:
python utils/scripts/inference.py \
--dataset Cobots_Synthetic \
--safety_area RoboArm \
--checkpoints checkpoints/AD_Cobots_Synthetic \
--static_mask_paths masks/PLeft.png masks/PRight.png masks/RoboArm.png masks/ConvBelt.png \
--threshold_dir results/thresholdsExample with all safety areas:
python utils/scripts/inference.py \
--dataset Cobots_Synthetic \
--safety_area ALL \
--checkpoints checkpoints/AD_Cobots_Synthetic \
--static_mask_paths masks/PLeft.png masks/PRight.png masks/RoboArm.png masks/ConvBelt.png \
--threshold_dir results/thresholds2.6 Notes on thresholds
Thresholds are dataset-specific and camera/setup-specific. If you change the dataset, camera view, preprocessing, or safety-area masks, recalibrate thresholds before reporting final results.
python utils/scripts/calibrate_threshold.py \
--safety_area RoboArm \
--checkpoints checkpoints/AD_Cobots_Synthetic \
--threshold_strategy percentile \
--threshold_percentile 99.0Optional: Train models Again?
Train a VAE-GAN model on one (PLeft, PRight, RoboArm, ConvBelt) or all safety areas.
# Single area (default settings)
python utils/scripts/train.py --safety_area RoboArm# All areas sequentially
python utils/scripts/train.py --safety_area ALLRun anomaly detection from multiple input sources including following input sources;
# Pre-cropped frames, evaluate against annotations
python utils/scripts/inference.py --dataset MVtec --object hazelnut
python utils/scripts/inference.py --dataset Robotics_Hazards
python utils/scripts/inference.py --dataset Cobots_SyntheticCheck Machine Specific configuration setup here
Check Model Trainings here
Check model checkpoints here
Check inference here
Got errors? check Troubleshooting Guides here
- Base Repository: https://github.com/rashidrao-pk/advis_distrimuse_unito
- DistriMuSe Dataset: https://zenodo.org/records/18742241
- Synthetic Dataset Generator: https://github.com/valerialabugr/SimIndus-Dataset
- MVTec AD Dataset: https://www.mvtec.com/company/research/datasets/ad
- v1.0 (Current): Multi-dataset support, model inspection utilities
- Dataset switching: MVtec, Robotics_Hazards, Cobots_Synthetic
- Enhanced configuration management
- Model loader and inspection tools
- Comprehensive documentation
We welcome contributions! Check out our Contributing Guide to get started.
Thank you to all our contributors!