This is very popular in the microblog last year, the code on the Git_hub is Https://github.com/fzliu/style-transfer
Like this is Van Gogh's painting.
This is your own picture.
And then you want to generate such
How do you do that? On Windows-based Caffe, this is really simple.
1 First in Https://github.com/fzliu/style-transfer to download the code, and the main code based on Pycaffe, you need to compile the Pycaffe well.
It is best to install a Python ProgressBar package on your computer by entering PIP install under Windows cmd ProgressBar
2 Unzip the Style-transfer-master folder, run the \scripts folder download_models.sh will download the model,
in the Model folder will appear Caffenet, Vgg16, Vgg19, googlenet and other folders, but sometimes the model folder there is no. model file, generally speaking. Model files range from dozens of to hundreds of M. If the download is not successful. Model file, We can open the download_models.sh and follow the links inside the manual download directly.
3 Running the Code
Here is the format for running the code: Python style.py-s <style_image>-C <content_image>-M <model_name>-G 0
Under Windows switch to the directory where style.py is located, enter the code as follows
Python style.py-s images/style/starry_night.jpg-c images/content/nanjing.jpg-m vgg19-g 0
In the example above, style-image corresponds to starry_night.jpg that is the style image, content_image corresponding to their own photo nanjing.jpg, model selection vgg19 (although other models can be selected, But generally vgg19 the best effect), G 0 corresponds to select the default GPU, if the g-1 is the CPU
Then enter to run, after the run can be in the outputs folder to get the results of the above processing.
The following are the running:
As you can see, selecting the GPU, then loading the image and the model succeeds and starts running, the left side is the display running progress, is already 6%, also needs about 54 minutes, because the image is relatively large, time is longer.
4 Change the following statement in style.py
Parser.add_argument ("-L", "--length", default=1024, Type=float, Required=false, help= "maximum image Length")
def transfer_style (self, img_style, img_content, length=1024, ratio=1e5,
n_iter=512, init= "-1", Verbose=false, Callback=none):
You can set the size of the image output, such as your own photo image size is 1024*500, change the output of the above statement length=1024, you can get the same size as the original image.
If not changed, the default output in the program is 512 width, the length of the installation input the same width-length ratio of the original image calculation.
The results of my own experiments
Original Image:
The effect of the output:
Realization of Image art style conversion style-transfer based on Window7+caffe