‫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 in TensorFlow, but one of the best ways to get started is to use the TensorFlow
‫carer's API, which is a recent addition to TensorFlow 2.0.
‫So if we go TensorFlow carer's, we just Google that.
‫There we go.
‫Carers TensorFlow core.
‫Here we go.
‫HTF carers is tensorflow is 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 composable.
‫Yes.
‫Easy to extend.
‫This would probably be a good resource to link.
‫I'll link this in the resources 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 or the Q&A is what is the difference between
‫carer's sequential and where is 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 TensorFlow guide, carers overview for 10 minutes.
‫And the question you got to answer the difference between sequential and functional API, but let's
‫not waste any time there.
‫Let's get hands on with the code.
‫And the beautiful thing about carers is that 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 in 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 going to 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, if 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.
‫I do this first, then this, then that.
‫So it's just like a linear step by step process.
‫Here's the inputs, here's the middle layer, here's 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.
‫Hmm.
‫We haven't seen that one before.
‫That's a new term.
‫Don't worry, we're going to 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 got this one from builds the model we can come up here into.
‫Oh we closed it so TF Hub Dev.
‫If we go here.
‫Back to mobile net to.
‫This is that step, their 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 going to load it 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 carers model.
‫So def create model.
‫This is our own custom function.
‫This is what we want to get used to writing.
‫So it's going to take input shape.
‫Which is just there.
‫Wonderful output shape equals output shape and then it's going to take model URL.
‫This is handy because if we wanted to change the model we were using, we could just update the model
‫URL 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 building model with.
‫Just the model URL here and now we're going to set up the model layers.
‫So model equals TF carer's dot sequential.
‫And then we want to write Hub Scarers Layer.
‫And we're going to pass it.
‫Model URL.
‫So this is layer one, the input layer.
‫And then after that we want to do HTF carers.
‫Not layers, not dense, and then the number of units equals our output shape.
‫And the activation, which is a word you've probably haven't heard before, equals soft Macs.
‫Layer two.
‫This is the output layer.
‫Now.
‫Just bear with me if you don't understand it.
‫That's all right.
‫We're going to go through it.
‫This is just practicing writing the code.
‫I'd like that to be over here, actually.
‫I have a strange feeling.
‫CoLab 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.
‫I want you to just have.
‫Actually, that looks a bit better.
‫If it's over here, that's a bit more Python esque.
‫Just when 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 carer's losses, categorical cross entropy.
‫Wow, that's a big word.
‫So.
‫Right, if it's confusing to carers, the optimizer.
‫What is an optimizer.
‫Adam.
‫And then metrics.
‫This one will be familiar for sure because we're working with classification accuracy.
‫Whew.
‫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.
‫Shows us our URL.
‫What have we missed here?
‫No attribute optimizer optimizers.
‫There we go.
‫What else have we got wrong?
‫Oh.
‫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 in a little bit of a cliffhanger because in the next one 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.