Now we've got the inputs outputs and model we're going to use ready to go.
We can start to put them together.
And one of the ways that we're going to do that is well one of the things to remember is there's many
ways of building a model intensive flow.
But one of the best ways to get started is to use the tensor flow carer's API which is a recent addition
to tensor flow 2.0.
So if we go tensor flow carers we just google that.
There we go.
Carers tens of local Here we go.
TAF carers is tensor flows high level API for building and training deep learning models.
That is what we're after.
It's used for fast prototyping State of the art research and production with three key advantages user
friendly yes modular and compose well.
Yes easy to extend this would probably be a good resource to link I'll link this in the reasons section.
It's not a little bit of homework for yourself is to just have a read through this after this video.
Maybe go through it for about 10 minutes or so.
The question I want to ask and leave a message in the discord all the Q and A is what is the difference
between carers sequential and whereas functional and functional so that's what I want to know the difference
between the carers sequential API and the functional API as a spoiler.
We're going to be using the sequential so go through the carers tensor flow guide carers overview for
10 minutes and the question you go to answer the difference between sequential and functional API.
Well let's not waste any time there.
Let's get hands on with the code and the beautiful thing about carers is at defining a deep learning
model can be as straightforward as saying hey here's the layers of the model a.k.a. let me go back to
this little graphic.
When I say layers often a neural network.
These are what are referred to as layers.
So you'll have an input layer which will be here okay.
This one then you'll have some sort of other layer here which is often referred to as a hidden layer
which is gonna find some patterns and then an output layer.
So that's what I mean by layers.
And so in carers it's kind of as easy as going hey here are the layers of the model the input shape
the output shape let's go.
So let's create a function that does that.
So what we might do is write out we'll make a little markdown cell.
Change this into markdown.
Now we've got our inputs outputs and model ready to go.
Let's put them together into a carer's deep learning model.
Wonderful.
Now remember how right at the start we said we want to start getting functional about what we're doing.
So we could write out the code line by line but we're going to put it into a function.
So we go knowing this let's create a function which we go here takes the input shape output shape and
the model we've chosen as input or as parameters.
That's probably a better word to say and we go defines the layers in a carer's model in a sequential
fashion.
Okay do this first then this then that.
So it's just like a linear step by step process he is the inputs he is the middle layer his the output
layer.
So just running sequentially from left to right or in in deep learning you often run like from top to
bottom.
We'll see that in a moment and then we go here compiles the model says how it should be evaluated and
improved.
We haven't seen that one before.
That's a new term Don't worry we're gonna go through it and then we want to build the model tells the
model the kind or the input shape better that's better the input shape it'll be getting and then finally
returns the model.
That's a fair few steps in there.
But we can do it.
And if you're wondering where I've got this one from builds the model we can come up here into oh we
closed it CTF hub Dev go here back to mobile Net V2 this is that step there m dot build but we'll see
this in a moment.
And if you're wondering where any of these other steps are you could pause this video and have a read
through this even if it doesn't make sense don't worry because we're gonna coded up in a second.
Have a read through this and then come back here if not if you don't want to read through that we'll
just keep going with the code here we'll go here.
All of these steps can be found
here.
This is just a way of documenting for our own sake.
All right so let's let's write the code first and then we'll discuss each part.
I think that's a better way to go.
So create a function which builds a carer's model.
So def create model.
This is our own custom function.
This is what we want to get used to writing.
So it's gonna take input shape which is just their wonderful output shape equals output shape.
And then it's gonna take model U.R.L..
This is handy because if we wanted to change the model we were using we could just update the model
you are all variable and if we wanted to similarly change the input shape and the output shape we could
we could also change those later on.
So print we just want to find out what model we're using.
So let's hope building model with just the model you are L here and now we're going to set up model
layers so model equals t after Kerry's dot sequential
and then we want to write hub dot layout layer and we're going to pass it model U.R.L.
so this is layer 1 the input layer
and then after that we want to do.
TMF Kerry's layers don't dance and then the number of units equals our output shape.
And the activation which is a word you probably haven't heard before equals soft Max
layer to.
This is the output layer.
Now just bear with me if you don't understand it that's all right we're gonna go through it.
This is just practicing writing the code.
I'd like that to be over here actually I have a strange feeling collab uses two spaces instead of four
spaces but we'll find out in a moment.
There we go.
That looks a bit better.
So without even discussing what's going on there.
Want you to just have are actually.
That looks a bit better if it's over here.
That's a bit more python.
So I would just want you to have a think about what's happening here.
And if you wanted to help your thought process don't forget you can always read through here.
So now we want to compile the model again a term we haven't heard but we're going to discuss these shortly.
So compile we just want to get used to writing this sort of code.
So this is just instantiating a model and this is putting the model together essentially so carries
dot losses dot categorical cross entropy.
Well that's a big word.
So right.
If it's confusing to after carers the optimizer what is an optimizer.
Adam.
Adam and then metrics.
This one will be familiar for sure.
Because we're working with classification accuracy.
And then finally you want to build the model so model to build input shape
and then we're going to return model
so now let's run the code if in doubt run the code.
So model equals create model we can use all of the default parameters and then we're going to go model
dot summary
building model choses say you are.
What have we missed here.
No attribute optimizer optimize Zeus.
Now we got.
What else have we got wrong.
All what is this.
We haven't seen this before.
In fact a lot of this we haven't seen before but we're going to end this video on a little bit of a
cliffhanger because in the next round we're going to go through this and discuss it.
But in the meantime I'd like you to rewrite this at a bare minimum for yourself and to have a think
about what's going on here.
Also check out this.
What do you think we've done here and after you've written the code and after you've gotten this output
read a little bit through here especially the sequential model section and see if you can relate it
back to what we're doing here.
But otherwise I'll see you in the next video and we'll go through what's happening here.