HairFastGan: A Virtual Hairstyle Try-On Framework for Near-Real-Time Hair Transfer
What is HairFastGAN?
HairFastGAN is a virtual hairstyle try-on framework that enables near real-time hairstyle transfer at high resolution. It operates in StyleGAN's FS latent space, combined with an enhanced inpainting method and improved encoder, solving the problems of hairstyle alignment, color transfer, and detail restoration under complex poses. It performs particularly well in scenarios with complex hairstyles and significant pose differences.
Core Features of HairFastGAN
Efficiency: Compared with traditional optimization-based hairstyle transfer methods, HairFastGAN adopts an encoder architecture that achieves near real-time performance while ensuring high-resolution output. In the most complex scenarios involving hairstyle shape and color transfer, the method runs in less than one second on an Nvidia V100 GPU.
High-Quality Reconstruction: By operating in StyleGAN's FS latent space, employing an enhanced inpainting method, and using an improved encoder, the HairFastGAN framework achieves better alignment, color transfer, and post-processing, delivering outstanding performance in both random hairstyle transfer and original hairstyle reconstruction.
Pose Adaptability: Traditional hairstyle transfer methods perform poorly when there is a significant difference between the source and target poses, whereas HairFastGAN effectively handles this difference by taking pose information into account.

HairFastGAN Method
Embedding: Embed both the input image and reference image into StyleGAN's FS latent space while obtaining segmentation masks.
Alignment: Transfer the hairstyle shape from the reference image onto the target image through a shape module.
Blending: Transfer the hair color from the reference image onto the target image by editing the S space of the source image.
Post-Processing: Restore the details lost in the original image, ensuring preservation of facial identity and realism of the result.

HairFastGAN Application Scenarios
Hairdressing Industry: Virtual hairstyle try-on helps clients quickly preview different hairstyle effects, enhancing the hairdressing design experience.
Fashion and Beauty: Used in fashion magazines, advertising design, and personal image design to quickly generate multiple hairstyle options.
Entertainment and Gaming: Customize character hairstyles in games, or use as a real-time filter on social media.
Medical Rehabilitation: Help hair transplant patients preview post-surgery results, or provide psychological rehabilitation assistance for patients with hair loss.
How to Use HairFastGAN
1. Install Dependencies
First, make sure your environment has Python and the necessary dependency libraries installed. You can install them with the following commands:
pip install torch torchvision pip install git+https://github.com/NVlabs/stylegan2-ada-pytorch.git
2. Clone the Project Code
Clone the HairFastGAN code from GitHub:
git clone https://github.com/AIRI-Institute/HairFastGAN.git cd HairFastGAN
3. Download Pre-trained Models
Download the pre-trained model files from Hugging Face or the link provided by the project, and place them in the specified directory (e.g., models/).
4. Prepare Input Images
Input photo: A high-definition photo containing a face.
Reference photo: A reference photo containing the target hairstyle.
Make sure the resolution and format of the input photo and reference photo meet the requirements.

5. Run the Code
Run the following command to perform hairstyle transfer:
python run.py --input <input_image_path> --ref <reference_image_path> --model <model_path>
<input_image_path>: The path to the input photo.
<reference_image_path>: The path to the reference photo.
<model_path>: The path to the pre-trained model.
6. View the Results
Once the run is complete, the generated hairstyle transfer result will be saved to the specified output directory (e.g., output/).
Related Links
GitHub Repository:https://github.com/AIRI-Institute/HairFastGAN
Project Page:https://airi-institute.github.io/HairFastGAN/
Try it Out:https://huggingface.co/spaces/AIRI-Institute/HairFastGAN
Hugging Face Model:https://huggingface.co/AIRI-Institute/HairFastGAN
Paper:https://arxiv.org/abs/2404.01094
Script Planner Assistant▸
AI Apps
AI News 