1
00:00:00,150 --> 00:00:07,470
Hi and welcome back in this lesson, we'll take a look and using PyTorch to create a simple D.C. gun,

2
00:00:07,470 --> 00:00:11,430
that's a deep convolutional gun again on the amnesty data set.

3
00:00:11,610 --> 00:00:14,580
So let's begin to open No.22.

4
00:00:14,910 --> 00:00:16,350
And we could start to listen.

5
00:00:17,010 --> 00:00:21,990
So firstly, let's just import or modules and libraries that we'll be using.

6
00:00:22,890 --> 00:00:25,560
And now we can fetch our amnesty, the set.

7
00:00:26,010 --> 00:00:29,610
You would have seen this before we discover transforms here.

8
00:00:29,610 --> 00:00:34,800
We normalize it between minus one and one setting to mean inside the deviation here.

9
00:00:35,310 --> 00:00:36,990
Converting it to a tensor.

10
00:00:37,440 --> 00:00:43,050
We lowered a training dataset here and we create a train loader right there.

11
00:00:43,470 --> 00:00:44,250
Quite simple.

12
00:00:44,970 --> 00:00:48,330
And now let's remember, we're not using the test dataset here.

13
00:00:48,330 --> 00:00:51,720
We're just using the trained data to create this just in case you were wondering.

14
00:00:52,770 --> 00:00:54,840
Now let's visualize some of the samples.

15
00:00:54,840 --> 00:00:58,110
So we just take a batch of images from a tree and luda.

16
00:00:59,250 --> 00:01:00,180
And no.

17
00:01:01,050 --> 00:01:02,520
So you would have seen this before.

18
00:01:02,550 --> 00:01:04,260
I don't have to go over that too much.

19
00:01:04,860 --> 00:01:08,370
Now we can take a look at our discriminator model.

20
00:01:08,910 --> 00:01:16,110
So remember, the discriminator tries to tell the difference between real and fake images.

21
00:01:16,470 --> 00:01:22,650
So its output basically is a binary output, and you can see that it takes inputs here.

22
00:01:22,710 --> 00:01:27,980
It's a 784 is 28 by 28, so it doesn't use any convalesce here.

23
00:01:27,990 --> 00:01:30,960
It just builds linear, fully connected layers and discriminator.

24
00:01:31,470 --> 00:01:35,850
So in this case, it's actually we're not using we're not building a DC again.

25
00:01:35,850 --> 00:01:38,750
In this case, we risk building a regular again.

26
00:01:38,760 --> 00:01:40,800
So I should actually change the name of this lesson.

27
00:01:41,430 --> 00:01:42,030
It's my bad.

28
00:01:42,780 --> 00:01:47,460
So now you can see we have multiple layers here.

29
00:01:47,970 --> 00:01:50,910
We go up in the layers and we come back down as well.

30
00:01:51,390 --> 00:01:53,850
And then we create a forward loop here.

31
00:01:54,000 --> 00:01:58,680
So we just take the input here and the final output, which is one here.

32
00:01:59,430 --> 00:02:03,660
So let's create a class that instantiate so model.

33
00:02:04,440 --> 00:02:07,170
Next, we can create our generated model.

34
00:02:07,560 --> 00:02:11,730
So remember, we generate a model that takes a random vector of, let's say, 100.

35
00:02:11,730 --> 00:02:17,310
So we use 100 in this one and then it generates an output image from that.

36
00:02:17,820 --> 00:02:23,370
So we're going to output the final image, which is going to be seven in four pixels and then we just

37
00:02:23,370 --> 00:02:26,370
have to reshape that afterward here.

38
00:02:26,850 --> 00:02:34,020
So we have a model here for propagated and then we just reshape the output to generate a 28 by 28 image.

39
00:02:35,610 --> 00:02:37,380
So let's create our generator here.

40
00:02:38,310 --> 00:02:40,310
Now we just set our trading parameters.

41
00:02:40,330 --> 00:02:46,530
So this is our living rate, which is a low living rate, said the number of epochs at the lowest functions.

42
00:02:46,530 --> 00:02:51,360
And this loss function we're using to get something called the B c loss.

43
00:02:52,410 --> 00:02:54,860
So here we just set our training parameters.

44
00:02:54,870 --> 00:03:00,030
We use a very low learning rate of zero point zero zero zero one seven above epochs.

45
00:03:00,030 --> 00:03:08,070
We use binary cross entropy loss and then for a follow optimizer, we use Adam for both the discriminator

46
00:03:08,070 --> 00:03:10,050
and the generator next.

47
00:03:10,770 --> 00:03:12,860
So here we have our creating a loop.

48
00:03:12,870 --> 00:03:16,620
So we firstly get the samples and labels from our tree and Luda.

49
00:03:17,250 --> 00:03:21,780
We put this on the device we generate or random vector here.

50
00:03:22,350 --> 00:03:24,780
This we give this latent space samples here.

51
00:03:24,780 --> 00:03:29,040
That's the random vector to the generator that gets them generated samples.

52
00:03:29,550 --> 00:03:31,800
And then we just pass that.

53
00:03:33,300 --> 00:03:35,530
So we set those labels to zero.

54
00:03:36,270 --> 00:03:41,220
And then we just concatenate everything here to real samples with the generated samples here.

55
00:03:41,610 --> 00:03:47,580
So this is to input the mix input that we're going to be feeding no to a discriminator along with all

56
00:03:47,580 --> 00:03:49,620
the ground should sample labels here.

57
00:03:50,190 --> 00:03:52,620
So then we just pass that in general to here.

58
00:03:52,620 --> 00:03:56,040
So we set the zero gravity at the start to initiate the training.

59
00:03:56,580 --> 00:03:58,290
We give it all the samples.

60
00:03:58,680 --> 00:04:00,600
We get the outputs out of that here.

61
00:04:00,630 --> 00:04:06,930
We then we use the lost function, which we defined to get the loss basically from the output discriminative.

62
00:04:07,710 --> 00:04:08,690
So this takes the output.

63
00:04:08,730 --> 00:04:13,650
Sorry, the output of discriminator again with the sample level, so we can actually compute the loss

64
00:04:13,650 --> 00:04:15,150
for the lost discriminator here.

65
00:04:15,750 --> 00:04:17,430
And then we did gradients.

66
00:04:18,000 --> 00:04:24,840
Then we can generate data for the generator again, so we generate some more random than samples here.

67
00:04:25,470 --> 00:04:28,680
This is because we're not going to train the generator as well.

68
00:04:28,680 --> 00:04:33,090
So remember, we have to wait for discriminator here, the updated widths.

69
00:04:33,570 --> 00:04:39,120
So now we can start training the generator here so we can give it this new random samples here.

70
00:04:39,690 --> 00:04:45,540
And then we feed those generated samples now back to the discriminator again to get the results.

71
00:04:45,540 --> 00:04:53,250
And then we used the loss function here to the predefined above that to take this, real samples here,

72
00:04:53,250 --> 00:04:59,740
as well as the output discriminator generated samples and we see how well did you the.

73
00:04:59,880 --> 00:05:04,560
Its function, we see how well it did it, and then we opted to suites accordingly.

74
00:05:04,770 --> 00:05:11,220
And obviously, like in all the pay to watch training, we just print our results here or loss results

75
00:05:11,640 --> 00:05:14,130
so we can monitor it during its screening process.

76
00:05:14,850 --> 00:05:16,590
So it's a bit exhaustive.

77
00:05:16,590 --> 00:05:18,150
So let's run this.

78
00:05:18,720 --> 00:05:25,020
OK, so I stop the video for a while because it was taking up too much space to record it.

79
00:05:25,620 --> 00:05:30,930
But you can see it's taken quite a while to train 50 bucks, even though it is using the CPU, and they

80
00:05:30,930 --> 00:05:33,900
can just double check that it is using the GPU here.

81
00:05:34,650 --> 00:05:38,910
But so luckily, I did run this number before, so I have the output results here.

82
00:05:39,270 --> 00:05:42,120
So let's take a look at some generated samples.

83
00:05:42,120 --> 00:05:48,510
So remember, our generator needs that one by 100 vector here to generate a sample.

84
00:05:48,510 --> 00:05:53,400
So we create a number of those random vectors according to the bat size that we set.

85
00:05:54,000 --> 00:05:59,250
And then we just generate a we just use that to generate a new generated sample.

86
00:05:59,250 --> 00:06:04,740
So we feed this into this function that generates a model to get our generated samples.

87
00:06:05,340 --> 00:06:08,370
This this produces synthetic images right there.

88
00:06:08,880 --> 00:06:11,640
And then we can just use this and that that we can visualize.

89
00:06:11,640 --> 00:06:17,760
This generated synthetic images by just passing it to the CPU and using the touch here.

90
00:06:18,390 --> 00:06:22,320
This allows us to now use that plot level to visualize it.

91
00:06:22,710 --> 00:06:24,460
So let's take a look.

92
00:06:24,480 --> 00:06:25,950
We also have to reshape it here.

93
00:06:25,950 --> 00:06:31,440
Just in case you were wondering, because this produces a one day 784 vector at that point, because

94
00:06:31,440 --> 00:06:34,340
that's what we were generating, so we have to bring it back into the ship.

95
00:06:34,860 --> 00:06:36,630
Twenty eight by 28 pixel shape.

96
00:06:37,170 --> 00:06:43,620
So we get the updates here and you can see after 50 books, it's doing quite a good job.

97
00:06:43,620 --> 00:06:48,990
It's actually building the numbers better than our Keros DC again previously that we use.

98
00:06:49,450 --> 00:06:51,220
However, it's a bit noisier.

99
00:06:51,240 --> 00:06:55,170
You can see there's a lot of noise in these images, little touches here and there.

100
00:06:55,860 --> 00:07:02,700
So that's that's the difference between using a neural network for the connected neural network to generate

101
00:07:03,210 --> 00:07:03,600
this.

102
00:07:03,990 --> 00:07:07,620
These images, as opposed to what we did before, was a DC gun.

103
00:07:08,310 --> 00:07:11,580
In actual fact, our DC would discriminate.

104
00:07:11,580 --> 00:07:15,780
So for the Keros network was a convolutional discriminator.

105
00:07:16,170 --> 00:07:18,750
However, in this network, it wasn't.

106
00:07:19,320 --> 00:07:20,700
And that's merely the difference.

107
00:07:20,700 --> 00:07:24,120
That is, two generators were roughly the same, if I remember correctly.

108
00:07:24,540 --> 00:07:28,080
But you can go back and inspect yourself and verified what I'm saying is true.

109
00:07:28,680 --> 00:07:30,210
So that's it for this lesson.

110
00:07:30,210 --> 00:07:31,290
I hope you enjoyed it.

111
00:07:31,710 --> 00:07:32,910
Guns are really cool.

112
00:07:33,000 --> 00:07:37,620
One of my it's one of my favorite topics in the computer vision, deep learning domain.

113
00:07:38,160 --> 00:07:41,280
So that's it for know what we'll do next.

114
00:07:41,670 --> 00:07:48,660
We'll take a look at super risk and then generating some and some anime characters, as well as some

115
00:07:48,660 --> 00:07:53,940
other cool gun projects, will do cycle gun where we could the horses into zebras.

116
00:07:54,360 --> 00:07:58,320
And then we'll also do all gun to generate that arc in style.

117
00:07:59,130 --> 00:08:00,570
So stay tuned for those lessons.

118
00:08:00,720 --> 00:08:01,140
Thank you.
