We've spent a bit of time making our models predictions more visual which is very very important for
when you're communicating your work.
I don't want you to think that just building a model and having an accuracy value like we've got up
here is enough because at the end of the day you can actually run this to get something like this in
about 10 lines of code.
But what really matters is how you're going to integrate your models use and how you're going to communicate
what it's actually doing to other people.
Because Robert always bring yourself back to what the project goal is.
What are we trying to do here with dog vision so let's take our little visualization functions and it'd
be good if we could see more than just one at a time.
So let's write some code to do that or leave a little bit of text here.
Now we've got
some functions to help us visualize our predictions and evaluate our model.
Let's check out a few.
So what we can do is probably create a few subplots and I want to get this image compared to its top
10 pred confidences.
So that's what I'm going to do.
Let's check out a few predictions.
And there are different values nice and simple.
So we want to go I multiply this to make sense in a second so we'll keep it at zero to begin with.
And again this is probably something we can also function eyes maybe that's a little challenge to you.
So we've got a number of rows three num calls equals two.
So we're going to plot out a subplot that's got three rows two columns and the number of images total
is just going to be num rows times num calls and then we'll go to plot that figure we'll set the fig
size.
I've had a bit of playing around with this so this might have to change depending on what your notebook
is or actually we could probably just go 10 times num calls and five times now it throws.
All right.
So now we want for I in range num images so five times two.
We're going to plot three times two sorry we're gonna plot six images total now images we need a semicolon
there.
We want to create a subplot peyote that subplot and it's gonna have two rows but it's going to have
two times number of columns and this will make sense once you pull it out.
So two times I.
This is the index we want to use.
Now we want to go plot Fred prediction probabilities
is equal to one that go to the next line.
Come on Mark prediction probabilities equals predictions and then we want to go what else is after that
we need to posit labels so labels is our Val labels and then images equals Val images and then the n
so the number or the index of the imagery want is I plus I multiplier.
And I'm starting to realize how janky this code is but that's a right.
It's gonna work.
We can probably function is this.
Remember I said you a little challenge at the start of video function or is this that could be a cool
series function.
Is this.
Someone just writes Paul code and then someone turns it into a function.
We go here plot thread com prediction probabilities
predictions and then we want to go labels equals valid labels because what we want to do is just compare
our predictions to the troop levels and then the end is going to be again I.
Plus I multiply and then let's say what it looks like plot don't show hopefully this works.
A It's starting to come out member might take a little while.
Oh that looks pretty terrible how can we fix this so it's kind of getting what we wanted.
Like an image with a title and then the top 10 prediction probability so see here Border Terrier number
one but it got it wrong.
The true label was Khan.
Or can I can't.
I can't really pronounce that.
We have a city in a shire called Cairns which is spelled very like that.
It has an S on the end.
Let's take this plot.
We want plot type layout should help us out so tight layout is just basically like hey we're working
with a subplot don't just plot them all over the place bring them together are you know why I think
this is work broken because we are calling plot docs show Inside the for loops that's gonna show a subplot
every time it plots
a gallon ha there we go look at that and our labels are cut off.
This is where plot type layout will help so one last adjustment to fix up our plot peyote type layout
and we we're gonna do Hage pads so horizontal padding.
So basically like take the padding along the horizontal axis and just give us a bit more space equals
1.0
and would you look at that fourth time lucky.
That's what it's all about right.
Trial and error trial and error.
If in doubt run the code.
So what's happening here.
We've got our image here.
We've got border terrier 22 percent calm.
We can say we just looked at this one let's look at this Scotch Terrier so we can see it's got a few
other predictions here.
It's overwhelmingly predicting Scotch Terrier this one it got it wrong Lakeland terrier and it's actually
a blue tick.
So wow this is the fourth the fourth label so it's overwhelmingly predicting likely a..
What's a like land terrier.
Look I'm using underscores because that's what our labels have images.
Okay you can kind of see that it's a fair bit going on in that image I think that now that even might
be a cat over there.
OK.
Bell linked a..
Yeah it's got that.
It's got that one really right.
That's amazing.
Oh now this that is that is a base prediction.
98 percent of our dish drops off that's what's up.
Okay now let's change this to maybe see the eye multiplier is going to modify our end.
So we want to try it.
Let's just try the next 10 images
all Irish Wolfhound 34 percent but it's actually a Yorkshire terrier.
Again this is you can start to see how this image is pretty hard.
Look how much is going on we're going to show sure what that is in the background.
We've got two people here.
But what's an Irish wolfhound look like Irish Wolfhound
hahaha big dog
OK.
You can almost.
It's really clutching at straws to try and say it's an Irish wolfhound because look it's even got its
even got three more predictions toy poodle like land terrier Italian Greyhound before the actual true
label.
So this is really fun.
This is predicted give us give us.
But it's actually a border collie and now you can see how it's probably got confused because there's
another dog there.
Whippet miniature poodle standard.
Look at that.
How fancy is that.
Ah OK.
So see here the top three labels are all poodles but it's a standard poodle when it's predicted a miniature
poodle.
Now this is where a lot of evaluation machine learning models.
This is what you got to remind yourself of.
If a human classifier like if we were looking at this image and if you knew dogs I don't really know
dogs except for like the three breeds that we've spoken about before I would say that that's just a
poodle.
But there's actually multiple different kinds of poodles.
So you've got to give your model a little bit of leniency here and go okay.
If a human is going to get confused on predicting a machine learning model is probably also going to
get confused at some point.
So let's do one more sample because this is just fun to look at dogs and look out dog vision application
coming together.
Now remember this is only trained on a thousand total images.
So hopefully we see a little bit of improvement when we trying to full model looking at asset based
prediction golden retriever.
It's actually a flat coated retriever Khan Khan.
Yes that's a great prediction there.
So this is this is cool right.
This is really cool visualizing what's going on if we were to show this to someone else.
We could explain to them rather than just showing them a prediction probability array we could start
to explain to them what's happening and if we were building our dog vision app.
This is probably something we'd like it to display and even something like this may be looking a little
bit cleaner.
This is it's still a bit matte plot layered spec and in a jeep and a notebook.
But this is a really important part of building a machine learning workflow.
So here we are evaluate the model what we might move onto next we might jump all over the place a bit
we might save and reload our train model because right now if our Google collab session decided to quit
and we didn't save our model we'd lose all of our predictions.
So we'd have to retrain a model so let's figure out the next video now that we visualize some of our
predictions.
I could play around with this all day actually let's figure out how to save our train model and load
a trained model intensive low.