Hi and welcome back in this lesson, we'll take a look and using PyTorch to create a simple D.C. gun,
that's a deep convolutional gun again on the amnesty data set.
So let's begin to open No.22.
And we could start to listen.
So firstly, let's just import or modules and libraries that we'll be using.
And now we can fetch our amnesty, the set.
You would have seen this before we discover transforms here.
We normalize it between minus one and one setting to mean inside the deviation here.
Converting it to a tensor.
We lowered a training dataset here and we create a train loader right there.
Quite simple.
And now let's remember, we're not using the test dataset here.
We're just using the trained data to create this just in case you were wondering.
Now let's visualize some of the samples.
So we just take a batch of images from a tree and luda.
And no.
So you would have seen this before.
I don't have to go over that too much.
Now we can take a look at our discriminator model.
So remember, the discriminator tries to tell the difference between real and fake images.
So its output basically is a binary output, and you can see that it takes inputs here.
It's a 784 is 28 by 28, so it doesn't use any convalesce here.
It just builds linear, fully connected layers and discriminator.
So in this case, it's actually we're not using we're not building a DC again.
In this case, we risk building a regular again.
So I should actually change the name of this lesson.
It's my bad.
So now you can see we have multiple layers here.
We go up in the layers and we come back down as well.
And then we create a forward loop here.
So we just take the input here and the final output, which is one here.
So let's create a class that instantiate so model.
Next, we can create our generated model.
So remember, we generate a model that takes a random vector of, let's say, 100.
So we use 100 in this one and then it generates an output image from that.
So we're going to output the final image, which is going to be seven in four pixels and then we just
have to reshape that afterward here.
So we have a model here for propagated and then we just reshape the output to generate a 28 by 28 image.
So let's create our generator here.
Now we just set our trading parameters.
So this is our living rate, which is a low living rate, said the number of epochs at the lowest functions.
And this loss function we're using to get something called the B c loss.
So here we just set our training parameters.
We use a very low learning rate of zero point zero zero zero one seven above epochs.
We use binary cross entropy loss and then for a follow optimizer, we use Adam for both the discriminator
and the generator next.
So here we have our creating a loop.
So we firstly get the samples and labels from our tree and Luda.
We put this on the device we generate or random vector here.
This we give this latent space samples here.
That's the random vector to the generator that gets them generated samples.
And then we just pass that.
So we set those labels to zero.
And then we just concatenate everything here to real samples with the generated samples here.
So this is to input the mix input that we're going to be feeding no to a discriminator along with all
the ground should sample labels here.
So then we just pass that in general to here.
So we set the zero gravity at the start to initiate the training.
We give it all the samples.
We get the outputs out of that here.
We then we use the lost function, which we defined to get the loss basically from the output discriminative.
So this takes the output.
Sorry, the output of discriminator again with the sample level, so we can actually compute the loss
for the lost discriminator here.
And then we did gradients.
Then we can generate data for the generator again, so we generate some more random than samples here.
This is because we're not going to train the generator as well.
So remember, we have to wait for discriminator here, the updated widths.
So now we can start training the generator here so we can give it this new random samples here.
And then we feed those generated samples now back to the discriminator again to get the results.
And then we used the loss function here to the predefined above that to take this, real samples here,
as well as the output discriminator generated samples and we see how well did you the.
Its function, we see how well it did it, and then we opted to suites accordingly.
And obviously, like in all the pay to watch training, we just print our results here or loss results
so we can monitor it during its screening process.
So it's a bit exhaustive.
So let's run this.
OK, so I stop the video for a while because it was taking up too much space to record it.
But you can see it's taken quite a while to train 50 bucks, even though it is using the CPU, and they
can just double check that it is using the GPU here.
But so luckily, I did run this number before, so I have the output results here.
So let's take a look at some generated samples.
So remember, our generator needs that one by 100 vector here to generate a sample.
So we create a number of those random vectors according to the bat size that we set.
And then we just generate a we just use that to generate a new generated sample.
So we feed this into this function that generates a model to get our generated samples.
This this produces synthetic images right there.
And then we can just use this and that that we can visualize.
This generated synthetic images by just passing it to the CPU and using the touch here.
This allows us to now use that plot level to visualize it.
So let's take a look.
We also have to reshape it here.
Just in case you were wondering, because this produces a one day 784 vector at that point, because
that's what we were generating, so we have to bring it back into the ship.
Twenty eight by 28 pixel shape.
So we get the updates here and you can see after 50 books, it's doing quite a good job.
It's actually building the numbers better than our Keros DC again previously that we use.
However, it's a bit noisier.
You can see there's a lot of noise in these images, little touches here and there.
So that's that's the difference between using a neural network for the connected neural network to generate
this.
These images, as opposed to what we did before, was a DC gun.
In actual fact, our DC would discriminate.
So for the Keros network was a convolutional discriminator.
However, in this network, it wasn't.
And that's merely the difference.
That is, two generators were roughly the same, if I remember correctly.
But you can go back and inspect yourself and verified what I'm saying is true.
So that's it for this lesson.
I hope you enjoyed it.
Guns are really cool.
One of my it's one of my favorite topics in the computer vision, deep learning domain.
So that's it for know what we'll do next.
We'll take a look at super risk and then generating some and some anime characters, as well as some
other cool gun projects, will do cycle gun where we could the horses into zebras.
And then we'll also do all gun to generate that arc in style.
So stay tuned for those lessons.
Thank you.