As you can see that similarities are astonishing, Tensorflow learned the patterns from the style image and applied them over the content picture (me). Ok enough talking let's jump straight into the tutorial: Install Python3 from this link. Make sure that you download version equal or bigger than 3.4  After that install virtualenv by initiating this command: pip3 install virtualenv When that is done we are ready to install Tenserflow. First, create a new directory for the project by typing - mkdir NeuralStyle and then - cd NeuralStyle After that create a virtual environment by - virtualenv neuralStyleProject Next, we need to activate the virtual environment in order to use it so in the terminal entire the command - source neuralStyleProject/bin/activate. After this command, your terminal should look similar to that “(NeuralStyleProjec) Georgi:NeuralStyle ” Finally, we are ready to install Tensorflow - export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl - pip3 install --upgrade $TF_BINARY_URL That will install the framework, it should take a couple of seconds (depending on your internet connection and computer) (Optional) In order to test if the installation was successful do the following $ python3 >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> exit() clone the Neuro style repository: git clone https://github.com/anishathalye/neural-style.git Enter the command “open .” it will open the home directory that is relative to the project Move the content “neural-style” folder and paste it into the folder “neuralStyleProject” Afer that you can delete the empty "neural-style" folder. Now your project directory should look like that: [caption id="attachment_16775" align="alignnone" width="1268"] NeuralStyleProject directory1[/caption] We need to download an already traded model in order for the need learning to work. Go to this link, and download this file “Pre-trained VGG network” at the bottom of the page. When downloaded cut and paste the file in the “neuralStyleProject” folder with the rest of the files. Find two good images one that is the one that you want to apply the style to and other that is the style. I name mines such as “georgi_content.jps” and “1-style.jpg” [caption id="attachment_16776" align="alignnone" width="840"] NeuralStyleProject directory2[/caption] Now in your terminal do cd neuralStyleProject to enter to the project directory. We are almost there, we need to install just a couple of needed libraries in order to run the neural-style program. install “numpy” by entering the command in the terminal enter: "pip3 install numpy” press enter "pip3 install scipy” press enter "pip3 install pillow” press enter Enter the following command to initiate the script by entering the following command: “python3 neural_style.py --content georgi_content.jpg --styles 1-style.jpg --output result.jpg” The program will start and your terminal will look like that: [caption id="attachment_16777" align="alignnone" width="1224"] initiated neuro-style image[/caption] If you want to achieve better results you can open the “neural_style.py” file with your program of choice (I used xCode) and you can change this variable: [caption id="attachment_16778" align="alignnone" width="908"] xcode image[/caption] 1000 iterations tend to achieve good results, but you can experiment with increasing this value. Bear in mind that this is a very long process and it could take (depending on the resolution of the content and the number of iterations) about 9 hours or more. I would suggest resizing your content and style images to about 300 pixels width - keep the resolution low and after you are certain that the style will produce the desirable effect you can run the algorithm with bigger resolution images for content and style. Forgot to mention that your output image will keep the same resolution as your content image. If you do not have a Mac OS machine but you want to try the framework there is a website called deepart.io. It works on the same principle, you have to provide a content image (the one that you want to apply a style to) and a style image (the one that will be used to generate the style)."/> As you can see that similarities are astonishing, Tensorflow learned the patterns from the style image and applied them over the content picture (me). Ok enough talking let's jump straight into the tutorial: Install Python3 from this link. Make sure that you download version equal or bigger than 3.4  After that install virtualenv by initiating this command: pip3 install virtualenv When that is done we are ready to install Tenserflow. First, create a new directory for the project by typing - mkdir NeuralStyle and then - cd NeuralStyle After that create a virtual environment by - virtualenv neuralStyleProject Next, we need to activate the virtual environment in order to use it so in the terminal entire the command - source neuralStyleProject/bin/activate. After this command, your terminal should look similar to that “(NeuralStyleProjec) Georgi:NeuralStyle ” Finally, we are ready to install Tensorflow - export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl - pip3 install --upgrade $TF_BINARY_URL That will install the framework, it should take a couple of seconds (depending on your internet connection and computer) (Optional) In order to test if the installation was successful do the following $ python3 >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> exit() clone the Neuro style repository: git clone https://github.com/anishathalye/neural-style.git Enter the command “open .” it will open the home directory that is relative to the project Move the content “neural-style” folder and paste it into the folder “neuralStyleProject” Afer that you can delete the empty "neural-style" folder. Now your project directory should look like that: [caption id="attachment_16775" align="alignnone" width="1268"] NeuralStyleProject directory1[/caption] We need to download an already traded model in order for the need learning to work. Go to this link, and download this file “Pre-trained VGG network” at the bottom of the page. When downloaded cut and paste the file in the “neuralStyleProject” folder with the rest of the files. Find two good images one that is the one that you want to apply the style to and other that is the style. I name mines such as “georgi_content.jps” and “1-style.jpg” [caption id="attachment_16776" align="alignnone" width="840"] NeuralStyleProject directory2[/caption] Now in your terminal do cd neuralStyleProject to enter to the project directory. We are almost there, we need to install just a couple of needed libraries in order to run the neural-style program. install “numpy” by entering the command in the terminal enter: "pip3 install numpy” press enter "pip3 install scipy” press enter "pip3 install pillow” press enter Enter the following command to initiate the script by entering the following command: “python3 neural_style.py --content georgi_content.jpg --styles 1-style.jpg --output result.jpg” The program will start and your terminal will look like that: [caption id="attachment_16777" align="alignnone" width="1224"] initiated neuro-style image[/caption] If you want to achieve better results you can open the “neural_style.py” file with your program of choice (I used xCode) and you can change this variable: [caption id="attachment_16778" align="alignnone" width="908"] xcode image[/caption] 1000 iterations tend to achieve good results, but you can experiment with increasing this value. Bear in mind that this is a very long process and it could take (depending on the resolution of the content and the number of iterations) about 9 hours or more. I would suggest resizing your content and style images to about 300 pixels width - keep the resolution low and after you are certain that the style will produce the desirable effect you can run the algorithm with bigger resolution images for content and style. Forgot to mention that your output image will keep the same resolution as your content image. If you do not have a Mac OS machine but you want to try the framework there is a website called deepart.io. It works on the same principle, you have to provide a content image (the one that you want to apply a style to) and a style image (the one that will be used to generate the style)."/> Use “Deep Learning” To Create Art Masterpieces [Tutorial] – MrThaiBox123
 

