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 models predictions evaluating them and going Yep our model is definitely
learning something.
But since we've only trained it on 1000 images let's see if we can train a full scale model like our
first full blown deep learning model.
Training on 10000 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 it might put a little merger 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 code what we need is remember right up the top if you don't that's okay.
We're gonna have a look at it now.
We have X and Y land X land y and this is all of our training data.
These are the file names and these are the labels.
So we come up here X is all of the file names in train so if we have a look at the first maybe 10 of
x 10 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 eight hundred images.
So at the moment our model has only trained on eight hundred 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 Kino 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 right.
We've created a function for that and we got pick a model to suit your problem so it tends to flow.
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 the data if it's training but doesn't.
Well that's a bit of a hinderance we can't see that.
Also accepts test data as input no labels so that's alright right.
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 dataset beautiful with images and labels.
Wonderful.
And if you're wondering what create data batches actually does.
Let's go right back up.
If we have a look at our index here what do we do on 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 dataset creating training data batches turns.
X and Y and tenses it shuffles them and then it maps out processing image function as well as get labeled
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 there 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 batch.
What's the next step.
Well we need a model so let's do create a model for full model form model eagles.
Create model mean what I create model function did no doctoring.
Mm hmm.
Well let's run that anyway.
When go check it out.
So building a model with TFR that Dev image net mobile Net V2.
So we've got a model.
Okay.
We've got a batch dataset and we've got a model.
Now if you 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.
It doesn't have a doctorate.
Maybe that's something you could add.
So create a function which builds a carer's model.
So what it's gonna go through is go through the steps that it took before to create a carer's sequential
model using the model we downloaded from tensor flow 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 gonna 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 comeback.
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 models
so let's do that let's go create full model callbacks for model tensor bald eagles create tensor board
callback there we go there's our function from before to create a tense a 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 without early stopping callback we can't
monitor validation accuracy so for out early stopping callback we need full model early stopping equals
T F carers callbacks don't early stopping there we go and we're gonna get it to monitor accuracy when
our model is training 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 over fit all we're going to try and prevent it from overheating
too much.
So shift and enter wonderful things 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 not 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 numb epochs because we've set Naam epochs before and we're gonna 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 put a little note here to give you a little head's up.
And while 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 GPA way
using in the runtime passed to load all of the images into memory.
So the first epoch remember without smaller model on a thousand images the first epoch took a couple
of minutes maybe three or four minutes as you could imagine.
Because this one's on the full data set it's training with 10000 images.
So it's gonna 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 codes correct actually it might error out.
That's why rather than train on the full data from the beginning we've made sure everything works.
Because when training a full machine learning motor a full deep learning model 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 GP you 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 10000 plus images dog vision is truly
becoming a reality here with me.
Three to one shift and into 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 tensor board 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 gonna take a little longer than half an hour.
This time it should go down unless my testing is incorrect.
But 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 stopping callback so I will see you in a couple of seconds.
But for me it's gonna be a couple hours in the future.
Maybe it's a couple hours in your future as well.
And we're back.
All righty.
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 let's take a moment if you finish this.
If you've gone through this you need to put yourself on the back because this is like a rite of passage.
Training your first end and deep learning neural network and it's taking a long time.
One of the things you'll have to figure out when you become a data scientist or a 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 four thousand seven hundred thirty 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 jeep use memory checking out how fast it goes after
that and what you probably want to do is as this cell is running I should've 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 callback 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 see it's gonna 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's saved here.
We've got our path so now we can have a look.
Our model 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 train file.
Okay.
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 out our load model function so loaded for model equals load model.
We're just gonna copy this part here
we'll go there loading the full model and if we copy this line here
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 tensor fly 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 10000 plus images I think we see
how to make some predictions on the test dataset so let's do that the next video.