This repository is the official implementation of What to Preserve and What to Transfer: Faithful, Identity-Preserving Diffusion-based Hairstyle Transfer. Note that this repository only includes the inference codes.
Install PyTorch and other dependencies:
conda create -y -n hairfusion python=3.8
conda activate hairfusion
pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 --index-url https://download.pytorch.org/whl/cu117
pip install einops
pip install pytorch-lightning==1.5.0
pip install opencv-python==4.7.0.72
pip install matplotlib
pip install omegaconf
pip install albumentations
pip install transformers==4.33.2
pip install xformers==0.0.19
pip install triton==2.0.0
pip install open-clip-torch==2.19.0
pip install clean-fid==0.1.35
pip install diffusers==0.20.2
pip install scipy==1.10.1
conda install -c anaconda ipython -y
sample data in ./data/test
Preprocess a given image and save the outputs in ./data/${dir_name}
- Download face_segment16.pth (50.8MB) and shape_predictor_68_face_landmarks.dat (95.1MB) into ./models
- run
CUDA_VISIBLE_DEVICES=0 python preprocess.py --img_path ${image_path} --save_dir_name ${dir_name} --crop_scale ${crop_scale}
Extract DensePose of the images in ./data/${dir_name}/images and save them in ./data/${dir_name}/images-densepose
- Installation
git clone https://github.com/facebookresearch/detectron2.git pip install opencv-python torchgeometry Pillow tqdm tensorboardX scikit-image scipy cd detectron2 pip install -e . cd projects/DensePose pip install -e .
- run in ./detectron2/projects/DensePose:
Please check the 'detectron2' repository for details.
CUDA_VISIBLE_DEVICES=0 python apply_net.py get configs/densepose_rcnn_R_50_FPN_s1x.yaml https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_s1x/165712039/model_final_162be9.pkl ../../../data/${dir_name}/images --output ../../../data/${dir_name}/images-densepose -v
- run:
CUDA_VISIBLE_DEVICES=0 python make_agnostic.py --dir_name ${dir_name} --dil_size ${hair_dilation_size}
Save a text file of test pairs as ./data/${dir_name}/test_pairs.txt
python make_test_pairs.py --dir_path ./data/${dir_name}- VAE model:
- download 'realisticVisionV51_v51VAE.ckpt' (3.97G) from https://civitai.com/models/4201?modelVersionId=130072 and save it into ./models
- HairFusion:
- download and unzip 'hairfusion.zip' (8.4G) and save it into ./logs
bash ./scripts/test.sh
If you find our work useful for your research, please cite us:
@inproceedings{chung2025hairfusion,
title={What to Preserve and What to Transfer: Faithful, Identity-Preserving Diffusion-based Hairstyle Transfer},
author={Chung, Chaeyeon and Park, Sunghyun and Kim, Jeongho and Choo, Jaegul},
booktitle={The Association for the Advancement of Artificial Intelligence},
year={2025}
}
Licensed under the CC BY-NC-SA 4.0 license https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode.

