‫Roddy 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 right, 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 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 models 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 end goal?
‫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 colour in our lives.
‫Okay.
‫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 that image.
‫That's what we can use.
‫Map, plot, lib, something like that.
‫Take an array of image values which we've got here.
‫Maybe a good thing we worked towards is it plots the predicted label its predicted probability so the
‫max value up here so something like this.
‫So this is 75% and then it's actual label.
‫I think we can get them all onto a single plot.
‫Maybe we'll write that down.
‫So we don't confuse ourselves.
‫Remember the rubber ducky technique from my boy, Ron?
‫Thanks, Ron.
‫We'll create a function which
‫takes an array of prediction probabilities, an array of truth labels, and an array of images and integers.
‫Now, again, I want to stress I'll say it till I go hoarse, 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 going to go convert the prediction probabilities.
‫Of course, you may need to use some other visualization techniques that aren't map plot 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 truth label and the target image on a single plot.
‫Okay.
‫So how might we do that?
‫Let's go here.
‫We'll call it def.
‫Something simple.
‫Plot bread.
‫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 so it plots a single image, a single prediction label, and a single truth label and
‫an integer.
‫So maybe we could just save this as nn equals one.
‫That's going to air out because we've got nothing there.
‫That's all right.
‫Get rid of that error.
‫We don't like seeing them.
‫Like it caused me a little bit of stress.
‫So we go here, give you the prediction.
‫Ground truth and image for sample MN.
‫And again, getting trigger happy, right?
‫It's like almost instinct for me to press shift and enter whenever I finish writing a line of code.
‫Okay.
‫So the first thing we'll need is the PRED probe.
‫It's actually a prediction probability, but i'm not typing that multiple times through label and the
‫image.
‫So this is going to equal.
‫Remember, we want the nth sample.
‫So we do have to actually type prediction probabilities.
‫N So the index, so the EMF sample and then we want labels and, 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 pred label.
‫Now that we have 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 tics because
‫we just want to square images.
‫We don't want axes.
‫Dot m show image.
‫So this is a map plot lib function.
‫You pass it an umpire ray if it's an image, display an image, i.e. data on a 2D regular raster far
‫out.
‫Sometimes Doc strings are written in a in a complex way, like it could have just said plot an image
‫and y tics.
‫So this is just empty lists.
‫So we're just turning them off.
‫And basically it's just going to show nothing because there's nothing in that list.
‫We might need the plot title.
‫You're right.
‫Change.
‫Plot.
‫Title.
‫To be predicted.
‫What predicted?
‫Liable probability of prediction and truth.
‫Label, sir plt title.
‫Now we've got our prob, we've got our true label and we've got our bread label.
‫So we're just going to have to create a string of three of these.
‫So 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.
‫A better example is not something long like this, it's a percentage.
‫So rather than being that it's 75%.
‫That's what we're after.
‫Come down here, we'll just do a little format.
‫And we'll go to Red Label because that's the first one.
‫So prediction is there.
‫And then we want Npj Max.
‫Pred prob.
‫Times 100.
‫Times 1000.
‫Whoa.
‫So this is just going to be.
‫The prediction probability value.
‫So the max of this of the PRED probe three times 100.
‫So when we saw 0.75 up before, it's just going two times that by 100 might not be 0.75 because it'll
‫be a different value for each different image.
‫There we go.
‫And we want to label is the last one.
‫So does that make sense?
‫So plot title.
‫I want to get rid of that pass.
‫Plot title squiggly brackets for red 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 up.
‫We need another one.
‫Plop, Fred.
‫Okay.
‫And now let's go.
‫Plot, Fred, we want predictions.
‫On prediction, probabilities equals predictions.
‫And then we want labels equals VAL labels and images equals VAL images.
‫So this is just from upper before where we on batch ified our validation data set we've got here.
‫And let's come down.
‫Let's test out our little function.
‫Oh.
‫Now our labels are printing out incorrectly.
‫What's happened here?
‫True labels equals bread label.
‫Get Fred prob.
‫What is happening here.
‫True label.
‫Hmm.
‫Well, 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 function to be unique breeds and this is going to be
‫np r 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, but we might save that just for
‫predictions.
‫So this is going to get the unique Breed's MP max label.
‫We need to rerun this.
‫So make sure you update your on batch of fire function.
‫And then if we rerun this, this should be correct.
‫And then if we rerun this.
‫Oh yeah.
‫Scott Terry are 68% correct.
‫This is not very intuitive.
‫What if someone was looking at this and it was like Scotch Terrier, 68% Scotch Terrier.
‫Which one is the predicted and which one is the non-protected?
‫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.
‫Oh, that looks disgusting to me.
‫Oh.
‫Ah.
‫See, I'm Australian and we spell colour.
‫Oh, you are.
‫So whenever I see.
‫Oh.
‫Ah.
‫Even though that's the actual little parameter that we have to pass to format.
‫I don't like it.
‫Colour 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.
‫Trade label equals true label.
‫We want color equals green.
‫Else color equals red.
‫And then we're going to pass a little parameter here.
‫So it's all about making our plots more visual.
‫Oh.
‫What?
‫What is that change?
‫If private label equals true label.
‫Oh, 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% beautiful.
‫Now, remember, this is predicting for index one.
‫So what we might do is just make sure it works on another image.
‫What's our favourite number?
‫42.
‫Oh, they got that one wrong.
‫That's a good example, actually.
‫It's pretty confident.
‫76% it predicted walk around, but it's actually an English fox hound.
‫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 there.
‫So you can kind of see, oh, look at these puppies.
‫This is a beautiful thing about working on a project dog vision.
‫You get to look at dogs.
‫So you can kind of say where that's going wrong.
‫Let's look at one more.
‫My other favorite number is seven.
‫So why not 77?
‫And I got that one right.
‫That's really confident.
‫That's awesome.
‫A grow, grow and grow in India.
‫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 data set an image our model has never seen before.
‫So you better pat yourself on your back because you have just built 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 it 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%, so that's pretty darn confident
‫on that.
‫It's a grown in day, all breed of dog.
‫I can't even pronounce some of these breeds of dogs.
‫Well, let's do that.
‫In the next video, we'll create a plot to show the top ten predictions.