1
00:00:00,540 --> 00:00:04,680
Hi and welcome back in this lesson, we'll take a look at PyTorch Lightning.

2
00:00:04,950 --> 00:00:09,450
You'll get your first introduction to pay to watch lightning and start implementing a bunch of the cool

3
00:00:09,450 --> 00:00:12,200
features that pay to watch lightning offers.

4
00:00:12,240 --> 00:00:15,930
So open this notebook here and we'll get started.

5
00:00:16,020 --> 00:00:21,780
So just to warn you, let's firstly, make sure you're using the GPU in this notebook.

6
00:00:21,780 --> 00:00:26,010
So just double check that GPU is selected in your notebook settings here and press safe.

7
00:00:26,880 --> 00:00:31,230
So there's a lot going on in this notebook, so it's going to be split into multiple videos.

8
00:00:31,770 --> 00:00:36,780
So what I'm going to start with here is firstly, how do we set up an install page to watch lightning?

9
00:00:37,320 --> 00:00:38,610
Well, it's actually quite simple.

10
00:00:38,940 --> 00:00:41,130
It works simply from a simple tap install.

11
00:00:41,130 --> 00:00:44,040
See, you just put exclamation mark when you're using this.

12
00:00:44,040 --> 00:00:51,680
Python is called Evernote, Roblox, PIP Install PyTorch Dash Lightning, and we can use the Dash Dash

13
00:00:51,690 --> 00:00:57,060
quiet argument just to avoid printing out the tons of information here on screen.

14
00:00:57,630 --> 00:01:02,490
And then also we're going to install towards metrics which we'll use in the alongside PyTorch torch

15
00:01:02,490 --> 00:01:02,880
lightning.

16
00:01:03,630 --> 00:01:04,830
So let's install this.

17
00:01:05,580 --> 00:01:07,140
It doesn't take too long to install.

18
00:01:09,600 --> 00:01:10,100
There we go.

19
00:01:10,380 --> 00:01:12,060
12 seconds it took to install here.

20
00:01:12,750 --> 00:01:19,290
Now let's import the packages we'll be using and not will be importing by torch lighting as played by

21
00:01:19,290 --> 00:01:25,890
torch lighting loggers for tens of logging that we use later on in this project, as well as we import

22
00:01:25,890 --> 00:01:32,160
the image function from Pep Pill, as well as some some of the torch functions that we've used before

23
00:01:32,160 --> 00:01:35,910
and the torch vision function, which we've actually not using them this dataset.

24
00:01:35,910 --> 00:01:37,040
So that's irrelevant.

25
00:01:37,050 --> 00:01:44,010
And let's just import these here and now that sort of data sets, which I think you've already downloaded.

26
00:01:44,130 --> 00:01:45,210
Actually, no, not yet.

27
00:01:47,600 --> 00:01:48,060
There we go.

28
00:01:48,080 --> 00:01:50,300
So it's done in just under 30 seconds.

29
00:01:51,140 --> 00:01:54,170
Now remember, we're using our cats versus dogs dataset.

30
00:01:54,260 --> 00:01:57,200
So remember this function that we created in this class?

31
00:01:57,200 --> 00:02:03,410
Sorry, this class is where we actually just get the dataset from our files, from data so that we have

32
00:02:03,410 --> 00:02:05,780
downloaded here the cats versus dogs.

33
00:02:06,260 --> 00:02:09,800
And so we can enter the path, which is what we declare here.

34
00:02:10,430 --> 00:02:14,180
And then when we actually use this dataset, I'm class here.

35
00:02:14,630 --> 00:02:16,340
We specify, oops.

36
00:02:16,790 --> 00:02:22,280
We specify the training files that we get in the star, actually the training directory pointer there

37
00:02:22,280 --> 00:02:24,050
and the transformations we declare here.

38
00:02:24,830 --> 00:02:32,240
And this data listed asset class object basically returns the data along with the distorted image,

39
00:02:32,690 --> 00:02:35,990
along with the label liberal, that it gets from the path here.

40
00:02:36,620 --> 00:02:39,090
So this might seem confusing, I admit.

41
00:02:39,110 --> 00:02:44,450
However, it's just in the nature of working with this cats, this dogs dataset that we have to do it

42
00:02:44,450 --> 00:02:44,780
this way.

43
00:02:44,780 --> 00:02:47,720
It's not organized and full is like some other datasets.

44
00:02:48,290 --> 00:02:49,850
So just bear with me here.

45
00:02:49,880 --> 00:02:53,720
I'm trying to explain that as best as I can for you guys.

46
00:02:54,380 --> 00:03:00,710
So also, we just used a random split, which function split the dataset after we get it from here.

47
00:03:00,710 --> 00:03:09,680
So we have a new validation dataset basically here splitting this ratio twenty thousand to 5000 next.

48
00:03:10,190 --> 00:03:16,430
What we'll do will start organizing our could into the lightning structure or their design philosophy.