Use “Deep Learning” To Create Art Masterpieces [Tutorial]

Georgi Koemdzhiev Jul 18, 2016 603 No Comments

Featured Image

Would you like to create unique art like the painting above? You can do that very easily and the results are very interesting. You can create masterpieces that can be compared to the work of some of the greatest painters ever lived such as Pablo Picasso, Michelangelo, Vincent van Gogh and others. You can do that using a framework that uses Google’s deep learning framework called Tensorflow. In this tutorial, we are going to use Tensorflow in conjunction with a small library on GitHub that utilizes it and makes it “learn” the patterns (style) from one image and apply it on another (content). I have to note that this tutorial is only for MAC users because the library that we are going to use supports only Mac OS. The above image was generated by the framework using this style image:

style image

style image

This is the original image:

Content Me

Content Me




As you can see that similarities are astonishing, Tensorflow learned the patterns from the style image and applied them over the content picture (me).

Ok enough talking let’s jump straight into the tutorial:

  1. Install Python3 from this link. Make sure that you download version equal or bigger than 3.4
  2.  After that install virtualenv by initiating this command: pip3 install virtualenv
  3. When that is done we are ready to install Tenserflow. First, create a new directory for the project by typing
    – mkdir NeuralStyle and then
    – cd NeuralStyle
  4. After that create a virtual environment by
    – virtualenv neuralStyleProject
  5. Next, we need to activate the virtual environment in order to use it so in the terminal entire the command
    – source neuralStyleProject/bin/activate. After this command, your terminal should look similar to that “(NeuralStyleProjec) Georgi:NeuralStyle ”
  6. Finally, we are ready to install Tensorflow
    – export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl
    – pip3 install –upgrade $TF_BINARY_URL
    That will install the framework, it should take a couple of seconds (depending on your internet connection and computer)
  7. (Optional) In order to test if the installation was successful do the following
    $ python3
    >>> import tensorflow as tf
    >>> hello = tf.constant(‘Hello, TensorFlow!’)
    >>> sess = tf.Session()
    >>> print(sess.run(hello))
    Hello, TensorFlow!
    >>> exit()
  8. clone the Neuro style repository: git clone https://github.com/anishathalye/neural-style.git
  9. Enter the command “open .” it will open the home directory that is relative to the project
  10. Move the content “neural-style” folder and paste it into the folder “neuralStyleProject”
  11. Afer that you can delete the empty “neural-style” folder. Now your project directory should look like that:
    NeuralStyleProject directory1

    NeuralStyleProject directory1

  12. We need to download an already traded model in order for the need learning to work. Go to this link, and download this file “Pre-trained VGG network” at the bottom of the page. When downloaded cut and paste the file in the “neuralStyleProject” folder with the rest of the files.
  13. Find two good images one that is the one that you want to apply the style to and other that is the style. I name mines such as “georgi_content.jps” and “1-style.jpg”
    NeuralStyleProject directory2

    NeuralStyleProject directory2

  14. Now in your terminal do cd neuralStyleProject to enter to the project directory.
  15. We are almost there, we need to install just a couple of needed libraries in order to run the neural-style program. install “numpy” by entering the command in the terminal enter:
    “pip3 install numpy” press enter
    “pip3 install scipy” press enter
    “pip3 install pillow” press enter
  16. Enter the following command to initiate the script by entering the following command:
    “python3 neural_style.py –content georgi_content.jpg –styles 1-style.jpg –output result.jpg”
  17. The program will start and your terminal will look like that:
    initiated neuro-style image

    initiated neuro-style image

  18. If you want to achieve better results you can open the “neural_style.py” file with your program of choice (I used xCode) and you can change this variable:
    xcode image

    xcode image

1000 iterations tend to achieve good results, but you can experiment with increasing this value. Bear in mind that this is a very long process and it could take (depending on the resolution of the content and the number of iterations) about 9 hours or more. I would suggest resizing your content and style images to about 300 pixels width – keep the resolution low and after you are certain that the style will produce the desirable effect you can run the algorithm with bigger resolution images for content and style. Forgot to mention that your output image will keep the same resolution as your content image.

If you do not have a Mac OS machine but you want to try the framework there is a website called deepart.io. It works on the same principle, you have to provide a content image (the one that you want to apply a style to) and a style image (the one that will be used to generate the style).

Leave a Reply

Your email address will not be published. Required fields are marked *