HairCLIP: Design Your Hair by Text and Reference Image

Overview

Overview

This repository hosts the official PyTorch implementation of the paper: "HairCLIP: Design Your Hair by Text and Reference Image".

Our single framework supports hairstyle and hair color editing individually or jointly, and conditional inputs can come from either image or text domain.

Tianyi Wei1, Dongdong Chen2, Wenbo Zhou1, Jing Liao3, Zhentao Tan1, Lu Yuan2, Weiming Zhang1, Nenghai Yu1
1University of Science and Technology of China, 2Microsoft Cloud AI, 3City University of Hong Kong

Abstract

Hair editing is an interesting and challenging problem in computer vision and graphics. Many existing methods require well-drawn sketches or masks as conditional inputs for editing, however these interactions are neither straightforward nor efficient. In order to free users from the tedious interaction process, this paper proposes a new hair editing interaction mode, which enables manipulating hair attributes individually or jointly based on the texts or reference images provided by users. For this purpose, we encode the image and text conditions in a shared embedding space and propose a unified hair editing framework by leveraging the powerful image text representation capability of the Contrastive Language-Image Pre-Training (CLIP) model. With the carefully designed network structures and loss functions, our framework can perform high-quality hair editing in a disentangled manner. Extensive experiments demonstrate the superiority of our approach in terms of manipulation accuracy, visual realism of editing results, and irrelevant attribute preservation.

Comparison

Comparison to Text-Driven Image Manipulation Methods

Comparison to Hair Transfer Methods

Application

Hair Interpolation

Generalization Ability to Unseen Descriptions

Cross-Modal Conditional Inputs

To Do

  • Release testing code
  • Release pretrained model
  • Release training code
