Setting up a neural network to render images into art

By Solominer | Solominer | 24 Jun 2019


stylestransferguidecover.jpg

A few followers of mine asked me to write out a guide on how to do the types art I do on #trippythursday. I take two photos taken on tripod with my special camera, a full spectrum photo and an infrared or ultraviolet photo. Then I use a code based neural network to add colors from the full spectrum photo into the colorless infrared or ultraviolet photo. Sometimes the neural network adds colors, patterns and other interesting and psychedelic features to the otherwise colorless photo.

 

Background and History

This technology is similar to the "Deep Dream" project started by Google. A CAPTCHA based algorithm trained in a neural net to identify objects and superimpose them into images or videos.

https://en.wikipedia.org/wiki/DeepDream
More info on DeepDream

 

So Style-Transfer is technique of using these trained algorithms on an Nvidia CUDA enabled machine to analyze and superimpose what its been trained to see onto the new images. For the images I make I am currently using "NIN-Imagenet" which was designed to detect objects using a "model zoo". By it does this by looking for colors, lines, shadows and other repeatable patterns to attempt to identify what is in the photo. Using special software (Neural-style-pt), you can harness the power of this object detecting neural network to transfer style in photography.

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

Neural-style-pt is a Python application that runs with other dependencies to turn my black and white infrared photos into computer generated art work.

Setting up your own Neural net environment

Before starting with Python, some important tools and drivers need to be installed.

CUDA Toolkit and compatible video card.

A list of video cards that support such drivers: https://developer.nvidia.com/cuda-gpus

 

Miniconda

https://docs.conda.io/en/latest/miniconda.html
Anaconda is a full distribution of Python itself along with the binaries for several hundred third-party open-source projects. Miniconda is just an installer for an empty conda environment, containing only Conda, its dependencies, and Python.

After installing both, verify they are working in the terminal.

Check the CUDA version to make sure its functioning.

nvcc --version

Download Neural-Style-pt from Github

https://github.com/ProGamerGov/neural-style-pt/archive/master.zip

ptfolder.jpeg

Extract and Create two folders. Style and Content.

Content Will be used for the black and white infrared photos in my case. But consider these the base photos.

Style Is used to "Stylize" the content photos, adding what the Neural network things should be in the content photo.

 

Navigate to the downloaded Neural-Style-pt in terminal by using CD. Then test Conda:

conda create -n neural-style-pt python=3

activate neural-style-pt

conda install tensorflow scipy pillow

Once the above commands are run you should have tested Conda and verified you have CUDA up and running.

Install the models, which are the trained neural networks that will be used to transfer style from the style to the content

You do this by running the download_models.py which will download VGG16, VGG19 and NIN-Imagenet.

If all went well you are ready to run Neural-Style-pt

While in the terminal enter the following command tailor it to your modelcontent style and out directory paths.

python neural_style.py -style_image C:/neuralstylept/style/picasso_selfport1907.jpg -content_image C:/neuralstylept/content/brad_pitt.jpg -output_image C:/neuralstylept/Out/profile.png -model_file models/nin_imagenet.pth -gpu 0 -backend cudnn -num_iterations 1000 -seed 123 -content_layers relu0,relu3,relu7,relu12 -style_layers relu0,relu3,relu7,relu12 -content_weight 10 -style_weight 500 -image_size 512 -optimizer adam

processescuda.jpeg

If you get an out of memory error you may need to decrease the image_size value. But if you have a big beefy video card you can increase it past 2000.

consoleoutput1.jpeg

Running the python script looks like the above

consoleoutput2.jpeg

As the python app runs it will create iterations in the Out folder. And after 10 or so the image should appear more than just some psychedelic patterns.

outfolder.jpg

With a successful render the image should have colors added to it from the full spectrum image into the new image. Though sometimes the colors may be slightly different and placement can be a little off so has its own unique look to the image.

 

This Python script can do alot more than just what I am currently doing with it. You can stylize pictures taken in real life with artwork to get very unique effects.

keepersphotographyart.jpeg

I plan to run many of my photos taken through this Python script using art as the style photo, so far above is what I have come out with.

 

The possibilities are limitless with this tool, with the variety that occurs in art the merges would be countless with amazing results.


BJx7lFsDX4.png

 

Addresses below to help me buy better camera equipment and support me to travel to locations to do photo and video and overall great blogs in new places. I would be happy to list some of the contributors in my posts for donations that help me along the way.

Coin Address btc1.png BTC: bc1qhfmvd2gywg4fvrgy2kkkkyqta0g86whkt7j8r7 ltc.png LTC: ltc1qdyzm5cwgt8e2373prx67yye6y9ewk0l8jf3ys9 dash.png DASH: XkSqR5DxQL3wy4kNbjqDbgbMYNih3a7ZcM eth.png ETH: 0x045f409dAe14338669730078201888636B047DC3 doge.png DOGE: DSoekC21AKSZHAcV9vqR8yYefrh8XcX92Z zen.png ZEN: znW9mh62WDSCeBXxnVLCETMx59Ho446HJgq Platform URL/Username steem.png Steem https://steempeak.com/@solominer dtube.png D.Tube https://d.tube/#!/c/solominer weku.png Weku https://main.weku.io/@solominer TUBE.png Bit.Tube https://bit.tube/solominer mithril.png Mithril Solominer discord.png Discord Solominer#4248 bitcointalk.png Bitcointalk https://bitcointalk.org/index.php?action=profile;u=83228 109046833app-icon.pngCryptoPanic https://cryptopanic.com/solominer D5z-H9-Syx-CKd9-GJ4-T6rk-Bdeq-Zw1co-QAa-Qy-CUz-UF4-Foz-Bv-W6xf-LX2-PECcvq-Brku4u7.pngWhaleshares https://whaleshares.io/@solominer bearshare.png Bearshares https://bearshares.com/@solominer

How do you rate this article?

0


Solominer
Solominer

I am a user of cryptocurrency and also run infrastructure for multiple Coins and Dapps. I write about my experience with blockchain tech and nature. On the side I use a full spectrum camera to take unique photos in the Infrared and Ultraviolet spectrums.


Solominer
Solominer

Working with interesting technology: blockchain, IPFS, infrared and ultraviolet photography/videos

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.