- Version: 20261019
- Source Code Copyright: MIT License — samet-akcay/ganomaly
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Console/terminal demo of anomaly detection with GANomaly (PyTorch) for Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon): digit 0 is normal, other digits are anomalies. Trained weights ship with the project, so scoring works out of the box (full-test-set AUC 0.998); training has optional live visdom curves on port 8801. Training and scoring run on the GPU (CUDA on Windows/Linux, MPS on Apple Silicon) and fall back to the CPU automatically. Based on samet-akcay/ganomaly (MIT).
[Prerequisites]
- Python 3.14, installed by src\01_python_install_windows.bat (winget), src/01_python_install_linux.sh (apt, deadsnakes PPA when needed; uses sudo) or src/01_python_install_mac.sh (Homebrew).
- The venv scripts install PyTorch 2.13.0 + torchvision 0.28.0 first, then src/requirements.txt (numpy, opencv-python, Pillow, matplotlib, scikit-learn, scipy, tqdm, visdom).
- Windows / Linux: the CUDA 13.0 (cu130) build. GPU use needs an NVIDIA Turing or newer GPU (GTX 16 / RTX 20 series and later) with a driver supporting CUDA 13.0 or newer (check nvidia-smi); without one the same build runs on the CPU.
- macOS: the PyPI build, using the Apple GPU through MPS. Apple Silicon (arm64) with macOS 14+ only; Intel Macs are not supported by PyTorch 2.13.0.
[Launcher Scripts]
1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh
Install Python 3.14 (winget / apt + deadsnakes / Homebrew). Skips when it is already installed.
2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh
Delete the old venv/, create a fresh one with Python 3.14, install PyTorch 2.13.0 + torchvision 0.28.0 (CUDA 13.0 build on Windows/Linux, PyPI/MPS build on macOS), then src/requirements.txt. Aborts loudly if pip fails; prints whether CUDA (or MPS) is available.
3. 03_venv_activate.bat / 03_venv_activate.sh
Activate the venv (source it on Linux/macOS). If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.
4. 04_visdom.bat / 04_visdom.sh
Start the visdom server on port 8801 (optional live curves).
5. 05_train.bat / 05_train.sh
Train GANomaly (outputs to model/train/; add --display for curves).
6. 06_find_threshold.bat / 06_find_threshold.sh
Score the test set; prints AUC + suggested threshold.
7. 07_inference.bat / 07_inference.sh
Score one image against the anomaly threshold.
8. 99_venv_clean.bat / 99_venv_clean.sh
Delete the venv folder.
9. 99_venv_deactivate.bat / 99_venv_deactivate.sh
Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).
Extra arguments are forwarded to the Python entry point, e.g. src\07_inference.bat --device cpu.
[Python Entry Points]
src/train.py
[--dataset mnist_1/] [--isize 32] [--niter 20] [--batchsize 64] [--nz 100] [--lr 0.0002] [--device auto] [--workers 0] [--outf model/train] [--display]. The shipped model/ganomaly is never overwritten.
src/find_threshold.py
[--dataset mnist_1/] [--outf model] [--device auto] [--workers 0]. Prints ROC AUC and the suggested threshold.
src/inference.py
[--image data/mnist_1/predict/2.png] [--an-threshold 0.2] [--outf model] [--device auto]. Prints the anomaly score and verdict.
--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device (the old value gpu means auto). The selected device is printed at startup. --workers (default 0) sets the DataLoader worker processes; every spawned worker re-imports torch (about 1.4 GB of memory each with the CUDA build on Windows), so raise it only on machines with plenty of memory.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
src\02_venv_create_windows.bat
src\07_inference.bat
src\06_find_threshold.bat
src\05_train.bat
Ubuntu 24.04
bash src/01_python_install_linux.sh
bash src/02_venv_create_linux.sh
bash src/07_inference.sh
bash src/06_find_threshold.sh
bash src/05_train.sh
macOS 14+ (Apple Silicon)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/07_inference.sh
bash src/06_find_threshold.sh
bash src/05_train.sh
[GPU]
- Device order: CUDA → MPS → CPU, overridable with --device.
- Windows / Linux: the venv scripts install the CUDA 13.0 (cu130) build directly. It needs a Turing-or-newer NVIDIA GPU and a driver supporting CUDA 13.0+. Pascal/Volta GPUs (GTX 10xx, V100) are not supported by cu130; on those, reinstall torch from the cu126 index inside the venv: pip install torch==2.13.0 torchvision==0.28.0 --index-url https://download.pytorch.org/whl/cu126 --force-reinstall
- macOS (Apple Silicon): the networks run on the Apple GPU through MPS; ops MPS lacks fall back to the CPU (PYTORCH_ENABLE_MPS_FALLBACK=1 is set by the entry scripts).
- Without a usable GPU everything runs on the CPU (scoring is fast; training is slow). The weights load on any device.
[Notes]
- With the shipped weights: full-test-set AUC 0.998, suggested threshold ~0.244 (the notebooks used 0.2).
- The predict/ images are demo inputs numbered 0-9 (names are not digit labels).
- For your own data, mirror data/{name}/train/0.normal + test/0.normal + test/1.abnormal and pass --dataset {name}/.
This SDK is built in AppForAI - AI Dev Tools.