程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python one line code turns your avatar into an animation style!

編輯:Python

source : Learn quickly Python

I have a problem recently , need Turn avatars into anime style , At that time, the first idea was to find ready-made wheels . For example, in our previous article 《 Super interesting Python actual combat : Turn the picture into plain wind !》, By calling a call called Tiler Open source library , Generate cute pixel wind pictures !

▲ The picture turns into plain wind

Turn avatars into anime style , I want to keep the original image information and texture details at the same time , Convert real photos to anime / Cartoon style non photorealistic images . At present, except baidu api,Github There are many open source libraries available for us to use directly .

among AnimeGAN It's a study from Wuhan University and Hubei University of Technology , It's neural style migration + Generative antagonistic network (GAN) The combination of , The implementation effect meets our needs very well .

AnimeGAN The first one to use is Tensorflow frame , However, after querying the data, it is found that the project has supported PyTorch frame .

Address :https://github.com/bryandlee/animegan2-pytorch

And I happened to be based on PyTorch Realized the emotional analysis of microblog comments , So it won't be a burden to use , It also saves installing libraries .

Pytorch install

PyTorch It's an open source Python Machine learning library , be based on Torch, For natural language processing applications . This deep learning framework , It can be applied to numerical modeling 、 Image modeling 、 Text modeling 、 Audio modeling and so on .

install Pytorch It will be more troublesome than other libraries , If you go to the official installation and download , You need to get your own installation commands according to the actual configuration .

If you find that the download speed is slow through the above steps , Or encounter various problems , Try this website :

https://download.pytorch.org/whl/torch_stable.html

Site view :

Animation style migration

install Pytorch After the framework , We can put this animegan2-pytorch project clone To local / Download it directly :

git clone https://github.com/bryandlee/animegan2-pytorch

Download to the local file end directory as shown in the following figure :

among weights The folder contains four weights , Choose the corresponding weight to achieve your desired animation style migration .samples Under the inputs Examples of pictures are stored in the folder , You can test the water directly . in addition to , I also created a new one under the same path output Folder , Used to store processed pictures .

Next , We just need to run... From the command line test.py The script can call the project , The specific command format is as follows :

python test.py --checkpoint [ Model file path ] --input_dir [ Enter the directory where the image is located ] --output_dir [ The output directory ] --device [ Device selection ,cpu perhaps cuda]

Actual operation :

Because it is like face animation migration , So I used face_paint_512_v1.pt and face_paint_512_v2.pt The weight , The effect is shown below :

Actual combat effect ①

Look at another picture :

Actual combat effect ②

Personally feel face_paint_512_v2.pt The weight of the finished product is more in line with my imagination of animation style , What do you think ?

Finally I tried paprika.pt Animation migration of landscape pictures .

▲ Original picture

The effect is shown below :

▲ design sketch

If you look at the head portrait / I am interested in the cartoon style , You might as well try it ~


Be careful !

Be careful !

If you finish reading this article , Don't want to install Pytorch, I also want to create my own cartoon face directly ?

You can open this website on your computer :https://huggingface.co/spaces/akhaliq/AnimeGANv2, This is online AnimeGANv2 Of APP, There is no need to install any framework locally , You can convert directly .

▲AnimeGANv2 Website

This is the end of our article .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved