首页
/ HairCLIP项目使用与启动教程

HairCLIP项目使用与启动教程

2026-01-30 04:52:53作者:俞予舒Fleming

1. 项目介绍

HairCLIP是一个开源项目,提供了根据文本和参考图像设计头发的功能。该项目基于PyTorch框架,支持单独或同时编辑发型和发色,输入可以是图像或文本。HairCLIP的目的是通过先进的机器学习技术为用户提供一个简单易用的头发编辑工具。

2. 项目快速启动

环境准备

首先,确保安装了以下依赖项:

conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0
pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git
pip install tensorflow-io

预训练模型下载

从以下链接下载预训练的HairCLIP模型,并保存在pretrained_models目录下。

  • HairCLIP: 完整的架构,包括mapper和decoder权重。

训练

训练脚本位于scripts/train.py。以下是一个基本的训练命令示例:

cd mapper
python scripts/train.py \
--exp_dir=/path/to/experiment \
--hairstyle_description="hairstyle_list.txt" \
--color_description="purple, red, orange, yellow, green, blue, gray, brown, black, white, blond, pink" \
--latents_train_path=/path/to/train_faces.pt \
--latents_test_path=/path/to/test_faces.pt \
--hairstyle_ref_img_train_path=/path/to/celeba_hq_train \
--color_ref_img_train_path=/path/to/celeba_hq_train \
--color_ref_img_in_domain_path=/path/to/generated_hair_of_various_colors \
--hairstyle_manipulation_prob=0.5 \
--color_manipulation_prob=0.2 \
--both_manipulation_prob=0.27 \
--hairstyle_text_manipulation_prob=0.5 \
--color_text_manipulation_prob=0.5 \
--color_in_domain_ref_manipulation_prob=0.25

推断

推断脚本位于scripts/inference.py。以下是一个使用文本编辑发型的推断命令示例:

cd mapper
python scripts/inference.py \
--exp_dir=/path/to/experiment \
--checkpoint_path=../pretrained_models/hairclip.pt \
--latents_test_path=/path/to/test_faces.pt \
--editing_type=hairstyle \
--input_type=text \
--hairstyle_description="hairstyle_list.txt"

3. 应用案例和最佳实践

  • 发型编辑:通过提供文本描述,用户可以编辑图像中的发型。
  • 发色编辑:用户可以使用参考图像来改变图像中的发色。
  • 综合编辑:用户可以同时编辑发型和发色。

最佳实践是先使用预训练模型进行推断,然后根据需要调整模型配置和训练参数以获得更好的效果。

4. 典型生态项目

目前,HairCLIP的生态项目包括但不限于:

  • HairCLIPv2:改进版本,支持更多的交互模式。
  • StyleCLIP:基于StyleGAN和CLIP的开源项目,用于编辑图像样式。

这些项目都是基于头发编辑和图像处理的开源尝试,共同推进了该领域的技术发展。

登录后查看全文
热门项目推荐
相关项目推荐