Neural Style Transfer

Motivating Neural Style Transfer

  • Neural style transfer involves combining two images together:

    • One image refers to our content image CC
    • The second image refers to our style image SS
    • Combining these two images creates a genereated image GG
  • Essentially, we apply a style from one image to our content image
  • Then, the generated image will be include the content of our content image with the style from our style image

Introducing the Cost Function for Neural Style Transfer

  • We must define a new cost function in order to build a neural style transfer system
  • The cost function measures how well our generated image GG fits to our data
  • The cost function is minimized using gradient descent
  • The cost function is defined as the following:
J(G)=αJc(C,G)+βJs(S,G)J(G) = \alpha J_{c}(C,G) + \beta J_{s}(S,G)
  • The cost function is made up of two cost sub-functions:

    • The cost function Jc(C,G)J_{c}(C,G) is the cost of the content image
    • The cost function Js(C,G)J_{s}(C,G) is the cost of the style image
  • The content cost function measures the similarity between the content image CC and generated image GG
  • The style cost function measures the similarity between the style image SS and generated image GG
  • The hyperaparameters α\alpha and β\beta specify the weighting between the content and style cost functions
  • For example, we could increase α\alpha to place more weight on the content cost function
  • We could also decrease β\beta to place more weight on the content cost function

Using the Cost Function to Generate Image GG

  • The general algorithm looks like the following:

    1. Initiate some random GG with the following dimensions:
    G:100×100×3G: 100 \times 100 \times 3
    1. Use gradient descent to minimize J(G)J(G):
    G=GJ(G)GG = G - \frac{\partial J(G)}{\partial G}
  • Therefore, gradient descent updates the pixels of our image GG
  • An example looks like the following:

costnst

More about the Content Cost Function


tldr


References

Previous

Visualizing a CNN