TL;DR
HairFastGAN is a novel framework that achieves high-fidelity hairstyle transfer in under a second. By operating in StyleGAN’s structural FS latent space and utilizing a unique "Rotate Encoder" for pose alignment, it matches the quality of slow, optimization-heavy methods while running at near real-time speeds.
The Challenge of Virtual Hair Try-On
Virtual hair try-on—the process of transferring a hairstyle from a reference "shape" image and a "color" image to a target face—is notoriously difficult. Historically, researchers have faced a frustrating trade-off between speed and quality:
- Optimization-based methods (like Barbershop) produce stunning, highly realistic results but are computationally expensive. They often take 10 minutes or more to process a single image because they must solve complex equations for every pixel.
- Encoder-based methods (like HairCLIP) are fast, often running in sub-second times, but frequently yield blurry or artificial-looking results. They typically operate in StyleGAN’s lower-dimensional $W+$ latent space, which lacks the resolution to capture fine hair textures.
Furthermore, both approaches struggle when the person in the reference photo is facing a different direction than the target. If the poses do not match, the transferred hair often looks misaligned or unnatural.
How HairFastGAN Works
The authors bridge this gap by moving away from the $W+$ space and into the FS latent space, where $F$ represents structural features and $S$ represents global style. Their pipeline, HairFastGAN, consists of four specialized modules:
- Pose Alignment (The Rotate Encoder): Instead of attempting to warp the image directly, the authors developed a "Rotate Encoder" that operates on the latent code. It rotates the reference hair in latent space to match the target's pose before the transfer begins, preventing structural artifacts.
- Shape Alignment: This module uses a pre-trained SEAN (Semantic Region-Adaptive Normalization) model for inpainting. It ensures that when a voluminous hairstyle is replaced by a shorter one, the newly revealed background and forehead look natural.
- Color Alignment: Rather than simply blending colors, the model uses CLIP embeddings to extract semantic color information. This allows it to transfer the specific hue and "vibe" of the hair without accidentally altering the person's skin tone or eye color.
- Refinement Alignment: As the final step, this module restores fine details—such as makeup, earrings, and background textures—that are often lost during the initial GAN inversion process.
Datasets and Evaluation
The model was trained and evaluated using two standard datasets in facial synthesis:
- FFHQ (Flickr-Faces-HQ): Used for training the Rotate, Color, and Refinement encoders.
- CelebA-HQ: Used for extensive benchmarking against existing state-of-the-art models.
To rigorously test the framework, the authors also created a custom evaluation setup by selecting 1,000 to 3,000 random triples (Face, Shape, Color) to simulate the most difficult transfer scenarios.
Key Insights
- Latent Rotation is Key: The Rotate Encoder is a crucial innovation. By fixing the pose mismatch in the latent space early on, the model avoids the structural artifacts that plague other fast methods.
- FS Space is the Sweet Spot: The paper demonstrates that $F$ tensors (structural) are essential for hair texture, while $S$ (style) is better for color. Mixing these specifically for hair allows for high-resolution results without the computational cost of full-image optimization.
- CLIP for Color Consistency: Using CLIP as a loss function helps the model understand "hair color" conceptually, preventing the color bleeding onto the face that often occurs in simpler GAN architectures.
Results: Speed, Quality, and Robustness
- Speed: HairFastGAN processes a transfer in just 0.78 seconds on an Nvidia V100 GPU. For comparison, the high-quality Barbershop model takes 645 seconds (over 10 minutes).
- Quality: In terms of Fréchet Inception Distance (FID)—a standard metric for image realism—HairFastGAN scored 13.12, significantly outperforming Barbershop (15.94) and HairCLIP (34.95).
- Robustness: Qualitative results show the model successfully handles extreme 90-degree head rotations and preserves fine details like facial piercings and complex backgrounds that previous models typically erased.
Limitations and Future Work
While HairFastGAN represents a major step forward, the authors acknowledge a few remaining challenges. When replacing very long hair with a very short cut, the model occasionally struggles to perfectly reconstruct the newly exposed skin or background via inpainting. Additionally, intricate styles like tight braids, ribbons, or complex ponytails can still result in some blurring or loss of structural detail.
Looking ahead, the team suggests that the architecture could be adapted to allow for text-based editing (e.g., "make the hair more curly") using the same fast encoder-based logic.
Reference: Nikolaev, M., et al. (2024). HairFastGAN: Realistic and Robust Hair Transfer with a Fast Encoder-Based Approach. NeurIPS 2024.
Summary updated