Hi and welcome back in this lesson, we'll take a look at the PyTorch implementation of nine old style
transfer.
So open this notebook and we'll begin to listen.
So in this lesson, we're doing it from scratch.
We're not going to be loading a pre-trained model like we did with TensorFlow hub.
And we're going to basically build the components from scratch like we did in the second half of that
last lesson.
So let's take a look.
So I'm not going to read through all of these explanation notes here, but lengthy, and you can do
that on your own time.
So let's import these functions that we'll be using.
You can see we're using the regular watch functions, as well as some towards vision models.
That's that's that gives us the pre-trained Kijiji model that we will we will be using of that pre-treatment
model.
We're not going to be using specific, stylized model like we used in TensorFlow Arab.
Let's double check that we're using our GPU and we just print this out.
We are using energy for you.
Great.
Now let's load our test images here of we're going to take a look at so the content image is going to
be a difference.
In this case, I wanted to show you that we can actually apply neural style transfer to a style, an
auto image so you can copy the artistic style of one image onto another image.
So we'll take a look and I'll show you what I mean.
You can use any of the any images you want here.
Just point a URL to it to upload it to your GitHub and point of view URL here.
So I'm using the one on the PyTorch tutorial site to demonstrate this because I think it's a good example
and it works well.
So this is the image loader here where we convert into a pill image.
This is a plotting function, and let's take a look at those test images.
So this is a content image, and we're going to apply this artistic style onto this image.
So that should lead to a very cool result.
So now we have to define our lost functions.
So, you know, we have our content loss here, which we create does a small little function that calculates
the MSI loss between the input and the target.
Then we have a star loss along with our grand matrix.
So in this one, we are using the grand matrix and you can see and PyTorch.
It's actually fairly easy to implement some of these functions.
Not as confusing as to Carrasco.
No, is it?
So now we can take a look at star loss here.
So this is a Star Wars class.
I should say that it keeps track of both of these things with the ground matrix.
And now we just import or model set it to evaluation mode.
So we download a model from Dubai to its repo and then now we just have a normalization means a standard
deviation for the image net pre-processing, and we create another normalization function here.
And then, no, this is a big class that this is what it's doing.
Most of the heavy lifting here.
We basically run the the neural cell transfer algorithm right here.
So this is going to step true for all of the different layers we want to specify.
And this is going to basically get the content layers, get the star layers and then trim off the layers
of last content and style and return our model.
So this basically is the core of our network.
So let's run that.
And no and no, we can just take a look at our test image just again did with image, just so content
image.
And here we have a optimizer.
We're using the LBC's algorithm, so optimizer.
It's recommended for neural cell transfer to get these people.
And then we can now finally step through the network because we had the class above that basically extracted
all the layers that we're working with and now and and losses.
And no, we can actually compute everything with our training steps.
So that's run that we have everything in our PyTorch setup optimizes.
You agreed.
So everything should be fine.
So let's create this and now we can do to run out and run style transfer function and implement our
new rules to transfer using by touch.
So let's take a look.
You can see it's running fine.
We don't see an output yet.
So we're running for the default of 200 steps here, and these are some of the content with some weight
ratios and you can change as well.
So you can see after running for those 200 iterations, we get this nicely generated image here.
So that's pretty cool.
And you can experiment with different weights to try it.
But this one actually looks quite good, in my opinion.
It looks like it actually was painted in that style that autistic.
So.
So that's it for the PyTorch implementation of neural cell transfer and the next lesson, we'll start
taking a look at auto incluidas and then micho it again, which is a really cool part of the course.
So I'll see you then.
But.