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 !
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 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 :
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 :
Look at another picture :
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 .
The effect is shown below :
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 .
This is the end of our article .