In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Python how to achieve nine image style transfer, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Image style transfer already belongs to a relatively mature field, and now even real-time style transfer is not a problem. I have been coming up with an article like this before, but it is very troublesome to configure most open source projects, such as luanfujun/deep-photo-styletransfer projects, which need to install CUDA, pytorch, cudnn, and so on.
Recently, however, I found a very good open source application project, which is OpenCV's DNN image style migration. You only need to install OpenCV to use it, enter it in cmd/terminal (if you have not already installed Python, please see this article "Python installation"):
Pip install python-opencv
However, it also has limitations, we can only use models trained by others for style transfer, if we want to customize the style, we must configure tools such as cudn and use the methods of projects such as deep-photo-styletransfer for training. In today's tutorial, we use the model trained by fast-neural-style to do a style transfer to the following picture.
1. Selection model
There are 9 model styles released by fast-neural-style. We will try them one by one. Some of them are as follows:
Candy
Mosaic
Starry_night
Udnie
Model file can scan the following QR code to follow the Python utility dictionary, reply style migration download, which contains all 9 model style resources and source code.
two。 Clone OpenCV source code
We directly cloned the example of DNN image migration in the OpenCV open source project at:
Https://github.com/opencv/opencv/blob/3.4.0/samples/dnn/fast_neural_style.py
Code:
Note that the source code is based on Python2, so line 46 is missing parentheses, if you are Python3, please pay attention to the parentheses. This code can be used directly, parser defines five parameters,-input input to migrate the image width and height, median_filter is the median filter, the basic idea is to use the pixel neighborhood gray value of the median value to replace the pixel gray value, so the larger the theoretical value, the smoother the image, the better the details of the output results (uncertain). I personally tried the impact of median_filter on the image and found that the change was minimal, so it was fine with the default value.
3. Start the migration
Save the code in step 2 to a file named 1.py, and run the script with parameters in CMD/Terminal, where input is the source image path and model is the migrated style model file, such as running:
$python 1.py-input 1.jpg-model udnie.t7
Effect:
Migration effects of all 9 styles:
This is the answer to the question about how Python realizes the transfer of 9 image styles. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.