‫So now we've got a fully trained model on the full training dataset, aka 10,000 images because if we
‫look at X.
‫We've got 10,000 images and labels.
‫Now let's use our fully trained model to make some predictions.
‫On the test data set, which is also about 10,000 images.
‫We'll have a look at that in a second.
‫But let's come up to Kaggle and see how.
‫They want our predictions to look.
‫So a submission file for each image in the test set, you must predict a probability for each of the
‫different breeds.
‫The file should contain a header and have the following format.
‫So we need ID dog breed one.
‫I'm not even going to pretend I'm going to try to pronounce that once again, Afghan hound, Yorkshire
‫terrier and then the prediction probabilities for all of those.
‫All right.
‫Now it says multiclass log loss.
‫That's just the prediction probabilities for each dog breed.
‫Create another header section making predictions on the test data set.
‫Now I want you to have a think before we go through the code.
‫What did we have to do to train our model on the training images?
‫Again, pretend this is data agnostic.
‫Whatever data you're working with, whether it's text or audio or images or video or something like
‫that.
‫What is our rule before we can use it with a machine learning model?
‫Or in our case, a deep learning neural network.
‫We've got to convert it into numbers.
‫So that's what we have to do, the exact same data type that our model was trained on.
‫So the data batch up here, the data batch of images, we need to create one of those out of the test
‫images so that we can make predictions on those images.
‫So we'll write ourselves a little note since our model has been trained on images in the form of tens
‫of batches.
‫To make predictions on the test data.
‫We'll have to get it into the same format.
‫So if we come back to our graphic and keynote, I remember how I always said we're focusing on the inputs.
‫So getting our data into the right shape for our machine learning algorithm and then making sure the
‫outputs are correct.
‫This is what we focus on in the beginning.
‫This has already been implemented for us in quite a large way.
‫As we get deeper and deeper, as you get into further projects, then you might want to start diving
‫into this.
‫But for the time being and for approaching your first projects like we're doing now, you're going to
‫be focused on inputs and outputs.
‫Now, a little tidbit here is, again, our function's coming in handy.
‫Luckily, we created create data batches earlier, which can take a list of file names as input.
‫If you don't remember, go back up to where we create data batches and convert them into tensor batches.
‫So what steps do we have to do to make predictions on the test data?
‫Let's write those down to make predictions on the test data.
‫Well, now, this is kind of what I do with a lot of my projects is just talk to myself, talk myself
‫through it.
‫The rubber ducky technique.
‫So get the test image file names.
‫That'll involve us writing just a little list comprehension like we've done before.
‫To access the test, go through all the files in here and save the file names to some sort of list.
‫Yeah, we can do that.
‫And then we got to convert the file names into test data batches using create data batches.
‫And setting.
‫The test data.
‫Remember how we created parameters to create data batches?
‫If you don't, that's okay.
‫We're going to see in a second parameter to true because why?
‫What's different about our test data to our training data?
‫There's no labels with the test data.
‫So since the test data doesn't have labels and then finally we make a predictions, a predictions array
‫by passing the test data batches to the predict.
‫Method called on our model.
‫Woo!
‫We got three steps there.
‫But we can do them.
‫We can tackle them one by one.
‫How about we start with the first one?
‫That's pretty logical.
‫Load test image file names.
‫What could we do?
‫We could go test file names.
‫Nice and simple equals.
‫Actually, you might set up the test path.
‫How about we do that?
‫Test path equals.
‫And we'll just copy it here to save us writing it out twice.
‫Copy path.
‫That's a little handy tip.
‫You can do that.
‫You can paste.
‫We don't need content.
‫We could just keep it there if we wanted to, but I'm going to remove it.
‫So it's consistent with the other paths that we have.
‫And I'm going to put this one here.
‫So that's my path to the test folder.
‫So now we're going to go create a little list.
‫Comprehension equals test path plus f name file name for f name in o's dot list dir.
‫Test path.
‫Now we've seen this before when recreating the original training file names, but let's just remind
‫ourselves what it's doing.
‫So O's dot lister is just going through or this directory.
‫That's what it's short for.
‫It's just saying, Hey, Python, get me all of the file names in this folder and then we're creating
‫a list which appends the test path, which is this or adds together the test path, plus every single
‫file name in.
‫The test folder.
‫Let's have a look.
‫If in doubt, run the code.
‫Wonderful.
‫So now we've got the file names towards our test data.
‫We can take that off.
‫Get out green tick emoji.
‫This notebook is going to be filled with them by the end.
‫Okay, now we've got it.
‫What's our next step?
‫Convert the file names into test data batches using create data batches.
‫Oh, I said date there.
‫That's wrong.
‫There we go.
‫Fix it up.
‫First of all, let's just do a little length check of our test file name, see how many images we have.
‫10,357.
‫Wonderful.
‫So now to create a data batch, it's pretty simple.
‫We just bring in our function.
‫We go test data.
‫We'll write a comment here before we get started.
‫So create test data.
‫Batch.
‫And we're going to go create data batches.
‫Oh, it knows what we're talking about and then we're going to pass it the test file names.
‫And we're also going to see there's our test data plane.
‫So we go test data equals true.
‫And we'll run that.
‫Wonderful.
‫We get a little print out saying creating test data batches.
‫Such a great function that we wrote.
‫Let's come up here and have a look at it again.
‫Turning our data into batches.
‫So we've got a function create data batch or create data batches.
‫And what does it do if it's test data, which it is, it prints out this little statement and then it
‫goes, Hey, turn our file names into tenses and then use from tens of slices to convert it into a tensor
‫data set and then create a data batch by mapping the process image function.
‫Remember, we don't pass get image label to the test data set because there's no labels with the test
‫data set.
‫So we process our images just like we did on the training data, and then we turn it into a batch,
‫in our case, batches of size 32 so that it can be computed really fast on with our GPU.
‫So let's come back to where we were.
‫That's what we've got.
‫And if we go test data.
‫It's a bad data set of shapes.
‫So there's no labels here.
‫These are just images of 2 to 4 by 2 to 4 by three for the color channels of type TensorFlow float.
‫So beautiful.
‫We've got our test data in the form of tensor batches.
‫That's what we're after.
‫And now the finale, we can come up here, see how handy writing our functions to begin with has helped
‫us out.
‫We've created a form model, we've created a data batch in one hit.
‫Now we're going to make a predictions array.
‫So how can we do that?
‫Make predictions on test data batch using the loaded full model.
‫All right.
‫So test predictions.
‫Equals loaded full model dot predict.
‫Test data.
‫We're going to set this to four bows equals one.
‫Excellent.
‫Now, I kind of have to warn you that this is going to take a fairly long time.
‫Reason being is because let's put a little note here before we run this cell note calling.
‫Even though we're running on a CPU.
‫This is just like training our phone model.
‫So calling predict on our full model and passing it.
‫The test data batch will take a long time to run.
‫And then it's going to be something like about an hour.
‫We'll just go about one hour.
‫That's what I found anyway.
‫Reason being is because we have another 10,000 images here.
‫And what we have to do is get our loaded four models.
‫So all of the patterns that our loaded full model has learned in the training data set.
‫It has to go through those process.
‫The 10,000 images in our test file names or our test data batch.
‫And then make predictions on those based on the patterns it finds in that test data.
‫So we've set verbose equal to one so that when we run this, it's going to give us another little time
‫step to update us about what's going on.
‫So without any further ado, let's run this.
‫And wait for it to load and then we'll do the same thing again.
‫All speed up the video so it'll be like instantaneously loaded for you.
‫In reality, it'll take you a while to run this cell.
‫In reality, it'll take me a while to run this cell.
‫But I'm just doing it to show you it.
‫Loading up, creating an ETA message, and then going through making some predictions on the test data.
‫So we'll just wait a little while.
‫This is going to go up.
‫There we go.
‫So, ETA, about 38 minutes.
‫It has to go through 324 batches.
‫And so that is because if you go 10,357 divided by 32.
‫It's going to round that up to 324.
‫That's where that number comes from.
‫Okay.
‫So I'm going to wait for this to go through.
‫You might have to wait for it to go through as well.
‫You don't actually have to wait.
‫I'll be back in a few seconds, so I'm going to pause my video here and I'll be back in three, two,
‫one, and we're back.
‫Now, I've gone and done something a little bit cheeky here.
‫As you see, we've got about an hour left, but I figured you'd rather me sit here and wait for this.
‫I've actually, like any good chef has done.
‫I've prepared a dish earlier, so I've actually gone through this process and waited the full one hour
‫to go through.
‫And now you could wait for yours to go through.
‫But if you'd like to download a pre-made CSV of the test predictions, I'll attach that in the resource
‫section so you don't have to wait that full hour to go through.
‫And now I probably should have told you this before running this cell, but it's a good thing to sort
‫of just get your feet wet and then figure out a better way of doing things.
‫If we wanted this to save test predictions to a CSV file after it runs through because if we waited
‫a full hour for it to go through and then we somehow our runtime disconnected and it didn't save, that'd
‫be pretty disappointing.
‫So what we can do is use np save text this function here to save.
‫Will this load a docstring while this is running?
‫I don't think it will.
‫But what this is going to do, we forgot this spreads array.
‫So let's just say that this finished.
‫If I ran this cell after it, it's going to save test predictions.
‫So this numpy array, which is a prediction probabilities array to this file as a CSV with the delimiter
‫comma four, comma, separated values.
‫And then once it was saved, it's going to appear.
‫In our files as a producer, a CSV, because that's the file name we gave it and then we can use NP
‫load text to load it back in.
‫So what we'll do?
‫Rather than wait for this to finish, I'll just show you that in action.
‫So these are some prediction probabilities that I've made in the past with a full model.
‫So I'm going to stop this had about an hour to go.
‫So again, my estimation is going to take about an hour is incorrect.
‫So keyboard interrupt.
‫There we go.
‫So we're not going to run that because I've already I've already saved this to press array, but I am
‫going to run this.
‫So let's pretend I've run this after this cell has completed.
‫So this ETA has reached zero.
‫So I'm going to load in this array from a CSV file.
‫Beautiful.
‫Now let's have a look at the first ten.
‫There we go.
‫So these are all prediction probabilities for the 10,000 images.
‫So let's have a look at the shape of test predictions.
‫10,357.
‫So that's how many test images we have.
‫And each one of them has 120 different prediction probabilities.
‫Now, we've seen these values before.
‫And so remember, I've just taken this, let it run to its extent, save the CSV to a file that I've
‫done earlier, as if we've cooked something earlier and then I've just reloaded it in here.
‫If my runtime disconnected, I'd want this file to be saved somewhere that I can access it later.
‫And so what's our next mission?
‫If we wanted to submit this predictions array to Kaggle, what would it have to look like?
‫So the sample submission is here.
‫Oh, something went wrong.
‫You're letting your data.
‫That's not very fun.
‫But luckily, I've got this file in dog vision.
‫And it's the same way.
‫And so all I've done is I've just downloaded it and opened it in Google sheets.
‫So this is what it looks like.
‫This is the, the sample submission we need to get our predictions array into something like this.
‫So an ID column and then a column for each of the different dog breeds and then their prediction probabilities.
‫So that's what we'll work towards in the next video.
‫We'll get our prediction probabilities array for dog vision or we're actually going back to the Kaggle
‫dog breed identification format.
‫So we'll get it set up like that so we can make a submission to Kaggle with our predictions.