• Version: 20261019
  • Source Code Copyright: MIT License — wtjiang98/PSGAN
  • 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 makeup transfer with PSGAN (PyTorch) for Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon): applies the makeup style of a reference face photo to a non-makeup source face (dlib landmarks + GAN transfer + color-matching postprocess). A trained generator ships with the project, so inference works out of the box. Training and inference run on the GPU (CUDA on Windows/Linux, MPS on Apple Silicon) and fall back to the CPU automatically (inference there takes about half a minute per reference; training is impractically slow). Based on wtjiang98/PSGAN.

 

[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, PyYAML, fvcore, matplotlib, requests, prebuilt dlib-bin — no compiler needed, torchgpipe).
  • 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. On Linux/macOS, source it: source src/03_venv_activate.sh. 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_train.bat / 04_train.sh

Train PSGAN (starts from the shipped generator; outputs to model/train/ — the shipped model/G.pth is never overwritten).

 

5. 05_inference.bat / 05_inference.sh

Makeup transfer with the shipped model (results to model/output/).

 

6. 99_venv_clean.bat / 99_venv_clean.sh

Delete the venv folder.

 

7. 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\05_inference.bat --device cpu.

[Python Entry Points]

src/inference.py

[--source data/test/non-makeup/xfsy_0106.png] [--reference-dir data/test/makeup/] [--model model/G.pth] [--device auto|cuda|cuda:N|mps|cpu] [--config data/base.yaml]. Saves model/output/transferred_{reference}.png per reference.

 

src/train.py

[--config data/base.yaml] [--device auto|cuda|cuda:N|mps|cpu]. Batch size 1, image size 256, 50 epochs of 2709 iterations; starts from model/G.pth; snapshots, loss plots and preview images go to model/train/ — the shipped model/G.pth is never overwritten. About 1.5 s per iteration on an NVIDIA Quadro RTX 5000.

 

--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device. The selected device is printed at startup.

[Quick Start]

Windows 11

src\01_python_install_windows.bat

src\02_venv_create_windows.bat

src\05_inference.bat

src\04_train.bat

 

Ubuntu 24.04

bash src/01_python_install_linux.sh

bash src/02_venv_create_linux.sh

bash src/05_inference.sh

bash src/04_train.sh

 

macOS 14+ (Apple Silicon)

bash src/01_python_install_mac.sh

bash src/02_venv_create_mac.sh

bash src/05_inference.sh

bash src/04_train.sh

Open a new terminal after 01_python_install_windows.bat before running 02_venv_create_windows.bat. Training realistically wants a GPU.

[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 face parser and the GAN 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).
  • dlib face detection / landmarks always run on the CPU (dlib-bin has no GPU backend), as do the histogram-matching loss and the training data loading.
  • Without a usable GPU everything runs on the CPU. Checkpoints load on any device.

[Notes]

  • Everything runs offline: the dlib 68-landmark model, the face-parser weights and the VGG16 weights ship with the project.
  • Use reasonably frontal face photos: dlib must detect a face in the source and in every reference image.

 

This SDK is built in AppForAI - AI Dev Tools.