"Distributed" artistic creation: 20 minutes +1080 graphics card, this AI can create complex works | Open Source

Guhao Nan Temple from the bottom of the recessed non-
qubit reports | Public number QbitAI

Generate complex art works in 20 minutes , and still use Nvidia’s previous 1080 graphics card?

Is the threshold for neural networks so close to the people now?

That's right, this is a style transfer model called neural-style-pt , based on Pytorch and just open sourced!

The topic of this algorithm model has only been published on Reddit for one day, and the popularity is close to 2000.

neural-style-pt, is it really cool and close to the people?

Rich integration methods

neural-style-pt is the Pytorch implementation of the paper A Neural Algorithm of Artistic Style .

The paper introduces an algorithm that uses a convolutional neural network to combine the content of one picture with the style of another picture, which is known as the "style transfer" network.

For example, mapping the artistic style of "Starry Sky" to a night view of the Stanford campus:

Or according to the different artistic styles of the given image, merge them into the target image:

In addition to "respectively" fusion, multiple artistic styles can be merged into one picture:

Starting clockwise from the upper left corner, the styles are "Starry Sky" + "Scream", "Scream "+" Composition Seven (Vassily Kandinsky Oil Painting)", "Sitting Nude Girl (Motiliani Oil Painting)" + "Composition Seven", "Sitting Nude" + "Starry Sky".

When performing style migration, add the "-original_colors 1" command, you can also change only the style without changing the colors of the original image:

Can run with 1080 card?

Depending on the background and optimizer, the speed of the algorithm will vary greatly.

Use 512 pixel images to iterate 500 times on Tesla K80. Time reference:

  • Backstage nn, optimizer L-BFGS: 117 seconds

  • Backstage nn, optimizer ADAM: 100 seconds

  • Background cudnn-optimizer L-BFGS: 124 seconds

  • Background cudnn-optimizer ADAM: 107 seconds

  • Background cudnn -cudnn_autotune-optimizer L-BFGS: 109 seconds

  • Background cudnn -cudnn_autotune-optimizer ADAM: 91 seconds

On GTX 1080, the time is faster under the same benchmark:

  • Backend nn-optimizer L-BFGS: 56 seconds

  • Backstage nn-optimizer ADAM: 38 seconds

  • Background cudnn-optimizer L-BFGS: 40 seconds

  • Backstage cudnn-optimizer ADAM: 40 seconds

  • Background cudnn -cudnn_autotune-optimizer lbfgs: 23 seconds

  • Background cudnn -cudnn_autotune-optimizer ADAM: 24 seconds

Combined with the current price of 1080 cards, I have to say that such a threshold is already very popular for machine learning.

By default, neural-style-pt uses the backend for convolution and L-BFGS for optimization. However, a large amount of memory will be used. The following methods can be used to reduce memory usage.

Use cuDNN, add -backend cudnn to use cuDNN backend. When using ADAM, add -optimizer adam to use ADAM instead of L-BFGS.

In the default settings, neural-style-pt uses approximately 3.7GB of GPU memory on the system; switching to ADAM and cuDNN can reduce the GPU memory footprint to approximately 1GB.

How to get started

To install neural-style-pt, you must first prepare Pytorch.

Then, use the following one-sentence command to install the trained model:

python models/download_models.py

After installation, it’s easy to get started and try it out with one line of code:

python neural_style.py -style_image-content_image

If you want to load multiple styles, you need to separate different image file names:

-style_image starry_night.jpg,the_scream.jpg

Note that the picture name must include the complete address path.

These are the basic operations.

Another powerful feature of neural-style-pt is that it can use multiple different computing devices to process high-resolution images.

Different devices will output the calculation results of different network layers.

You can use the -gpu instruction to control which GPU and CPU devices are used, and you can also use -multidevice_strategy to control how to split the layer on different devices.

For example, in a server with four GPUs, the command "-gpu 0,1,2,3" refers to processing on GPUs 0, 1, 2, and 3 in order.

Give -multidevice_strategy 3,6,12 instructions at the same time, indicating that the first two layers should be calculated on GPU 0, layers 3 to 5 should be calculated on GPU 1, layers 6 to 11 should be calculated on GPU 2, and the remaining layers Should be calculated on GPU 3.

Adjust -multidevice_strategy according to your needs to achieve the maximum output resolution.

The following is a 4016x2213 resolution image, which was generated on a server using 8 Tesla K80 GPUs:

Get started with 1080 graphics card, but also "distributed" computing, such a cool and fun low-threshold style migration network, hurry up and try it~

Portal:
https://github.com/ProGamerGov/neural-style-pt

Ends  -

This article is the original content of the NetEase News•NetEase Featured Content Incentive Program account [qubit]. Unauthorized reprinting is prohibited.

Join the AI ​​community and expand your network in the AI ​​industry

Qubit "AI Community" is recruiting! AI practitioners and friends who are concerned about the AI ​​industry are welcome to scan the code to join, and pay attention to the development of the artificial intelligence industry & technological progress with 50,000+ friends :

Qubit  QbitAI · headlines on the signing of

վ'ᴗ' ի Track new trends in AI technology and products

One-click three consecutive "Share", "Like" and "Looking"

The frontiers of science and technology are seeing each other~

Guess you like

Origin blog.csdn.net/QbitAI/article/details/112791020