AL-CycleGAN

April 16, 2026 · View on GitHub

PyTorch code for When Textures Deceive: Weakly Supervised Industrial Anomaly Detection with Adapted-Loss (CVPR 2025 Workshop on Visual Anomaly and Novelty Detection, VAND).

License: MIT

Paper: OpenAccess PDF

Abstract

Industrial anomaly detection often degrades on heavily textured surfaces. This work builds on CycleGAN-style unsupervised domain mapping and replaces the standard GAN objective with an adapted loss: training begins with the usual least-squares (L2) form, then switches to a higher-order power loss on discriminator outputs so the model stays useful for translation while becoming more sensitive to subtle defects. On the proposed MCBT benchmark, the paper reports anomaly localization improving from 89.0% to 92.9% with AL-CycleGAN, alongside strong I-AUROC / P-AUROC on MCBT and MVTec-AD texture categories; see the tables below and the paper for protocols and baselines.

What this repository contains

  • train.py — training loop with a fixed schedule (power_switch_epoch, default 50) that turns on the adapted loss after warm-up.
  • models/networks.pyGANLoss: for LSGAN/vanilla modes, squared error when switch is off, and 8th-power error ((prediction - target)^8) when switch is on (see GANLoss.__call__).
  • models/cycle_gan_model.py — CycleGAN with discriminator outputs upsampled for visualization and optional utilities for saving alpha/beta maps and loss traces (anomaly_detection, loss_analysis, etc.).
  • test.py — standard CycleGAN testing and HTML export of results.

The codebase extends pytorch-CycleGAN-and-pix2pix.

Installation

git clone https://github.com/ganatma/AL-CycleGAN.git
cd AL-CycleGAN

# Example: conda (see also environment.yml)
conda create -n al-cyclegan python=3.8 -y
conda activate al-cyclegan
conda install pytorch torchvision -c pytorch   # match CUDA for your machine
pip install -r requirements.txt

Alternatively, create the conda environment from the pinned file (name al-cyclegan, matches environment.yml):

conda env create -f environment.yml
conda activate al-cyclegan
  • Visdom (optional, for live curves and panels): python -m visdom.server then open the URL printed in the terminal (default display port in this code is 8098; override with --display_port).
  • Weights & Biases: pass --use_wandb (and optionally --wandb_project_name) when running train.py / test.py.

MCBT dataset

Manufacturing Complex Background Texture (MCBT) is the benchmark used in the paper. In this repository the images live in the MCBT/ directory at the project root. --dataroot defaults to ./MCBT in options/base_options.py, so you can omit it when working from this layout.

  • Size: 1,027 real-world images — 800 anomaly-free and 227 defective — with diverse defects and backgrounds.
  • Layout: Unaligned CycleGAN layout (trainA, trainB, testA, testB, etc.).

Data layout

Use --dataset_mode unaligned (default) with a root folder that contains the usual CycleGAN splits, for example trainA, trainB, testA, testB (and validation folders if you use them). By default, point --dataroot at ./MCBT or override with another path.

Training

python train.py --name my_experiment --model cycle_gan
# equivalent to --dataroot ./MCBT
python train.py --dataroot ./MCBT --name my_experiment --model cycle_gan

Intermediate web results are written under ./checkpoints/<name>/web/ (unless --no_html). The power switch (L2 GAN loss → 8th-power loss) is controlled by power_switch_epoch in train.py (default 50). The paper’s Table 3 ablation on MCBT reports the highest P-AUROC when the switch occurs at epoch 175 ((t^*) in the paper)—change power_switch_epoch in train.py if you want to reproduce that setting; the default 50 is a fixed schedule used in this codebase.

Convenience scripts (default experiment name mcbt_cyclegan; edit the script to change --name or other flags):

bash ./scripts/train_mcbt.sh

Example script from the upstream CycleGAN repo (uses ./datasets/maps): ./scripts/train_cyclegan.sh.

Testing

python test.py --name my_experiment --model cycle_gan
# equivalent to --dataroot ./MCBT

Outputs go under ./results/<name>/ (see --results_dir). Use --epoch <N> or latest (default) to select a checkpoint from ./checkpoints/<name>/.

bash ./scripts/test_mcbt.sh

Uses the same default --name mcbt_cyclegan as train_mcbt.sh; edit the script if your checkpoint folder uses a different name.

Pre-trained checkpoints

Place downloaded weights under ./checkpoints/<experiment_name>/ so they match the --name you pass to test.py. The repository does not ship large checkpoints; use your own or releases linked from the project when available.

Key results — MCBT (from the paper, Table 1)

Image-level AUROC (I-AUROC) and pixel-level AUROC (P-AUROC) on MCBT. Best per column in bold (see the paper for highlighting rules and std. dev. for AL-CycleGAN).

MethodI-AUROCP-AUROC
EfficientAD0.9780.892
DRAEM0.5000.500
SimpleNet0.8480.896
Mixed Supervision0.9970.488 ± 0.047
GFT0.781
AL-CycleGAN (ours)1.0000.929 ± 0.071

CAVGA-R / CAVGA-Rw are not reported on MCBT in the paper. DRAEM’s 0.5 / 0.5 on MCBT reflects poor generalization to this texture regime compared to MVTec-AD. The paper also reports efficiency on MCBT (e.g., training time for 200 epochs, inference FPS) in Section 5.2.3.

Key results — MVTec-AD texture categories (from the paper)

Pixel-level / image-level metrics (see paper for protocol). Bold = best; ± = std. dev. for AL-CycleGAN where reported.

CategoryInTraSimpleNetGFTAL-CycleGAN (ours)
Tile0.982/0.9440.998/0.970-/0.9351.0/0.952±0.064
Wood0.975/0.8871.0/0.945-/0.9081.0/0.929±0.088
Grid1.0/0.9880.997/0.988-/0.93180.966/0.788±0.196
Leather1.0/0.9951.0/0.992-/0.9841.0/0.995±0.005
Carpet0.988/0.9920.997/0.982-/0.9320.957/0.973±0.063

Qualitative comparisons for MVTec-AD and MCBT are in the paper (Figure 5).

Acknowledgments

Code builds on pytorch-CycleGAN-and-pix2pix and related PyTorch examples.

References

  1. Nakkina et al., When Textures Deceive: Weakly Supervised Industrial Anomaly Detection with Adapted-Loss, CVPR 2025 W (VAND). PDF
  2. Zhu et al., Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks (CycleGAN). arXiv:1703.10593
  3. Liu et al., SimpleNet. arXiv:2301.04632

License

MIT. See LICENSE.