All righty.
So now we've got a way to get validation images validation labels so a.k.a. the truth labels of what
an image is and prediction labels.
So you might be thinking this is a fair few steps to visualize what's going on but I hope you realize
where the importance is because we're always thinking about what's the end use case we're not just here
to build models for the sake of building models we want to build dog vision to return we could just
return an array of like this to a user and then they would go Wow.
I'm not going to use this app anymore because these numbers are just a bunch of jargon to me.
So that's why it's important that we can visualize our model's predictions in a way that people can
understand someone who isn't as versed in machine learning and prediction probabilities as us can understand.
That's our end goal and that's what I want you to start thinking about all of the projects that you're
working on rather than just building models.
What is your angle are you working towards something how can you communicate what you're doing to someone
else.
All right so let's write a little note to ourselves.
Now we've got ways to get
prediction labels validation labels which are the truth labels and validation images let's make some
functions to make these all a bit more visual.
Basically we need a bit of color in our lives
OK.
Now how might we do this.
So we're probably going to make a function as we said before.
That's going to show us an image and it'd be good if it could just plot an image that's what we can
use.
Map plotted something like that.
Take an array of image values which we've got here maybe a good thing we work towards is It plots the
predicted label it's predicted probability.
So the max value up here so something like this.
So this is 75 percent and then it's actual label.
I think we can get them along to a single plot maybe we'll write that down so we are don't confuse ourselves
with the rubber ducky technique from a boy Ron.
Thanks Rob.
We'll create a function which
takes an array of prediction probabilities and array of truth labels and an array of images and integers.
Now again I must stress I'll say it too I go horse but we are dealing with images.
But the visualization steps that we're doing goes to almost any data that you're working with.
So we're gonna go convert the prediction probabilities of course she may need to use some other visualization
techniques that aren't map pot lib to plot or to visualize a data sample but you get the picture predicted
label and plot the predicted label
it's predicted probability
the true label and the target image on a single plot like so how might we do that.
Let's go here we'll call it def some simple plot spread it takes what does it take takes prediction
probabilities probabilities it takes labels an array of true labels and an array of images and maybe
only one integer.
Let's make this a plot to a single image a single prediction label and a single truth label and an integer
so maybe we could just say this has an equals 1
that's going to error out because we've got nothing there that's all right get rid of that era we don't
like seeing them like calls me a little bit of stress so we go here view the prediction Ground Truth
and image for sample n and again getting trigger happy right it's like almost instinct for me to shift
and into whenever I finish writing a line of code okay.
So the first thing we'll need is the pred prob it's actually prediction probability but I'm not typing
that multiple times through label and the image.
So this is gonna equal member we want the end sample so we do have to actually type prediction probabilities
and so the index of the end sample and then we want labels n and again there's probably a thousand ways
to write this function.
This is just one way that I figured works could be probably optimized in some way but it works for now
equals get Fred label.
Now that we had the prediction probability we can use our function get pred label to get the pred label
brilliant nomenclature of our functions if I do say so myself.
Plot image and remove ticks because we just want a square of images we don't want accesses dot M show
image.
So this is a map partly a function.
You pass it an umpire.
If it's an image display an image by a data on a 2D regular raster far out sometimes Doc strings are
written in a complex way like it could adjust said puts an image
and Y takes.
So this is just empty list.
So what is turning them off and all basically is just going to show nothing because there's nothing
in that list.
We might need the plot title Iran change plot title to be predicted and what predicted libel probability
of prediction and truth labels peyote that title.
Now we've got our pred prob we've got our true label we've got our pride label so we're just gonna have
to create a string of three of these spread probability and true label now this one is going to have
to be 2.0 what is this doing.
This is just reducing the amount of decimal points in our prediction probability so that it's not something
long like this better example is not something long like this.
It's a percentage so rather than being that it's 75 percent that's what we're off.
Come down here.
We'll just do a little format and we'll go red label because that's the first one so prediction is there.
And then we want NDP Max Fred Traub Time's 100 times a thousand Woo.
So this is just going to be the prediction probability value.
So the max of this of the pred problem Ray times 100.
So when we saw a point seven five before it's just going to times that by 100 might not be.
Point seven five because it'll be a different value for a different image.
There we go.
And we want to label is the last one.
So does that make sense.
So plot title we want to get rid of that pass plot title squiggly brackets for pred label squiggly brackets
two decimal places percentage for the maximum prediction probability and squiggly brackets for the true
label.
Let's see what this bad boy looks like.
Unexpected end of string.
Oh we need another one
plot Fred.
Okay.
And now let's go plot Fred.
We want predictions.
On a prediction probabilities equals predictions.
And then we want labels equals Val labels and images equals Val images.
So this is just from up before where we UNbacked define our validation dataset.
We've got here and let's come down.
Let's test add a little function
O now labels are printing out incorrectly.
What's happened here true labels.
He calls pred label get Fred prob what is happening here.
True label
while we didn't convert I think I see what's going on what we have to do is convert our true label into
an actual label.
So right now.
This is debugging your own code right.
So what we have to do is change our own batch of five function to be unique breeds.
And this is going to be any ARG Max label.
Does that make sense.
Yes.
So just a very similar functionality what we could actually do is use this function here get pred label
what we might save that just for predictions.
So this is gonna get the unique braids NPR and Max label we need to rerun this
so make sure you update your own batch of high function and then if we rerun this this should be correct
and then if we rerun this Oh yeah.
Scott Terry are 68 percent correct.
This is not very intuitive.
What if someone was looking at this and it was like Scotch Terrier 68 percent Scotch Terrier.
Which one is the predicted and which one is the the non predicted.
Let's add some color.
That's how we could do it.
So what we will do will create a little if else cause so we'll go change the color.
That looks disgusting to me.
Ah see I'm Australian and we spell color.
Oh you are.
So whenever I say oh ah even though that's the actual little parameter that we have to pass to format
I don't like it the color of the title depending on if the prediction is right or wrong.
So all we're going to do is change this title to be green.
If it's right and red if it's wrong Red Label equals true label we want color equals green else color
equals red and then we're gonna pass a little parameter here.
So it's all about making out plots more visual
Oh what what in that change if pred label equals true label.
There we go.
I found it.
So that's part of the format we need to pass this outside of the format that makes sense.
So we're passing this color parameter directly to title rather than to format
Scotch Terrier 68 percent beautiful.
Now remember this is predicting for index 1.
So what we might do is just make sure it works on another image was our favorite number 42
you got that one wrong.
That's a good example actually it's pretty confident 76 percent predicted walk around but it's actually
an English fox hand.
So let's look up English fox hound.
What does an English fox hound look like images okay.
We go back to dog vision wow you can kind of see how they look pretty similar.
Especially that part on the back those two they're see how that's black there and that's black they're
seeing kind of say oh look at these puppies this is a beautiful thing about working on a project of
vision you get to look at dogs so you can kind of see where that's going wrong.
Let's look at one more.
My other favorite number is seven.
So why not seventy seven
and I got that one right.
That's really confident.
That's awesome.
A grow grow and grow in India.
Mm hmm.
Well this is very exciting because now we're actually seeing our model's predictions compared to actual
images dog vision is officially coming to life.
This is the kind of functionality we wanted from the very start to be able to pass our model and image
and it make a prediction.
And now we're seeing how confident it is on that prediction.
So prediction probability or confidence interval and we're actually comparing it to the real label.
So this is an image because it's from validation dataset and image our model has never seen before.
So you better pat yourself on your back because you've just felt a deep learning model that's able to
take photos of dogs and predict what kind of breed it is.
That's pretty cool.
Now one more thing we'll probably do to visualize a little bit more is see what other labels our model
predicted because there's prediction probabilities for every label.
It would be interesting to know what other dog breeds our model looked at an image and thought it was.
So this one's 96 percent so it's pretty darn confident on it that it's a growing N Dale breed of dog.
I can't even pronounce some of these breeds of dogs.
Well let's do that in the next video.
Hey we'll create a plot to show the top 10 predictions.