Comments
  • Except hair coloe change only, but hair style of some results are change

    Except hair coloe change only, but hair style of some results are change

    I want to change hair color on FFHQ data, however hairstyle of some of results are change. Did I do wrong? The following is my command

    python scripts/inference.py
    --exp_dir=./experiment
    --checkpoint_path=../pretrained_models/hairclip.pt
    --latents_test_path=./latents.pt
    --editing_type=color
    --input_type=text
    --color_description=red

    00001-0000-red hair

    opened by kasim0226 7
  • Demo Play ?

    Demo Play ?

    Hi. 🤗 This is an awesome work. 👍 Thanks for all of you, the contributors. 🌹 I am wondering if you could tell me if you have any plan to make one demo public on huggingface/spaces, etc. 🤔 ?

    opened by ZenMoore 3
  • Can I use my own image test?

    Can I use my own image test?

    Hello, can I use my own image for the resend test, I found that the input was test_face.pt (test data set ?) file, and I did not find the input image content in the code, The only thing that feels like an input image is w(w=torch.Size([1, 18, 512])), But it's not the size of a picture

    opened by liuzhuangyuan 2
  • The generated image is quite different from the reference image

    The generated image is quite different from the reference image

    I tested the effect and found that the hair style of the generated image is quite different from that of the reference image. Here is my test script. The reference image is selected from CelebAMask-HQ dataset. Is there a problem in my test process?

    python scripts/inference.py \ --exp_dir=../outputs/0321/ \ --checkpoint_path=../pretrained_models/hairclip.pt \ --latents_test_path=../pretrained_models/test_faces.pt \ --editing_type=both \ --input_type=image_image \ --color_ref_img_test_path=../input/16 \ --hairstyle_ref_img_test_path=../input/16 --num_of_ref_img 1

    image
    opened by 1273545169 2
  • about pretrained unet infer

    about pretrained unet infer

    mask_512 = (torch.unsqueeze(torch.max(labels_predict, 1)[1], 1)==13).float() 1.why hair equal 13, bg not equal 13? 2.unet infer results that have 19 channels, what did they means?

    opened by eeric 2
  • About the training details.

    About the training details.

    Thank you for your great project!

    In this paper, you said “We train and evaluate our hair mapper on the CelebA-HQ dataset. Since we use e4e [43] as our inversion encoder, we follow its division of the training set and test set.” However, I found that e4e used the FFHQ dataset for training and the CelebA-HQ test dataset for evaluation. Hence, I feel confused. My question is that how to split the training and test datasets on the CelebA-HQ dataset?

    opened by bb12346 2
  • About modulation module

    About modulation module

    Hi, Great work! But I have a question about the modulation module of mapper network. I assume the dimension of x and e should be 1x1xC. If so, what is the mean and std of x? channel-wise average? And how about the output dimensions of fr(e) and fb(e)?

    Thanks.

    opened by janchen0611 2
  • 用两张图片测试的时候报错

    用两张图片测试的时候报错

    输入命令: E:\Linux\XSpace\papers\HairCLIP\mapper>python scripts/inference.py --exp_dir=E:\Linux\XSpace\pap ers\HairCLIP\data\exp --checkpoint_path=F:\Dataset\CelebA\Data\hairclip.pt --latents_test_path=F:\Dataset\CelebA\Data\test_faces.pt --editin g_type=color --input_type=image --hairstyle_description="hairstyle_list.txt" --color_ref_img_test_path=E:\Linux\XSpace\papers\HairCLIP\data
    ref

    在 latent_mappers.py 中的 x = clip_model.encode_image(masked_generated_renormed) 报错了,错误信息如下:

    *** RuntimeError: The following operation failed in the TorchScript interpreter. Traceback of TorchScript, serialized code (most recent call last): File "code/torch/multimodal/model/multimodal_transformer/___torch_mangle_9591.py", line 19, in encode_image _0 = self.visual input = torch.to(image, torch.device("cuda:0"), 5, False, False, None) return (_0).forward(input, ) ~~~~~~~~~~~ <--- HERE def encode_text(self: torch.multimodal.model.multimodal_transformer.___torch_mangle_9591.Multimodal, input: Tensor) -> Tensor: File "code/torch/multimodal/model/multimodal_transformer.py", line 34, in forward x2 = torch.add(x1, torch.to(_4, 5, False, False, None), alpha=1) x3 = torch.permute((_3).forward(x2, ), [1, 0, 2]) x4 = torch.permute((_2).forward(x3, ), [1, 0, 2]) ~~~~~~~~~~~ <--- HERE _15 = torch.slice(x4, 0, 0, 9223372036854775807, 1) x5 = torch.slice(torch.select(_15, 1, 0), 1, 0, 9223372036854775807, 1) File "code/torch/multimodal/model/multimodal_transformer/___torch_mangle_9477.py", line 8, in forward def forward(self: torch.multimodal.model.multimodal_transformer.___torch_mangle_9477.Transformer, x: Tensor) -> Tensor: return (self.resblocks).forward(x, ) ~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE def forward1(self: torch.multimodal.model.multimodal_transformer.___torch_mangle_9477.Transformer, x: Tensor) -> Tensor: File "code/torch/torch/nn/modules/container/___torch_mangle_9476.py", line 29, in forward _8 = getattr(self, "3") _9 = getattr(self, "2") _10 = (getattr(self, "1")).forward((getattr(self, "0")).forward(x, ), ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE _11 = (_7).forward((_8).forward((_9).forward(_10, ), ), ) _12 = (_4).forward((_5).forward((_6).forward(_11, ), ), ) File "code/torch/multimodal/model/multimodal_transformer/___torch_mangle_9376.py", line 13, in forward _0 = self.mlp _1 = self.ln_2 _2 = (self.attn).forward((self.ln_1).forward(x, ), ) ~~~~~~~~~~~~~~~~~~ <--- HERE x0 = torch.add(x, _2, alpha=1) x1 = torch.add(x0, (_0).forward((_1).forward(x0, ), ), alpha=1) File "code/torch/torch/nn/modules/activation/___torch_mangle_9369.py", line 38, in forward _16 = [-1, int(torch.mul(bsz, CONSTANTS.c0)), _8] v0 = torch.transpose(torch.view(_15, _16), 0, 1) attn_output_weights = torch.bmm(q2, torch.transpose(k0, 1, 2)) ~~~~~~~~~ <--- HERE input = torch.softmax(attn_output_weights, -1, None) attn_output_weights0 = torch.dropout(input, 0., True)

    Traceback of TorchScript, original code (most recent call last): /opt/conda/lib/python3.7/site-packages/torch/nn/functional.py(4294): multi_head_attention_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/activation.py(985): forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl /root/workspace/multimodal-pytorch/multimodal/model/multimodal_transformer.py(45): attention /root/workspace/multimodal-pytorch/multimodal/model/multimodal_transformer.py(48): forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl /opt/conda/lib/python3.7/site-packages/torch/nn/modules/container.py(117): forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl /root/workspace/multimodal-pytorch/multimodal/model/multimodal_transformer.py(63): forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl /root/workspace/multimodal-pytorch/multimodal/model/multimodal_transformer.py(93): forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward /opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl /root/workspace/multimodal-pytorch/multimodal/model/multimodal_transformer.py(221): visual_forward /opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py(940): trace_module (36): export_torchscript_models (3): /opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3418): run_code /opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3338): run_ast_nodes /opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3147): run_cell_async /opt/conda/lib/python3.7/site-packages/IPython/core/async_helpers.py(68): _pseudo_sync_runner /opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py(2923): _run_cell /opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py(2878): run_cell /opt/conda/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py(555): interact /opt/conda/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py(564): mainloop /opt/conda/lib/python3.7/site-packages/IPython/terminal/ipapp.py(356): start /opt/conda/lib/python3.7/site-packages/traitlets/config/application.py(845): launch_instance /opt/conda/lib/python3.7/site-packages/IPython/init.py(126): start_ipython /opt/conda/bin/ipython(8): RuntimeError: cublas runtime error : unknown error at C:/cb/pytorch_1000000000000/work/aten/src/THC/THCBlas.cu:225 (Pdb) img_tensor.shape torch.Size([1, 3, 1024, 1024])

    请问是输入的tensor大小不对吗

    opened by hello-lx 1
  • Is is normal speed?

    Is is normal speed?

    微信截图_20220412182041 Hello, I want to ask if the speed of run the inferrence.py for testing is normal. This is my executive code: cd mapper python scripts/inference.py
    --exp_dir=/home/ps/HairCLIP/mapper/path/to/experiment
    --checkpoint_path=/home/ps/HairCLIP/pretrained_models/hairclip.pt
    --latents_test_path=/home/ps/HairCLIP/mapper/path/to/test_faces.pt
    --editing_type=hairstyle
    --input_type=text
    --hairstyle_description="/home/ps/HairCLIP/mapper/hairstyle_list.txt" \

    opened by sunhaha123 1
  • Hairstyles can only show so much

    Hairstyles can only show so much

    First of all , thanks for you excellent work! There are many hairstyles in hairstyle.txt, but actually I found only a few styles in result images after trying all styles. More or less repeat the following images.

    • cornrows cut hairstyle image

    • crew cut hairstyle image (the points on left glasses in right image is mouse)

    the following is my command:

    python scripts/inference.py 
    --exp_dir=../result/test_1/
    --checkpoint_path=../pretrained_models/hairclip.pt
    --latents_test_path=../inference_data/test_1/latent.pt
    --editing_type=hairstyle
    --input_type=text
    --hairstyle_description="hairstyle_list.txt"
    

    What's the problem? Should I train with my own dataset?

    I list some hairstyles which have the same effect:

      1. the same as cornrows: crown braid hairstyle, dreadlocks hairstyle, finger waves hairstyle, french braid hairstyle and so on.
      1. the same as crew cut hairstyle: caesar cut hairstyle, dido flip hairstyle, extensions hairstyle, fade hairstyle, fauxhawk hairstyle, frosted tops hairstyle ,full crown hairstyle, harvard clip hairstyle, high and tigh hairstyle, hime cut hairstyle, hi-top fade hairstyle and so son.
    opened by ZziTaiLeo 1
  • Hosting HairCLIP model

    Hosting HairCLIP model

    Hi!

    First off, thank you for your work!

    I'm trying to create a Colab Notebook to play with your model, but since the weights and stuff are hosted inside google drive, the download limits seems to restrict me from simply downloading it with gdown or wget.

    Could I download it and move it to another hosting service (i.e archive.org) to avoid this issue? Of course, I would add all the references to all the authors and parties involved.

    Again, thanks for your work!

    opened by ouhenio 1
  • F and C

    F and C

    Hello, boss. I noticed that the neural network structure diagram may be incorrectly drawn in the paper. F should be fine, meaning high-level semantic information; C should be coarse, meaning low-level semantic information.

    opened by 123456klk1 0
  • question of split database(train.pt and test.pt)

    question of split database(train.pt and test.pt)

    @wty-ustc Thank you for the amazing work! I try to split the CelebA-HQ by official list_eval_partition.txt. Eventually, I got 24183/2993/2824 images for training/validation/testing split. but i found the len of train.pt is 24176 ...so... I'm very confused about what data you're used?

    opened by ssxxx1a 0
  • About Video Hair Editing

    About Video Hair Editing

    Thanks you for you great works! Do you think video hair editing based on HairCLIP is achievable? I have a little try, but the region of hairstyle still hard to control. Consistency in hair styles is quite difficult to maintain. Can you give me some insights about video-hairstyle-editing?

    opened by ZziTaiLeo 0
