当前位置:网站首页>Test of the opposite sex what you look like?
Test of the opposite sex what you look like?
2022-08-10 05:55:00 【programming fun】
A lot of people may not find it strange to know PS and use it as a graphics software to be a self of the opposite sex.But isn't it more interesting that we are today, generated with artificial intelligence?
This kind of AI function implementation involving images, friends who understand deep learning will know some.It is often implemented with the very popular GAN generative adversarial network, or DCGAN.And the use of AI to make the opposite sex self mentioned in this article is to use a gender conversion function of PaddleGAN.In other words, it is to use the face attribute editing ability in PaddleGAN to realize gender transformation of any face!
I. Environment preparation
Download PaddleGAN
git clone https://github.com/PaddlePaddle/PaddleGANorgit clone https://gitee.com/PaddlePaddle/PaddleGANInstall PaddleGAN locally
#Enter PaddleGAN directorycd /home/aistudio/PaddleGAN#install dependenciespip install -r requirements.txt#Install PaddleGAN locallypython setup.py developInstall dlib
pip install dlibIf the arrangement of dlib fails, please go to the official website to download the corresponding whl version and install it manually.
Second, Extract the Latent Code of the original image
Here we use Pixel2Style2Pixel to extract Latent Code, you only need to change two parameters:
input_image: the original image path, that is, the photo path where hidden features need to be extractedoutput_path: The storage path of the hidden features of the original image, which needs to be used in the attribute editing and generation module later
Put the face photo of the face you want to change gender in the input_image part, please note that it is best to take a selfie and a big head photo, the effect is better without glasses~
Command method:
cd applications/python -u tools/pixel2style2pixel.py --input_image '/home/aistudio/face test set/yingbb2.png' --output_path '/home/aistudio/psp_output/yingbb2'--model_type ffhq-inversion--seed 233--size 1024--style_dim 512--n_mlp 8--channel_multiplier 2Programmatically:
import paddlefrom ppgan.apps import Pixel2Style2PixelPredictorpredictor = Pixel2Style2PixelPredictor(output_path="outputs",weight_path=None,model_type="ffhq-inversion",seed=233,size=1024,style_dim=512,n_mlp=8,channel_multiplier=2)predictor.output_path = 'outputs'predictor.run('inputs/src.png')Three, generate the opposite sex you
Edit the Latent Code in a specific direction, and use StyleGAN V2 to generate a new face from the edited vector.
Command method:
python -u tools/styleganv2editing.py--latent '/home/aistudio/psp_output/11/dst.npy'--output_path '/home/aistudio/final_output/11'--model_type ffhq-config-f--size 1024--style_dim 512--n_mlp 8--channel_multiplier 2--direction_name gender --direction_offset 5 #Convert positive numbers from female to male, and negative numbers from male to female, Programmatically
import paddlefrom ppgan.apps import StyleGANv2EditingPredictorpredictorEditing = StyleGANv2EditingPredictor(output_path="outputs",weight_path=None,model_type="ffhq-config-f",seed=None,size=1024,style_dim=512,n_mlp=8,channel_multiplier=2,direction_path=None)dstNpyPath="outputs/dst.npy"predictorEditing.output_path = 'outputs'direction_offset = 5 #positive numbers are converted from female to male, and negative numbers are converted from male to femalepredictorEditing.run(dstNpyPath, "gender", direction_offset)Four, the final conversion result

Okay, I'll share it here today. If you have any ideas, please leave a message for discussion.
边栏推荐
猜你喜欢
随机推荐
Day1 微信小程序-小程序代码的构成
笔记1
WeChat applet wx.writeBLECharacteristicValue Chinese character to buffer problem
常用类 String概述
操作表 函数的使用
菜谱小程序源码免费分享【推荐】
符号表
Four characteristics of ACID
棋类游戏-五子棋小游戏
Set Sources Resources and other folders in the IDEA project
优先队列
细说MySql索引原理
国内数字藏品投资价值分析
反射【笔记】
链读 | 最新最全的数字藏品发售日历-07.28
cesium rotate image
力扣——统计只差一个字符的子串数目
Link reading good article: What is the difference between hot encrypted storage and cold encrypted storage?
tinymce rich text editor
Likou - Number of Provinces









