In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the Python Barbershop how to achieve photo hairstyle function, the article is very detailed, has a certain reference value, interested friends must read it!
Environmental deployment
Let's move on to the worst part. First, let's take a look at the installation instructions given by the project.
In fact, there are only two, conda into the environment/environment.yaml environment, download II2S images. These two words made me pretend all night, and God knows what I've been through. If you step on one side of the pit, you can install it according to my process, which should not be a problem.
1. Import environment/environment.yaml environment
To create a conda virtual environment, use the following command:
Conda env create-f environment/environment.yaml2, install pytorch
If there is no, you can see my other article, there is a detailed construction method: machine learning basic environment deployment
3. Dependent library installation
I will not mention how many pitfalls I have stepped on. Below, I will summarize the dependencies that are not provided by the required projects.
Dlib
Ninja
Gdown
Scikit-image
IPython
Opencv-python
You can choose the latest version because I started running with the latest one.
4. Cl.exe environment variable configuration
I need to install Microsoft Visual Studio. The version I chose is version 2019.
Provide the download address: download Visual Studio Tools
It should be noted here that C++ should be selected when installing.
According to the number of machine bits, select the path to add to the environment variable path. Here's my path.
Add environment variabl
5. Model download
The project actually downloads the model itself when it is running, but it often fails from the google cloud disk, and the project requires a lot of models. I put it on Baidu cloud disk to share it, so you can download mine.
Model file link extraction code: tuan
First of all, the face 68 feature data is put into the cache directory of the project. Secondly, the other six pt files are placed in the pretrained_models directory of the project.
6. Download hairstyle data
Download from the cloud disk to the input/face directory according to the address given by the project. Here I still provide Baidu cloud disk sharing link, whether to come down can use mine.
Link extraction code: TUAN
7. Code adjustment
The project align_face.py file will not check whether the model exists or will be downloaded and needs to be adjusted. As shown below:
Project verification
OK, environment if you deploy successfully as I said above, congratulations. Let me verify the effect.
Let's take a look at the photos I prepared.
Put the photos in the unprocessed directory and note that the numbering needs to be different from the file number in input/face.
1. Preprocess photos
First, we execute the command to preprocess the photos in the unprocessed directory. The command is as follows:
Python align_face.py (Barbershop) C:\ Users\ yi\ PycharmProjects\ Barbershop > python align_face.pyDownloading Shape Predictor126.jpg: Number of faces detected: 1
You can see that there is an extra file in the input/face directory, and the pre-processing processes the faces of the original photos.
2. Change your hairstyle
Let's take a look at which hairstyle I'm going to change.
Change your hair for a short one. Execute the command as follows:
Python main.py-im_path2 126.png-im_path3 94.png-im_path4 94.png-sign realistic-smooth 5
Take a look at the execution result
(Barbershop) C:\ Users\ yi\ PycharmProjects\ Barbershop > python main.py-- im_path2 126.png-- im_path3 94.png-- im_path4 94.png-- sign realistic-- smooth 5Loading StyleGAN2 from checkpoint: pretrained_models/ffhq.ptSetting up Perceptual loss...Loading model from: C:\ Users\ yi\ PycharmProjects\ Barbershop\ losses\ lpips\ weights\ v0.1\ vgg.pth.[ net-lin [vgg] initialized...DoneNumber of images: 2Images: 100% | ███ █ | 2Accord 2 [10:39
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.