Hello, everyone, and welcome to this new and exciting session in which we are going to treat and sampling.
So up to this point we've been treating models separately.
That is, we build a resonant model, train this model on some inputs and outputs and then later on
expect to pass an input and get an output which corresponds to the input we passed in.
Now, on the section on assembling, what will be building here will be an ensemble or a group of different
models which will be put together to form one model or one block, such that now we pass our input and
then we get our output wherein this output here is a weighted sum of all the individual outputs delivered
by each and every model.
So in this section we are going to look at this rest net 34 and this Pre-trained model is actually an
efficient model.
We could see this right here and we'll build and assemble a group or family of models from this to models
which we have already built.
Just before we start, it's important to note that we've already trained this Resnick 34 model and this
Pre-trained model based on the efficient net model.
So we have these two models and we want to create this ensemble of the matter of these two models here.
Now, we should note that after evaluating these two models, we got 84.1% accuracy and 82.9% accuracy
for the rest net and pre-trained models respectively.
So now to create this ensemble, we're just going to simply start here and define our input.
We have inputs, which is TensorFlow input, and then we specify the shape.
So we have our shape, your configuration and size.
There we go, we have the size, and then we put this orders here.
So we have this shape which is specified.
And then once we have the shape specified, we will have to outputs.
Let's call this 1y1, which is from the rest net 34, it takes in the inputs and then we also have this
other 1y2 from the Pre-trained model.
So pre-trained model, text and inputs.
Here we should have inputs and that's it.
Now once we have this to outputs, what we are going to do here is we're going to create this ensemble.
So we'll call this ensemble model.
And it's a model, a TensorFlow model which takes in some inputs, which is actually these inputs here
inputs, and then also the outputs.
Now for the outputs, we're going to define it here.
Let's let's call this output.
So we have our output.
And this output is a linear combination of these two models output here.
So here we have 0.5 times Y one plus 0.5 times Y two.
So that's it.
So we have this output now and then here outputs equal output.
So that's fine.
So we have this ensemble model, we run this and that should be fine.
This is okay.
Now let's go ahead and evaluate this model.
But before evaluating this model, you should compile it so we could get your and simply do this, so
we could do ensemble model compile and that should be fine.
So we have the ensemble model compiled now we'll take this off because we just wanted to do this for
testing or to create that sample actually.
So we have this ensemble model which we've created, and then now that we have this ensemble model created,
let's go ahead and evaluate this model.
So let's create a code.
So your copy this passes out here and we have the ensemble assemble model.
Okay, So we have that.
Now let's evaluate the model and see what we get.
There we go.
We see we have a slight improvement from this higher accuracy.
Here we go from 84.1 to 84.43.
So this means that this ensemble model, which the combination of these two models is now better performing
than each and every one of them.
It should be know that this one was trained for 2040 epochs and this was trained for only 20 epochs.
So if you train this longer, you should.
Get results even better than this and and better still than sample model should perform even better
than the two.
And so with this, we've just seen the how to carry out and sampling with TensorFlow.
And it should be noted that this technique is greatly used, especially in competitions like Kaggle
and Indy, where you are struggling to get the best possible performance.
And so after building or after training several models, you could then combine these models into one
model and see if that gets you a step further in terms of model performance.