Photo-Sketching One can recognize the outline of a photo and transform it into “ Shorthand ” Open source module for image .
such as , This little dog :
After model transformation , Will become a cartoon version of the dog :
Of course , Not all the photos are handled well , For example, this landscape painting is not good :
suddenly , It became an abstract style :
Very beautiful , It's very artificial intelligence .
The use of this module is also relatively simple , Let's take a full range of tutorials :
1. Virtual environment and dependent installation
This project is recommended to be used directly Anaconda Build and develop the environment , Because the author provides a environment.yml file , You just need to enter the following command , One click installation environment and dependencies :
conda env create -f environment.yml
Besides , Recommended VSCode Editor to write small programs like this Python project .
2. Download pre training model
Unzip the file after downloading , take latest_net_D.pth and latest_net_G.pth Placed in Checkpoints Under the folder :
3. Run the pre training model
Next , We need to modify the startup script using the pre training model , These scripts are all in PhotoSketch\scripts Next , What we need to use is test_pretrained.cmd perhaps test_pretrained.sh These two scripts .
If you are windows System , Please amend test_pretrained.cmd Script , The key is dataDir、results_dir、checkpoints_dir:
dataDir Point to PhotoSketch Folder Directory , If you're a match like me ,results_dir Just match it to *%dataDir%\PhotoSketch\Results* that will do ,checkpoints_dir Then for *%dataDir%\PhotoSketch\Checkpoints* .
If you are macOS perhaps Linux, The modified test_pretrained.sh file , The modification method is the same as above windows The same as , It's just The backslash "" Change it into Diagonal bar "/" .
After modifying the script , Open the command line / terminal , Enter the following command , It'll take you PhotoSketch\examples The files in the directory are converted into “ Shorthand ”.
windows:
scripts\test_pretrained.cmd
Linux/MacOS:
./scripts/test_pretrained.sh
The results of transformation can be found in PhotoSketch\Results see , The following two figures are shown .
Directory to be converted :
After the transformation :
It can be seen that the effect is not very good , Because it's the author's pre training model , So the effect is not good and normal , If you need it , You can take some image training models for yourself , And targeted to do identification , This is the best way .
You need to train or test your own model, and it's very simple :
scripts/train.sh
You can train models scripts/test.sh
You can test val Set or test set Of course, the training process is not so simple , You're going to have a lot of problems , But I believe most of the problems are caused by the structure of the directory where the pictures are stored , If you are interested, you can try it .
This is the end of our article , If you like today's Python Practical course , Please keep an eye on me .