element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
PiCasso Design Challenge
  • Challenges & Projects
  • Design Challenges
  • PiCasso Design Challenge
  • More
  • Cancel
PiCasso Design Challenge
Blog AI powered CNC Painting Machine - Blog #2 - Image Stylization / Style Transfer
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Attila Tőkés
  • Date Created: 20 Apr 2019 8:07 PM Date Created
  • Views 924 views
  • Likes 5 likes
  • Comments 1 comment
Related
Recommended

AI powered CNC Painting Machine - Blog #2 - Image Stylization / Style Transfer

Attila Tőkés
Attila Tőkés
20 Apr 2019

Hi,

 

Today, I got progress on the software part of the project. I started searching for stylization / style transfer implementations and I found one that may be suitable for the Raspberry Pi.

 

Image stylization / style transfer is a process the can be described as "extracting the style" from an image and "applying it" to a second image.
An example would be to take a painting (ex take Vincent van Gogh's The Starry Night) and apply to a photo (Stanford campus):

image

(example from the neural-style GitHub Repo)

 

Two early techniques of image style transfer are described in the following articles:

 

  • A Neural Algorithm of Artistic Style
    (Leon A. Gatys, Alexander S. Ecker, Matthias Bethge - Sep, 2015)
    • video description: Two Minute Papers #6 (Youtube)
    • implementation: jcjohnson/neural-style (GitHub)

 

  • Combining Markov Random Fields and Convolutional Neural Networks for Image Synthesis
    (Chuan Li, Michael Wand - Jan, 2016)
    • video description: Two Minute Papers #49 (YouTube)
    • implementation: chuanli11/CNNMRF (GitHub)

 

I tried to run examples from the two implementation, but I quickly realized that these will not work for the project. Both techniques needs to train convolutional neural networks "on-the-fly" to apply a style to an input image. The process takes significant time (minutes on a powerful GPU, hours on CPU). This means there is no way to get this running on the Raspberry Pi.

 

Fortunately, the research was ongoing on the topic and some techniques for real-time stylization / style transfer were developed.

 

I found the the fast_neural_style example in the PyTorch repository which implements style transfer using pre-trained models. The example is based on the following two articles:

  • Perceptual Losses for Real-Time Style Transfer and Super-Resolution
    (Justin Johnson, Alexandre Alahi, Li Fei-Fei - Mar, 2016)

 

  • Instance Normalization: The Missing Ingredient for Fast Stylization
    (Dmitry Ulyanov, Andrea Vedaldi, Victor Lempitsky - Nov, 2016)

 

The example can be run as follows:

$ git clone https://github.com/pytorch/examples.git pytorch-examples

 

$ cd pytorch-examples/


$ pip3 install torch torchvision

$ python3 download_saved_models.py

$ python3 neural_style/neural_style.py eval --content-image images/content-images/amber.jpg --model saved_models/<model>.pth --output-image amber-candy.jpg --cuda 0


Here is what I got by running the examples:

  • input image
    image
  • output images
    • "candy" model
      imageimage
    • "mosaic" model


      imageimage
    • "rain princess" model
      imageimage
    • "Udnie" model
      imageimage

 

The example run in ~ 6.5 seconds each on CPU, so they are relatively fast. I think, it can be ported to the Raspberry Pi and hopefully it will run in a reasonable amount of time.

 

Cheers,

Attila

 

Refs :

  • Combining Markov Random Fields and Convolutional Neural Networks for Image Synthesis
    (Chuan Li, Michael Wand - Jan, 2016)
  • A Neural Algorithm of Artistic Style
    (Leon A. Gatys, Alexander S. Ecker, Matthias Bethge - Sep, 2015)
  • Perceptual Losses for Real-Time Style Transfer and Super-Resolution
    (Justin Johnson, Alexandre Alahi, Li Fei-Fei - Mar, 2016)
  • Instance Normalization: The Missing Ingredient for Fast Stylization
    (Dmitry Ulyanov, Andrea Vedaldi, Victor Lempitsky - Nov, 2016)
  • Towards Fast Neural Style Transfer
    (Connor Shorten, towardsdatascience.com)
  • chuanli11/CNNMRF - code for paper "Combining Markov Random Fields and Convolutional Neural Networks for Image Synthesis"
    (GitHub)
  • jcjohnson/neural-style - Torch implementation of neural style algorithm
    (GitHub)
  • pytorch/examples - fast_neural_style
    (GitHub)
  • Sign in to reply

Top Comments

  • dubbie
    dubbie over 6 years ago +3
    An interesting approach. Dubbie
Parents
  • dubbie
    dubbie over 6 years ago

    An interesting approach.

     

    Dubbie

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • dubbie
    dubbie over 6 years ago

    An interesting approach.

     

    Dubbie

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube