Skip to content

yyyangcoder/MSAD

Repository files navigation

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:

  1. run1_splitter.py: split original high-resolution images into multi-scale patches.
  2. run2_model.py: train the model, run evaluation, and export anomaly heatmaps.
  3. run3_post.py: post-process heatmaps to generate final masks and visualizations.

Current Directory Structure

.
├── 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.

Environment Setup

conda create -n msad python=3.8.12
conda activate msad
pip install -r requirements.txt

Data and Pipeline

The current workflow consists of three steps.

1. Data Splitting

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_apt

2. Model Training / Testing / Heatmap Export

Runs 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_images

Notes:

  • train: train the model and save checkpoints.
  • test: evaluate using an existing checkpoint.
  • val: export original-image-level anomaly heatmaps for post-processing.

3. 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:0

One-Click Script

If you want to run the predefined batch pipeline, use:

bash run.sh

It executes the following stages in order:

  1. run1_splitter.py
  2. run2_model.py training and val
  3. run3_post.py

Common Output Directories

  • saved_results/: training checkpoints and logs.
  • results/anomaly_images/: heatmaps exported by the val phase.
  • results/anomaly_images_thresholded/: binary masks after post-processing.
  • results/test_result/: visualization results and summary tables.

About

MTAD: Multi-Scale Anomaly Classification and Segmentation Method for CVPR2026 VAND4.0 Workshop Challenge Track 1

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors