1
00:00:00,660 --> 00:00:01,920
Hi and welcome back.

2
00:00:02,430 --> 00:00:07,740
Now let's take a look at using PyTorch to train a model on the fashion this data set.

3
00:00:08,040 --> 00:00:15,900
Firstly, without regularization, so let's close these previous notebooks and open up this notebook

4
00:00:15,900 --> 00:00:16,200
file.

5
00:00:19,540 --> 00:00:20,320
So there we go.

6
00:00:20,380 --> 00:00:21,940
So what we're going to do?

7
00:00:22,390 --> 00:00:27,820
We're going to do the same thing we did in the first part of its lesson, which was this one here where

8
00:00:27,820 --> 00:00:29,620
we basically just train trino model.

9
00:00:29,980 --> 00:00:32,320
So we just load or packages before.

10
00:00:32,320 --> 00:00:38,530
And we were training on model on the fashion amnesty to set which we import using to watch vision data

11
00:00:38,530 --> 00:00:40,310
sets, thought fashion gymnast.

12
00:00:40,330 --> 00:00:43,180
And you can specify you want true for the training dataset.

13
00:00:43,630 --> 00:00:45,700
Such training all forms for the test dataset.

14
00:00:46,300 --> 00:00:48,270
And it's quickly downloaded here.

15
00:00:48,280 --> 00:00:53,500
So we have that already next to we create our train and test data, Lueders.

16
00:00:54,040 --> 00:00:55,990
We set the classes as well here.

17
00:00:56,650 --> 00:01:01,180
We print the ships here just to check and make sure the dataset loaded correctly.

18
00:01:01,960 --> 00:01:04,660
It's always good to visualize some data here.

19
00:01:05,020 --> 00:01:08,140
I'm going quite fast because we would have done this in previous lessons before.

20
00:01:08,140 --> 00:01:09,260
There's nothing new.

21
00:01:09,280 --> 00:01:14,320
I'm teaching you right now, but if you just want to, if you want me to slow down, just request me

22
00:01:14,710 --> 00:01:16,630
to do it and I can remake these videos.

23
00:01:17,470 --> 00:01:22,570
So now let's move on to putting the images, visualizing the classes with torch vision.

24
00:01:22,990 --> 00:01:29,970
So we'll quickly do that here, and you would notice that it's the foreground, the basically the binaries

25
00:01:29,970 --> 00:01:31,150
that show has been inverted.

26
00:01:31,630 --> 00:01:34,210
And that's because this is actually how the classes look.

27
00:01:34,220 --> 00:01:35,260
They don't look like this.

28
00:01:35,620 --> 00:01:43,000
We just cleaned it up for using degree on the score, which does the reverse mapping of the it's basically

29
00:01:43,050 --> 00:01:44,880
a binaries invasion.

30
00:01:44,920 --> 00:01:45,640
It does here.

31
00:01:46,330 --> 00:01:48,010
And this one is the actual images here.

32
00:01:48,010 --> 00:01:50,770
So you can see it's quite similar to the amnesty to set.

33
00:01:51,340 --> 00:01:57,820
So now let's take a look at building and treating a simple CNN with no regularization, so this network

34
00:01:57,820 --> 00:01:59,020
should be quite familiar to you.

35
00:01:59,350 --> 00:02:03,190
It's what we trained our amnesty to set on in the previous lesson.

36
00:02:03,760 --> 00:02:09,820
So let's created there, and now let's define our loss and optimization functions.

37
00:02:10,780 --> 00:02:12,460
So we've done that there.

38
00:02:12,910 --> 00:02:13,900
Now let's try this.

39
00:02:13,900 --> 00:02:15,700
Let's try this for 10 epochs.

40
00:02:16,330 --> 00:02:21,850
Actually, let's create 15 epochs while we're at it, and I won't go through this code because it's

41
00:02:21,850 --> 00:02:26,410
the exact same code we went through in the first lesson of the deep learning section of this course.

42
00:02:26,830 --> 00:02:29,260
So let's begin training this here.

43
00:02:30,670 --> 00:02:35,650
This might take a little while so you can restart the video when it's finished.

44
00:02:36,670 --> 00:02:38,110
Hi, so welcome back.

45
00:02:38,170 --> 00:02:44,430
So our model has finished completed training right now, and you can see we've finished the eighteen

46
00:02:44,500 --> 00:02:46,240
hundred when it's finished here.

47
00:02:46,600 --> 00:02:53,500
That's a number of many batches and we get the accuracy out after each hundred mini batch iterations.

48
00:02:54,160 --> 00:02:56,710
So you can take a look the accuracy here.

49
00:02:56,740 --> 00:02:58,990
However, this isn't the final accuracy.

50
00:02:58,990 --> 00:03:05,800
Let's just stop this loop, and let's take a look at what our final model accuracy is.

51
00:03:06,310 --> 00:03:11,680
And the reason why this isn't the final model accuracy, because this is just the accuracy of the test

52
00:03:11,680 --> 00:03:15,310
batch at that point in time, it's going to be very similar to this.

53
00:03:15,320 --> 00:03:18,490
However, it's going to be more like an average of all of these together.

54
00:03:19,000 --> 00:03:22,540
And you can see when you more or less average all of these.

55
00:03:22,540 --> 00:03:28,570
Together, we get a final accuracy accuracy score to be ninety one point one four percent.

56
00:03:29,230 --> 00:03:30,010
So that's pretty good.

