当前位置:网站首页>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/PaddleGAN
Install PaddleGAN locally
#Enter PaddleGAN directorycd /home/aistudio/PaddleGAN#install dependenciespip install -r requirements.txt#Install PaddleGAN locallypython setup.py develop
Install dlib
pip install dlib
If 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 2
Programmatically:
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.
边栏推荐
猜你喜欢
随机推荐
pytorch-09.多分类问题
十年磨一剑!数字藏品行情软件,链读APP正式开放内测!
MySql constraints
Batch add watermark to pictures batch add background zoom batch merge tool picUnionV4.0
LeetCode 94.二叉树的中序遍历(简单)
I use this recruit let the team to improve the development efficiency of 100%!
Day1 微信小程序-小程序代码的构成
链读 | 最新最全的数字藏品发售日历-07.28
error in ./node_modules/cesium/Source/ThirdParty/zip.js
A timeout error is reported when connecting to Nacos
网络安全之防火墙
wiki confluence 安装
Privatisation build personal network backup NextCloud
笔记1
视图【】【】【】【】
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
pytorch-06.逻辑斯蒂回归
LeetCode 1894.找到需要补充粉笔的学生编号
cesium add point, move point
MySQL中MyISAM为什么比InnoDB查询快