MTAD: Multi-Scale Anomaly Classification and Segmentation Method for CVPR2026 VAND4.0 Workshop Challenge Track 1
This repository implements a three-stage pipeline for industrial anomaly detection and segmentation. The current main entrypoints are:
run1_splitter.py: split original high-resolution images into multi-scale patches.run2_model.py: train the model, run evaluation, and export anomaly heatmaps.run3_post.py: post-process heatmaps to generate final masks and visualizations.
.
├── run1_splitter.py
├── run2_model.py
├── run3_post.py
├── run.sh
├── models/
├── pre_process/
├── post_process/
├── utils/
├── optimizers/
├── dinov3/
└── requirements.txt
Directory responsibilities:
models/: main model definitions, ViT encoders, and network modules.pre_process/: dataset loading, augmentation, path resolution, and patch-related preprocessing.post_process/: post-processing, SAM2 refinement, and mask generation.utils/: evaluation, export, visualization, and shared utilities.dinov3/: DINOv3-related backbone code.
conda create -n msad python=3.8.12
conda activate msad
pip install -r requirements.txtThe current workflow consists of three steps.
Split the original dataset into multi-scale patches:
python run1_splitter.py --input_dir /dataset/VAND4/mvtec_ad_2 --output_dir /dataset/VAND4/mvtec_ad_2_aug_aptRuns are category-specific. Common phases are train, test, and val:
python run2_model.py --item_list fabric --phase train --data_path /dataset/VAND4/mvtec_ad_2_aug_apt --device cuda:0
python run2_model.py --item_list fabric --phase val --data_path /dataset/VAND4/mvtec_ad_2_aug_apt --device cuda:0 --output_dir ./results/anomaly_imagesNotes:
train: train the model and save checkpoints.test: evaluate using an existing checkpoint.val: export original-image-level anomaly heatmaps for post-processing.
Generate final segmentation masks from original images and anomaly heatmaps:
python run3_post.py --image-dir /dataset/VAND4/mvtec_ad_2 --heatmap-dir ./results/anomaly_images --output-dir ./results/test_result --mask-dir ./results/anomaly_images_thresholded --device cuda:0If you want to run the predefined batch pipeline, use:
bash run.shIt executes the following stages in order:
run1_splitter.pyrun2_model.pytraining andvalrun3_post.py
saved_results/: training checkpoints and logs.results/anomaly_images/: heatmaps exported by thevalphase.results/anomaly_images_thresholded/: binary masks after post-processing.results/test_result/: visualization results and summary tables.