Hi and welcome back in this lesson, we'll take a look at PyTorch Lightning.
You'll get your first introduction to pay to watch lightning and start implementing a bunch of the cool
features that pay to watch lightning offers.
So open this notebook here and we'll get started.
So just to warn you, let's firstly, make sure you're using the GPU in this notebook.
So just double check that GPU is selected in your notebook settings here and press safe.
So there's a lot going on in this notebook, so it's going to be split into multiple videos.
So what I'm going to start with here is firstly, how do we set up an install page to watch lightning?
Well, it's actually quite simple.
It works simply from a simple tap install.
See, you just put exclamation mark when you're using this.
Python is called Evernote, Roblox, PIP Install PyTorch Dash Lightning, and we can use the Dash Dash
quiet argument just to avoid printing out the tons of information here on screen.
And then also we're going to install towards metrics which we'll use in the alongside PyTorch torch
lightning.
So let's install this.
It doesn't take too long to install.
There we go.
12 seconds it took to install here.
Now let's import the packages we'll be using and not will be importing by torch lighting as played by
torch lighting loggers for tens of logging that we use later on in this project, as well as we import
the image function from Pep Pill, as well as some some of the torch functions that we've used before
and the torch vision function, which we've actually not using them this dataset.
So that's irrelevant.
And let's just import these here and now that sort of data sets, which I think you've already downloaded.
Actually, no, not yet.
There we go.
So it's done in just under 30 seconds.
Now remember, we're using our cats versus dogs dataset.
So remember this function that we created in this class?
Sorry, this class is where we actually just get the dataset from our files, from data so that we have
downloaded here the cats versus dogs.
And so we can enter the path, which is what we declare here.
And then when we actually use this dataset, I'm class here.
We specify, oops.
We specify the training files that we get in the star, actually the training directory pointer there
and the transformations we declare here.
And this data listed asset class object basically returns the data along with the distorted image,
along with the label liberal, that it gets from the path here.
So this might seem confusing, I admit.
However, it's just in the nature of working with this cats, this dogs dataset that we have to do it
this way.
It's not organized and full is like some other datasets.
So just bear with me here.
I'm trying to explain that as best as I can for you guys.
So also, we just used a random split, which function split the dataset after we get it from here.
So we have a new validation dataset basically here splitting this ratio twenty thousand to 5000 next.
What we'll do will start organizing our could into the lightning structure or their design philosophy.
So let's take a look at this so you can see we have the class name here.
Call it lightning module that model for short it inherits from the deployed or lightning module.
Plus that's using super.
To do that, we just input it with a bad size when we when we were initializing this model and then
we have to convert layers from the torch and then the functions we approach frequently as an O to fully
connected layers.
Here, 16 filters, 2.2 two filters, 64 filters and 128 nodes here, as well as 256 here.
So that's fairly simple.
CNN.
Next, we have a trained data loader, so let's take a look at that line.
So we use the torches to utilize the data data loader.
That's I mean, we can shorten this if we wanted to change the imports and how they look.
But for now, this is where we get our data loader from.
We tell it and then we point o data set to train, train, remember train.
Was this to tell us in the data input images we got here and valleys D5 tells them we specify all but
size and shuffle equal.
True.
Next, we have our validation data and truffle should be false in this case here.
And we just pointed out this dataset object again.
Next, we just declare a simple cross entropy loss function.
Basically, this is the same loss that you have seen before where we just declare that loss and we have
the logics and the labels.
Basically, that's all we're doing, OK?
And then we have the training step here as well with the batch and The Bachelor and The Bachelorette
with the batch comes with the data and the label for that specific that size of twenty two images to
the two labels.
We just forward past images into here.
Get the output, then you then use the cross entropy loss function here to get the output and to get
a lost story.
And then we just log the losses and self-taught log and we return the loss, as well as a self-taught
log loss here and then the training step.
Lastly, we'll lastly next, we take a look at the validation step, which is quite similar.
We're just doing a forward pass here and on the validation data here.
Next, we just create a config optimizes function.
That's this here where we use Adam with a living rate of point zero two.
Then finally, we just have a similar forward pass that we had in our existing PyTorch plus module design.
So we just create the sequence of events here that so we have X control going with conf one that went
to country then fully connected, one for the kinds of two and up to the self max later.
That's pretty much it.
So let's run this block of code.
I know it can seem a bit confusing, but does the pie towards lightning?
Design philosophy allows you to put everything into this lightning class module here, so it actually
simplifies things for you.
So if you get used to using lightning, it actually is simpler than using propane torch.
So now what we're going to do, we're going to take a look at it automatic batch selection.
So I'll pause division now and I'll join you in the next video section where we continue with using
the automatic selection tool in PI torch lighting.
Thank you.