57
00:03:30,340 --> 00:03:33,760
That's actually remarkably good better than a Keros model as well.

58
00:03:34,330 --> 00:03:40,690
Let's take a look at our training plots now, and you can see things are they went as expected, may

59
00:03:40,690 --> 00:03:44,980
have had a slight dip at the end and the loss was continuously going down.

60
00:03:45,340 --> 00:03:51,070
So in this case, you can't actually see this model is over overfitting at this point in time.

61
00:03:51,700 --> 00:03:56,860
However, it does seem to be like slightly going down, so you may have wanted to introduce some early

62
00:03:56,860 --> 00:03:59,290
stopping around that point here.

63
00:03:59,560 --> 00:04:07,060
So anyway, let's see if our model weights and what I'm going to demo, which, you know, is some data

64
00:04:07,060 --> 00:04:08,320
augmentation.

65
00:04:08,920 --> 00:04:13,570
So what I'm going to demo to you now, which I didn't do in the Keros lesson, however, I just wanted

66
00:04:13,570 --> 00:04:19,480
to show you guys what the actual data transformations do when you add these augmentation parameters.

67
00:04:19,490 --> 00:04:21,370
And so what we can do.

68
00:04:21,640 --> 00:04:28,870
Remember, we have already have this data or transform here that we've put into this list right here

69
00:04:28,870 --> 00:04:30,280
with all these different transforms.

70
00:04:30,790 --> 00:04:36,700
We're doing some random assigned color to I'm not going to do this because it's a little bit hard to

71
00:04:36,700 --> 00:04:37,660
see anyway.

72
00:04:38,350 --> 00:04:44,590
Visualization, but this is going to do some random horizontal flips, random rotation and then John,

73
00:04:44,590 --> 00:04:45,520
some degree of skill.

74
00:04:45,670 --> 00:04:49,090
So let's take a look at what that looks like.

75
00:04:49,570 --> 00:04:51,790
So we create a small little function here.

76
00:04:52,330 --> 00:04:58,630
This function is basically takes a parameter which we have a d for this six and creates six subplots

77
00:04:58,630 --> 00:05:04,630
in a row so that we can actually see the six different random augmentations that will apply to one single

78
00:05:04,630 --> 00:05:06,340
image know dataset.

79
00:05:06,350 --> 00:05:08,050
So we access that image here.

80
00:05:08,170 --> 00:05:13,530
Converting it to NumPy Remedies Transit, that's from our batch.

81
00:05:15,400 --> 00:05:18,070
Yeah, and then we have the data that.

82
00:05:18,120 --> 00:05:23,820
No, I let's pull it out here, and we use the power of Pill

83
00:05:26,550 --> 00:05:31,000
Pillow is a next library that actually allows us to do image processing.

84
00:05:31,020 --> 00:05:35,340
It's quite nice, actually, and we use it from time to time for some of the with some of the utility

85
00:05:35,340 --> 00:05:40,980
functions, it makes things, makes the code more readable, often has good, some good tools.

86
00:05:41,460 --> 00:05:43,310
We won't spend too much time using pill.

87
00:05:43,320 --> 00:05:46,770
We're talking about pill, but every now and then you will see it mentioned in the code.

88
00:05:47,280 --> 00:05:51,450
So all of this discussion with you there, what this does here, this just converts it into.

89
00:05:51,960 --> 00:05:57,480
Instead of using the OpenCV GB conversion and all of those things, sometimes we can just use pill.

90
00:05:57,990 --> 00:06:03,750
It loads it as a RGV of this case as a grayscale, so it doesn't matter, but it just converted into

91
00:06:03,750 --> 00:06:07,200
a pill format image, which we can easily visualize here.

92
00:06:07,560 --> 00:06:13,740
So let's view this now, and you can see this is exactly what happens in a training loop.

93
00:06:13,740 --> 00:06:15,660
You can see this image here.

94
00:06:15,660 --> 00:06:21,510
This is probably one of the original images, and although it's not, they're all going to be manipulated

95
00:06:21,750 --> 00:06:22,260
somehow.

96
00:06:23,100 --> 00:06:27,030
And then so you can see the different manipulations of the image as it passes through.

97
00:06:27,040 --> 00:06:30,190
You can see this one has been shifted down.

98
00:06:30,210 --> 00:06:32,250
This one looks like it's slightly rotated.

99
00:06:32,730 --> 00:06:36,150
This one flipped and it rotated a bit.

100
00:06:36,720 --> 00:06:39,690
So you can see that the images are never consistently the same.

101
00:06:40,170 --> 00:06:40,860
This is good.

102
00:06:41,070 --> 00:06:42,600
This helps generalization.

103
00:06:43,110 --> 00:06:46,230
So but we didn't use it in this training loop here.

104
00:06:46,500 --> 00:06:46,890
We didn't.

105
00:06:46,890 --> 00:06:48,780
We didn't use any of these augmentations.

106
00:06:49,230 --> 00:06:55,290
We'll talk about that in the next lesson where I actually talk more about these transformations, how

107
00:06:55,290 --> 00:06:55,770
they're done.

108
00:06:56,400 --> 00:07:02,580
Just remember that that's data augmentation is a regularization method that works very well with image

109
00:07:02,580 --> 00:07:03,240
datasets.

110
00:07:03,750 --> 00:07:06,660
So I'll stop now and I'll see you in the next lesson.

111
00:07:06,930 --> 00:07:07,350
Thank you.
