‫I hope you're ready, because now it's time to train a model on the full data.
‫We verified that everything is working by going through, checking our model's predictions, evaluating
‫them and going, Yep, our model is definitely learning something, but since we've only trained it
‫on a thousand images, let's see if we can try in a full scale model like our first full blown deep
‫learning model training on 10,000 plus images.
‫And this is where the power of the functions that we created earlier are really going to come into play.
‫So let's make a little heading for ourselves.
‫Training a model, actually, let's call it training a big dog model.
‫And we might put a little moji here.
‫On the full data and you get it.
‫It's a big dog model because we're training on lots of images of dogs.
‫I love this project now.
‫Cut.
‫What we need is remember right at the top.
‫If you don't, that's okay.
‫We're going to have a look at it now.
‫We have X and y, len x, len y and this is all of our training data.
‫These are the file names and these are the labels.
‫So if we come up here, X is all of the file names in train.
‫So if we have a look at the first maybe ten of X, ten of X.
‫These are all our training image file names.
‫We split these before into X train, which is only 800 in length.
‫There we go.
‫So if we have a look at land X train.
‫Only 800 images.
‫So at the moment our model has only trained on 800 images.
‫And if we want to have a look at why, why is the labels associated with each file path?
‫In the form of Boolean arrays.
‫So what do we need to do to train a full model?
‫If we come back to our keynote, what's our workflow?
‫Get data ready.
‫Turn it into tenses.
‫Well, we've got a function for that.
‫Do you remember?
‫Create data batches.
‫If you don't, it's all right.
‫We've created a function for that and we got pick a model to suit your problem.
‫So TensorFlow hub, we've got that we can just use create model and then fit the model to the data and
‫make a prediction.
‫Let's give it a crack.
‫So let's go create create a data batch.
‫With the full data set.
‫So this is where functions really help out is later on in your notebook.
‫I told you it was worth it for data equals.
‫Create data batches.
‫Look at this.
‫This is our function that we've written above.
‫Creates data, batches of data of image x and label y pairs.
‫Beautiful shuffles of data.
‫If it's training but doesn't, well, that's a bit of a hindrance.
‫We can't see that also accepts test data as input.
‫No labels.
‫So that's alright.
‫This is not training data.
‫So let's create a full data data batch.
‫Now we have a look at full data.
‫It's a batch data set.
‫Beautiful.
‫With images and labels.
‫Wonderful.
‫And if you're wondering what create data batch is actually does, let's go right back up if we have
‫a look at our index here, what are we doing?
‫Visualizing data batches turn our data into batches.
‫So here's our big function create data batches.
‫It takes X and Y.
‫And here's what's happening.
‫This is because it's a training data set.
‫Creating training data batches turns X and Y into tenses.
‫It shuffles them and then it maps our processing image function as well as get label function to the
‫data.
‫And then it turns the data into a batch size of 32.
‫But we've already seen a video on on this.
‫So if you need a refresher, go back and check out the video where we created this function.
‫So let's come back to where we were.
‫So now we've got our data back.
‫What's the next step?
‫Well, we need a model.
‫So let's do create a model for full model for model equals create model.
‫Remember what I create.
‫Model function did.
‫Oh, no docstring.
‫Hmm.
‫Well, let's run that anyway.
‫We can go check it out.
‫So building a model with TF Dev image net mobile nat v2.
‫So we've got a model.
‫Okay.
‫We've got a batch dataset and we've got a model.
‫Now, if we want to check out what create model does, where is it building a model?
‫If we come down here, this is our create model function.
‫Ah, it doesn't have a docstring.
‫Maybe that's something you could add.
‫So you create a function which builds a carer's model.
‫So what it's going to go through is go through the steps that it took before to create a carer's sequential
‫model using the model we downloaded from TensorFlow hub and a dense layer on the top to make sure our
‫outputs are the same size as the labels that we have.
‫It's going to compile the model with a loss function and optimizer, which our friend Adam, the guy
‫at the bottom of the hill telling us how to descend down the hill at the International Hill Descent
‫Championships and metrics is accuracy is what we're what we're measuring.
‫And then we're building the model feeding at the input shape, which is the size of our image.
‫Wonderful.
‫Come back.
‫So how might we train this?
‫What's next?
‫What do we do next?
‫Well, we created some callbacks, so we might have to make some specific callbacks for our for our
‫model.
‫So let's do that.
‫Let's go create full model callbacks.
‫Full modal tense aboard equals.
‫Create tents aboard.
‫Go back.
‫There we go.
‫There's our function from before to create a tensor board callback.
‫Remember, the tensor board callback helps us to track the performance of our model and compare it to
‫others.
‫And so there's no validation set when training on all the data.
‫So with our early stop and callback, we can't monitor validation accuracy.
‫So for our early stopping callback, we need for model early stopping.
‫Equals tfw carers dot callbacks dot early stopping.
‫There we go.
‫And we're going to get it to monitor accuracy when our model is shining on the full data, when its
‫accuracy stops going up for three epochs.
‫We're going to get it to stop training so it doesn't overfished or we're going to try and prevent it
‫from overfitting too much.
‫So shift and enter.
‫Wonderful.
‫Seems like we might have a recipe to to start training our model so fit the full model to the full data.
‫So here's where we can go.
‫We can go full model dot fit.
‫So we're just calling the model we created.
‫Dot fit x equals the full data.
‫Now there's no validation set, remember, because we're training on the full data.
‫Epochs is going to be 100.
‫Or it could just be num epochs because we've set num epochs before and we're going to have callbacks,
‫which are the two callbacks we've just created.
‫Now this is just doing the exact same steps as what we've done, training a smaller model, but this
‫time with more data.
‫Wonderful.
‫And now I'm going to put a little note here to give you a little heads up and well, I'm going to speak
‫it out.
‫So you know as well.
‫Running the cell below will take a little while, maybe up to 30 minutes or maybe a little bit longer,
‫30 minutes for the first epoch because the GPU we're using in the runtime has to load all of the images
‫into memory.
‫So the first epoch, remember, with our smaller model on 1000 images, the first epoch took a couple
‫of minutes, maybe three or 4 minutes, as you could imagine, because this one is on the full data
‫set.
‫It's training with 10,000 images.
‫So it's going to take a little bit longer to load all of the data for the first epoch.
‫So before we run this, as long as every all the code is correct, actually it might error out.
‫That's why rather than trying on the full data from the beginning, we've made sure everything works.
‫Because when training a full machine learning model, a full, deep learning model.
‫It can take a fairly long time and hours.
‫We're pretty lucky here.
‫This is going to train within an hour because we're using a GPU.
‫But you could imagine if you're working at a bigger company, you might leave something training for
‫a week.
‫So that's why you want to make sure that when you set up experiments, imagine training a deep learning
‫model for a whole week, and then it turns out that it wasn't working.
‫So that's why we did all of the steps above to make sure that everything's working.
‫So before we train a massive model, we can be sure, okay, things are in place.
‫Let's kick off a full training round.
‫So you're ready?
‫We're about to train our first full blown, deep learning model on 10,000 plus images.
‫Dog vision is truly becoming a reality.
‫Hate it with me.
‫Three, two, one.
‫Shift and enter.
‫Fingers crossed.
‫Hopefully this works.
‫We should see a little loading bar come up and because we've set number of epochs to 100, it's going
‫to keep training for up to 100 epochs.
‫But if it stops improving, we've got our full model early stopping callback.
‫That's going to stop at training early and then we can check the results using tenths of order after
‫it's finished.
‫So we'll just wait for this to kick off.
‫And then what I'll probably do is pause this video because it's going to take about half an hour.
‫I'm going to take a little break, maybe you could, to have a little walk around, chill out.
‫Oh.
‫Maybe it's going to take a little longer than half an hour.
‫This time I should go down unless my testing is incorrect.
‫But we'll wait a few seconds and then I'll come back to this video once the model has stopped.
‫So once the model early stopping the full model early stopping callback has kicked in.
‫Okay.
‫So I'm going to let this run for as long as it needs to run.
‫I'll come back once my model has stopped itself, thanks to the early stop and call back.
‫So I will see you in a couple of seconds, but for me, it's going to be a couple of hours in the future.
‫Maybe it's a couple of hours in your future as well.
‫And we're back.
‫Alrighty.
‫So let's have a look at our fully trained model.
‫As you can see, my first epoch took a fairly long time and this is actually going to take a moment
‫if you finish this, if you've gone through this.
‫You need to pat yourself on the back because this is like a rite of passage training your first and
‫and deep learning neural network.
‫And it's taken a long time.
‫One of the things you'll have to figure out when you become a data scientist or machine learning engineer
‫is ways to pass the time whilst your model trains.
‫So I went for a walk with my dogs because this took one.
‫How many seconds is that?
‫So 4730 divided by 60.
‫78 minutes.
‫So just over an hour to do the first epoch.
‫But as I said, after the images are loaded into the GPU's memory, check out how fast it goes after
‫that.
‫And what you'll probably want to do is as this cell is running, I should have told you this before,
‫but you can take note for the future.
‫As this cell is running, you want to have a save model running after it.
‫That way, once your model stops training.
‫Thanks to early stopping our early stopping call back up here.
‫It's going to automatically call our save model function and save our full model to our models directory.
‫Now let's come up here and have a look into models.
‫Oh, I've got a few there.
‫So let's say it's going to be the one with the there we go full image set mobile net 2nd of February
‫and I started at about 5 p.m..
‫So this time is actually wrong for me because I'm not sure.
‫Maybe date time is getting the wrong time for me.
‫But there we go.
‫That saved here.
‫We've got our path.
‫So now we can have a look at what actually ended up doing pretty well.
‫Look at that.
‫That's training accuracy.
‫But I'm a little bit skeptic here.
‫You know why?
‫Because we aren't validating this.
‫This is just a model training on the full training data.
‫So let's come here.
‫It's training on all the images in this trained file, a.k.a. X and Y.
‫And so we can't really test on a validation set, but what we can do is import the test data set that
‫we originally downloaded from Kaggle.
‫Here we go, the test file.
‫And we can import those, turn them into a data bunch, and then use our model to make predictions and
‫submit them to Kaggle.
‫How epic is this?
‫So let's our model is saved.
‫Let's test our our load model function.
‫So loaded for model equals load model.
‫We're just going to copy this path here.
‫Okay.
‫They're loading the full model.
‫And if we copy this line here.
‫Tick.
‫Oh, we don't want to put it there.
‫We want to put it in here as a string.
‫Let's check that out.
‫Wonderful.
‫That's going through.
‫That's what we're after.
‫So again, we're getting those warnings that the TensorFlow documentation says can be ignored.
‫All righty.
‫Now what's next?
‫Well, I think now that we've got a fully trained model on all of the 10,000 plus images, I think we
‫see how to make some predictions on the test data set.
‫So let's do that in the next video.