Owner
Ph.D Student @ University of Science and Technology of China
null
An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

Brian Peiris 12 Nov 2, 2022
Reference python implementation of Chia pool operations for pool operators

This repository provides a sample server written in python, which is meant to server as a basis for a Chia Pool. While this is a fully functional implementation, it requires some work in scalability and security to run in production.

Chia Network 451 Dec 13, 2022
Python package for reference counting native pointers

refcount master: testing: This package is primarily for managing resources in native libraries, written for instance in C++, from Python. While it boi

CSIRO Hydroinformatics 2 Nov 3, 2022
Project Faros is a reference implimentation of Red Hat OpenShift 4 on small footprint, bare-metal clusters.

Project Faros Project Faros is a reference implimentation of Red Hat OpenShift 4 on small footprint, bare-metal clusters. The project includes referen

project: Faros 9 Jul 18, 2022
Old versions of Deadcord that are problematic or used as reference.

⚠️ Unmaintained and broken. We have decided to release the old version of Deadcord before our v1.0 rewrite. (which will be equiped with much more feat

Galaxzy 1 Feb 10, 2022
A reference implementation for processing the content.log files found at opendata.dwd.de/weather

A reference implementation for processing the content.log files found at opendata.dwd.de/weather.

Deutscher Wetterdienst (DWD) 6 Nov 26, 2022
3D Printed Flip Clock Design and Code

Smart Flip Clock 3D printed smart clock that puts a new twist on old technology. Making The Smart Flip Clock The first thing that must be done for thi

Thomas 105 Oct 17, 2022
A collection of design patterns and idioms in Python (With tests!).

Python Patterns Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayP

null 5 Sep 12, 2021
Here is my Senior Design Project that I implemented to graduate from Computer Engineering.

Here is my Senior Design Project that I implemented to graduate from Computer Engineering. It is a chatbot made in RASA and helps the user to plan their vacation in the Turkish language. In order to plan the user's vacation, it provides reservations by asking various questions for hotel, flight, or event.

Ezgi Subaşı 25 May 31, 2022
An app about keyboards, originating from the design of u/Sonnenschirm

keebapp-backend An app about keyboards, originating from the design of u/Sonnenschirm Setup Firstly, ensure that the environment for python is install

null 8 Sep 4, 2022
Random pass word generator made with python. PyQt5 module is used to design GUI.

Differences in this GUI program : Default titlebar removed Custom Minimize,Maximize and Close Buttons Drag & move window from any point Program work l

Dimuth De Zoysa 1 Jan 26, 2022
Print 'text color' and 'text format' on Term with Python

term-printer Print 'text color' and 'text format' on Term with Python ※ It may not work depending on the OS and shell used. PIP $ pip install term-pri

ななといつ 10 Nov 12, 2022
Configure request params such as text, color, size etc. And then download the image

Configure request params such as text, color, size etc. And then download the image

null 6 Aug 18, 2022
Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends.

Quiz Application Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends. When they would a

Atharva Parkhe 1 Feb 23, 2022
PaintPrint - This module can colorize any text in your terminal

PaintPrint This module can colorize any text in your terminal Author: tankalxat3

Alexander Podstrechnyy 2 Feb 17, 2022
Purge your likes and wall comments from VKontakte. Set yourself free from your digital footprint.

vk_liberator Regain liberty in the cruel social media world. This program assists you with purging your metadata from Russian social network VKontakte

null 20 Jun 11, 2021
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.

pipupgrade The missing command for pip Table of Contents Features Quick Start Usage Basic Usage Docker Environment Variables FAQ License Features Upda

Achilles Rasquinha 529 Dec 31, 2022
Add your recently blog and douban states in your GitHub Profile

Add your recently blog and douban states in your GitHub Profile

Bingjie Yan 4 Dec 12, 2022
edgetest is a tox-inspired python library that will loop through your project's dependencies, and check if your project is compatible with the latest version of each dependency

Bleeding edge dependency testing Full Documentation edgetest is a tox-inspired python library that will loop through your project's dependencies, and

Capital One 16 Dec 7, 2022