And welcome back in this lesson, we'll take a look at executing the Google deep dream algorithm using
Keros.
So let's get started.
Open Notebook 25, which I've already done here, actually changed us to 25.
Sorry about that.
So let's take a look at this lesson.
So what we'll do?
Firstly, I'll just say one thing, though, because implementing these algorithms like Google Live
Stream and neural style transfer in a few of these fluid projects, in this course, they can get quite
technical because you're now implementing real research papers.
These researchers have spent years or months working on.
So to do justice to explain these, these theycould and their methods in a short space of time is often
quite difficult.
So what I will do, though, is I'll explain it at a very high level and try to put a lot of comments
in the code to help you understand what's going on.
I'm not going to do a line by line explanations because that can get very tedious.
And to be quite fair, I don't actually fully understand every single thing that they do.
So I apologize for that.
And now we can get started after that disclaimer warning.
So what we're doing here?
We're loading our modules and this image here.
Also, what we're doing, we're setting two layer settings here.
Remember, these are represent different layers of the network.
And this this, which we attribute here, basically see how much we want to this way to contribute to
the visual effect so you can mess with these parameters.
Um, I tend to actually like the scaling it up like this, but you can mess with those parameters to
get different types of effects.
Next, we can do a number of octaves.
This is the skills that you run gradient descent up to more octaves you do.
The more time it takes, however, that you at some point you're not going to see much difference because
when it's too small, it's hard to see that on the image.
So Tree is a good number to use.
The ratio between scales is 1.4 and iterations will do.
That's the Ascend steps, but scale would be 20.
And then we use a max loss of 15 to stop that.
So let's run this and we'll get started.
There we go.
So it's we've loaded an image and we've floated all libraries.
Now let's take a look at our test image to test.
Image we've been using for this lesson is a beautiful picture of a beach in the island of Tobago.
That's like home country of Trinidad and Tobago.
It's a star.
It's actually a heavenly bay, which is a bay next to costar a beach.
So it's a very, very beautiful spot that I love.
So now let's take a look at the deep dream process.
So remember, we're first loading our original image.
Then we define the number of processing skills which you have seen above in those parameters from small
astrologers.
Then we recites the original image to to the smallest skill.
And then for every skill, starting with the smallest one, we run gradient descent.
We upskill the image to the next skill and then re-injected the detail that was lost to the upskilling
time.
And then we stop.
When we cook, we are back to the original skill.
So now add them to obtain the detail lost during the upsampling.
We simply take the original image.
Shrink it down and then upskill it again and then compare the results of the original resized image.
So that's basically the process in the overview.
You can go back to the slides if you want to get a recap, more detailed recap with more, more visual
explanation.
So here we create a pre processing function for the image that we load, and this uses the Inception
version three pre processes because that's the model will be loading.
That's a pre-trained model that we've been using.
And then we also have a deep process function image, which is what we need to do when we do the mixing
of the images, and that's specific to the inception of each processing.
That's where these values come from.
So don't worry about these too much.
And no, we compute the gibbering loss.
So we load on that to work here.
We get upwards to orleaneans here in this and then we just create a feature extract extractor here using
those layers that we've loaded because we don't include the top layer.
That means that's a fully connected layers.
So it's basically a feature extract, a big feature extractor network.
So that's how we create this model, this feature to model here.
And now the most common computation is actually very simple.
We just promises how we run the gradient ascent part of it here.
So let's create that function.
And then we set up the gradient descent loop for one octave here.
So this is the gradient descent setup.
We're using TensorFlow as gradient to appear to run to compute these gradients at some.
Butterfly torches, Auchterarder, and then we just get to gradients normalized to gradients as we said
we would have to do.
And then this is the gradient descent loop that executes everything here next.
Now we can actually start the training loop and iterating over different octaves.
So this takes a little while to run when when it's finished running, we can display all final deep
dream output.
So let's go ahead and run this feature.
Extract is not defined within run this block of code on top here.
Let's do that now.
OK, so now we can run this.
So it's going to take a while, as they said, so we'll sit back and relax, go have a cup of tea or
coffee for the time being.
And then maybe in about a few minutes, it should be finished.
OK, actually, that took a lot shorter than expected 22 seconds.
Maybe we can actually use the parameters and tweak them to get the more fancy results, so let's take
a look at the output.
This should be exciting.
Let's see our first Google deep dream.
Here we go.
So you can see this is actually quite a way continues.
There's a weird little ES pattern that it created here.
I'm not entirely sure what it looks like.
It looks like a fish head, isn't it?
And then just some generic patterns here.
These patterns are due to the filters that we've we looked at.
You can you can feel free to change the mixing change a lot of those different parameters in the beginning
of the notebook and see if you get any other cool results.
Let's see.
Yeah, some of the cool patterns here.
Something trippy, not super trippy, but you can experiment and run this for longer with more iterations
as well to get even more color effects.
So that's it for the cameras, Google's deep dream algorithm.
Next, we'll take a look at how we do this and PyTorch, so I'll see you there.
But.