Neural style transfer

In this section, we are going to learn what neural style transfer is, the cost function, and what we are trying to minimize in the case of neural style transfer. When we are referring to style transfer, we will always have a content image followed by a style image, or the artwork, and what we want to do is to have a final image that looks such as the content image, but painted with a style from the styled image. Basically it's like the style is being transferred from the Van Gogh picture (as shown in the following diagram) to the content image:

Let's consider another example which is shown as follows. We have the content image once again, then we have the style image or the artwork, and we have a final, or the third image that looks like similar to both of those previous images, but in the same way they also look somewhat different:

In a few words, this is the application we will try to build in this section. We take two images and generate a third one that looks kind of similar to both of them.

As we have seen so far, neural networks are updating weights. With each update the model prediction or the hypothesis comes closer to the real data. So, we have the cost function measuring how similar the hypothesis is to the real data by calculating the square difference between them.

Ideally, we want the cost function to be zero, because that simply means that the hypothesis is exactly the same as the real data. The following formula is used to calculate the cost function of the hypothesis data:

J=1/m*sum(H(w)-Y)2-Cost function

The neural network does a really good job of predicting the same hypothesis as the real data. In the case of neural style transfer, we want the same, but with only one difference; instead of having only one ground truth, we have two of them. So we have two cost functions, one that measures the difference between the contact image and the generated image, and the second one, which measures the difference between the style image and the generated image. Ideally, we want these two cost functions to still be as low as possible, because that will mean that our generated image is similar to the content image and style image at the same time.

These coefficients, the alpha and the beta, simply impact how similar we want the generated image to be to the content or style image. So in a few words, if we have alpha to be way bigger than beta, that means that our generated image will be more similar to the content image rather than the style image. So these are just weights impacting how similar you want the generated image to be with a content or the style image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.117.214