49
00:03:16,970 --> 00:03:21,320
So let's take a look at this so you can see we have the class name here.

50
00:03:21,710 --> 00:03:27,890
Call it lightning module that model for short it inherits from the deployed or lightning module.

51
00:03:27,890 --> 00:03:29,690
Plus that's using super.

52
00:03:29,690 --> 00:03:36,860
To do that, we just input it with a bad size when we when we were initializing this model and then

53
00:03:36,860 --> 00:03:42,020
we have to convert layers from the torch and then the functions we approach frequently as an O to fully

54
00:03:42,020 --> 00:03:42,800
connected layers.

55
00:03:42,800 --> 00:03:52,820
Here, 16 filters, 2.2 two filters, 64 filters and 128 nodes here, as well as 256 here.

56
00:03:52,910 --> 00:03:54,200
So that's fairly simple.

57
00:03:54,560 --> 00:03:55,070
CNN.

58
00:03:55,680 --> 00:03:59,570
Next, we have a trained data loader, so let's take a look at that line.

59
00:04:00,110 --> 00:04:04,430
So we use the torches to utilize the data data loader.

60
00:04:04,760 --> 00:04:08,840
That's I mean, we can shorten this if we wanted to change the imports and how they look.

61
00:04:08,840 --> 00:04:12,200
But for now, this is where we get our data loader from.

62
00:04:12,950 --> 00:04:18,800
We tell it and then we point o data set to train, train, remember train.

63
00:04:18,800 --> 00:04:27,380
Was this to tell us in the data input images we got here and valleys D5 tells them we specify all but

64
00:04:27,380 --> 00:04:29,180
size and shuffle equal.

65
00:04:29,200 --> 00:04:29,750
True.

66
00:04:30,320 --> 00:04:34,850
Next, we have our validation data and truffle should be false in this case here.

67
00:04:36,740 --> 00:04:40,550
And we just pointed out this dataset object again.

68
00:04:41,240 --> 00:04:44,660
Next, we just declare a simple cross entropy loss function.

69
00:04:45,260 --> 00:04:50,450
Basically, this is the same loss that you have seen before where we just declare that loss and we have

70
00:04:50,450 --> 00:04:52,570
the logics and the labels.

71
00:04:52,580 --> 00:04:54,740
Basically, that's all we're doing, OK?

72
00:04:55,580 --> 00:05:01,850
And then we have the training step here as well with the batch and The Bachelor and The Bachelorette

73
00:05:01,850 --> 00:05:06,290
with the batch comes with the data and the label for that specific that size of twenty two images to

74
00:05:06,290 --> 00:05:07,040
the two labels.

75
00:05:07,520 --> 00:05:09,950
We just forward past images into here.

76
00:05:09,950 --> 00:05:18,590
Get the output, then you then use the cross entropy loss function here to get the output and to get

77
00:05:18,590 --> 00:05:19,190
a lost story.

78
00:05:19,670 --> 00:05:26,330
And then we just log the losses and self-taught log and we return the loss, as well as a self-taught

79
00:05:26,330 --> 00:05:29,360
log loss here and then the training step.

80
00:05:30,170 --> 00:05:34,700
Lastly, we'll lastly next, we take a look at the validation step, which is quite similar.

81
00:05:35,180 --> 00:05:39,800
We're just doing a forward pass here and on the validation data here.

82
00:05:40,490 --> 00:05:44,420
Next, we just create a config optimizes function.

83
00:05:45,170 --> 00:05:49,460
That's this here where we use Adam with a living rate of point zero two.

84
00:05:50,330 --> 00:05:57,900
Then finally, we just have a similar forward pass that we had in our existing PyTorch plus module design.

85
00:05:58,460 --> 00:06:05,330
So we just create the sequence of events here that so we have X control going with conf one that went

86
00:06:05,690 --> 00:06:11,420
to country then fully connected, one for the kinds of two and up to the self max later.

87
00:06:11,990 --> 00:06:12,790
That's pretty much it.

88
00:06:12,860 --> 00:06:14,660
So let's run this block of code.

89
00:06:14,660 --> 00:06:18,230
I know it can seem a bit confusing, but does the pie towards lightning?

90
00:06:18,620 --> 00:06:25,880
Design philosophy allows you to put everything into this lightning class module here, so it actually

91
00:06:26,000 --> 00:06:27,140
simplifies things for you.

92
00:06:27,170 --> 00:06:31,610
So if you get used to using lightning, it actually is simpler than using propane torch.

93
00:06:32,420 --> 00:06:36,290
So now what we're going to do, we're going to take a look at it automatic batch selection.

94
00:06:36,770 --> 00:06:41,780
So I'll pause division now and I'll join you in the next video section where we continue with using

95
00:06:42,140 --> 00:06:45,710
the automatic selection tool in PI torch lighting.

96
00:06:45,950 --> 00:06:46,360
Thank you.
