Official implementation of "Domain Generalizable Portrait Style Transfer" (Acceped to ICCV 2025)
Set up the python environment
conda create -n dgpst python=3.8
conda activate dgpst
pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txtDownload pretrained CLIP image encoder and IP-Adapter models from here and put the models folder in ./ip_adapter/.
Download our pre-trained models from Google drive and place all the files in ./checkpoints/CelebA_default.
Additionally, we provide another pre-trained model that demonstrates stronger stylization effects. Download it from this link.
The datasets used in our paper include CelebAMask-HQ, AAHQ, FS2K, APDrawing and images from DualStyleGAN.
Please download CelebAMask-HQ dataset. Run g_mask.py to aggregate the 19 categories and obtain a new mask folder for CelebA. Please set the dataroot path as the CelebA image path and dataroot2 path to the mask path in ./experiments/CelebA_launcher.py, and run
python -m experiments CelebA train CelebA_trainFor training, please replace CelebA_default in line 145 and 146 of ./models/DGPST_model.py with CelebA_train.
To train the semantic adapter, please specify the parameter --training_stage in ./models/DGPST_model/ as 1.
To train the ControlNet and style adapter, please set that as 2.
If your network cannot access Hugging Face, please add
HF_ENDPOINT=https://hf-mirror.combefore the training and following testing commands.
To perform style transfer between two given images using the pretrained model in ./checkpoints/CelebA_default/, you can run
CUDA_VISIBLE_DEVICES=0 --nproc_per_node=1 --master_port='29501' test.py \
--name CelebA_default \
--evaluation_metrics seed_swapping \
--preprocess scale_shortside \
--load_size 512 \
--model DGPST \
--input_structure_image /path/to/your/content/image \
--input_texture_image /path/to/your/style/imageIf the result is not satisfactory, you can add a argument --auto_mask True to further refine the semantic correspondence using portrait masks generated by a Segformer model. In addition, you can also use your own masks by adding
--input_structure_mask /path/to/your/content/mask \
--input_texture_mask /path/to/your/style/maskafter the testing command.
For different inputs, please try adjusting the controlnet_conditioning_scale parameter in line 329 of ./models/DGPST_model.py. Additionally, consider replacing pil_image=real_B_w with pil_image=real_B_img in the same line to better transfer reference styles for cross-domain style transfer scenarios.
To perform style transfer between a folder of content images and a folder of style images, you can place both folders under the same parent directory and then specify the dataroot path in test_options of ./experiments/CelebA_launcher.py as this parent folder, and change the dataname as desired to set a name for this experiment. After that, run
python -m experiments CelebA test swapping_gridIf you find our work helpful for your research, please consider citing our paper.
@article{wang2025domain,
title={Domain generalizable portrait style transfer},
author={Wang, Xinbo and Xu, Wenju and Zhang, Qing and Zheng, Wei-Shi},
journal={arXiv preprint arXiv:2507.04243},
year={2025}
}We thank the great work swapping-autoencoder, IP-Adapter and dift.