And welcome to the lesson where we basically do the same thing that we just did in Kansas, but no in
pie too much, and that same thing refers to identifying the mis classifications of the model that we
previously trained on the M.A. handwritten digit dataset, as well as generate the confusion matrix
and the classification report.
So open notebook for that's this one right here, which I really have done already.
And let's take a look at the lesson.
So before it, before we load on model learning models isn't as simple as as it is in Keros when in
pie too much.
And that's because we have to define the model architecture prior, so we have to set up the middle
class and define everything before we actually load the model in this case.
So let's let's end to do that.
We actually have to import all of these pie touch functions again.
So let's do that here.
There we go.
So it's loaded and we are using the GPU, which is good.
Let's look at the image plotting function.
And no, that's LoDo minus test data.
What are you going to look at to test data here?
So to do this, like previously, what we've seen before is that you define the transforms here.
We converting it to tensor or normalizing between minus one and one by setting the mean and standard
deviation two point five we are using towards efficient data sets amnesty to load the testator.
That's why trade is false.
We have to transform that we defined here.
And then we're creating a digital order out of test sets here where we specified a batch size.
We won't be shuffling no work as a zero, so let's run.
All of this now should run quickly.
There we go.
So now we have to define or create or model that definition class.
This is a model that we trained previously in the previous lesson.
So you can see it as a standard PyTorch model structure that we were using here and then.
Now we've done a little model that was saved to make a good Google drive previously.
And only now we can actually create the instance of the model and then load the state dictionary of
the model by using Torture Lord, and we pointed the file right here that we've downloaded.
So let's do that now.
And our model is now loaded.
There we go.
So it's a concern.
So, no, you would have seen this in the previous lesson here.
So we just use with torture no grid, which is basically what we do when we're running inference on
a model A deactivates the autocratic engine.
This allows it to reduce memory usage and speed up computations, which is why we use it in inference.
So we just want sitting ducks here.
We just use automated loader, which is either irritable and for so for data inside of it, we just
get the images and labels out of it.
Move it to the GPU, which is done in these lines here.
Then the default propagation with this batch of images here into the network get the outputs then used
to watch that max to get the predictions out of it.
And then we just do it to the accumulation for total number of levels, correct?
So total number of labels being examined, then total number of labels that were correct in this line
of code here and then just print the overall accuracy in the end of correct over total.
So let's run this, which you have seen before in the previous lesson, and our model has ninety eight
point seven percent accuracy.
It's better, better than the model that we loaded for accuracy dataset.
So, no, let's take a look at this polling on this classified images.
So as I said here, out of 10000 images, we have predicted many 8.7 percent correct, which is pretty
good.
However, we can get a lot better.
So a good practice, and it's a good habit when you're creating image classifiers to always examine
the misclassified images.
So that's what I mentioned in the Keras lesson, because you always want to see which what your model
is struggling, that why and you can figure out why and then make adjustments to your model or to your
data processing or image augmentation pipeline to understand.
So let's keep going.
And these are some reminder notes here.
In case you're wondering why we use native and towards undergrad as well.
So this sets the evaluation mode here for to inference again.
And we just do the same thing here with torsional grad.
So we just don't need a gradient validation.
So we just wrap it in and we have no grad, which saves us memory.
Take our data from a test data to go through the process again.
So when you're ready?
Just run this block of code here.
And what's happening here is that we're inspecting each prediction here, so we're checking to see if
the prediction is correct or not.
By this, let this look in this paper, and if it's not correct, we're just printing the actual label,
predicting the printed label, reshaping the image so that we can actually plot it here and then using
the initial function we defined previously to display the image.
So you can see we have no 128 samples of the batch.
It's actually actually not all the batch.
This is actually the full, all the misclassified images here.
So it's quite large number, I would imagine, but not as large as 500 from the Keras ones, probably
like about 200 and something, and you can see them here.
So you can see the actual label was a tree predictive it.
It's understandable, actually, there was a four, a nine.
This one does look like a bit like like a nine, though, so it's understandable.
So you can expect it to and you can see this one looks like a scorpion, actually.
But it's it's actually it's probably the spin skipped here and in particular to inadvertently this one
looks like one predicted of it.
Maybe because it's a tick one.
This one inflicted one, but it's actually a two.
So you can see it's doing quite well and the classes, it's making mistakes actually, classes that
some humans can make mistakes identifying too like this one is actually, I mean, it's a tree, but
it's honestly, it's not that visible that it's a tree.
It's not that appearance.
So let's keep going and we can examine the all of the glasses here.
But generally, you can see your model is doing quite well.
Let's delete this block here.
Now we'll stop there for now, and in the next section, we'll take a look at generating a confusion
matrix as well as a classification report.
So I'll see you in the next section.
Thank you.