1
00:00:00,450 --> 00:00:06,520
Now we've got the inputs outputs and model we're going to use ready to go.

2
00:00:06,630 --> 00:00:08,570
We can start to put them together.

3
00:00:08,910 --> 00:00:14,190
And one of the ways that we're going to do that is well one of the things to remember is there's many

4
00:00:14,190 --> 00:00:16,590
ways of building a model intensive flow.

5
00:00:16,590 --> 00:00:22,890
But one of the best ways to get started is to use the tensor flow carer's API which is a recent addition

6
00:00:22,890 --> 00:00:24,410
to tensor flow 2.0.

7
00:00:24,840 --> 00:00:30,910
So if we go tensor flow carers we just google that.

8
00:00:30,940 --> 00:00:31,660
There we go.

9
00:00:31,660 --> 00:00:36,160
Carers tens of local Here we go.

10
00:00:36,200 --> 00:00:40,950
TAF carers is tensor flows high level API for building and training deep learning models.

11
00:00:40,950 --> 00:00:42,720
That is what we're after.

12
00:00:42,780 --> 00:00:49,080
It's used for fast prototyping State of the art research and production with three key advantages user

13
00:00:49,080 --> 00:00:52,010
friendly yes modular and compose well.

14
00:00:52,030 --> 00:01:00,460
Yes easy to extend this would probably be a good resource to link I'll link this in the reasons section.

15
00:01:00,600 --> 00:01:05,680
It's not a little bit of homework for yourself is to just have a read through this after this video.

16
00:01:05,820 --> 00:01:09,070
Maybe go through it for about 10 minutes or so.

17
00:01:09,180 --> 00:01:15,540
The question I want to ask and leave a message in the discord all the Q and A is what is the difference

18
00:01:15,540 --> 00:01:26,060
between carers sequential and whereas functional and functional so that's what I want to know the difference

19
00:01:26,060 --> 00:01:30,690
between the carers sequential API and the functional API as a spoiler.

20
00:01:31,100 --> 00:01:37,010
We're going to be using the sequential so go through the carers tensor flow guide carers overview for

21
00:01:37,010 --> 00:01:43,500
10 minutes and the question you go to answer the difference between sequential and functional API.

22
00:01:43,520 --> 00:01:44,990
Well let's not waste any time there.

23
00:01:45,020 --> 00:01:51,290
Let's get hands on with the code and the beautiful thing about carers is at defining a deep learning

24
00:01:51,290 --> 00:01:57,320
model can be as straightforward as saying hey here's the layers of the model a.k.a. let me go back to

25
00:01:57,320 --> 00:01:58,550
this little graphic.

26
00:01:58,550 --> 00:02:01,730
When I say layers often a neural network.

27
00:02:01,790 --> 00:02:04,340
These are what are referred to as layers.

28
00:02:04,340 --> 00:02:07,480
So you'll have an input layer which will be here okay.

29
00:02:07,490 --> 00:02:12,560
This one then you'll have some sort of other layer here which is often referred to as a hidden layer

30
00:02:12,620 --> 00:02:16,430
which is gonna find some patterns and then an output layer.

31
00:02:16,430 --> 00:02:18,570
So that's what I mean by layers.

32
00:02:18,830 --> 00:02:24,080
And so in carers it's kind of as easy as going hey here are the layers of the model the input shape

33
00:02:24,110 --> 00:02:27,050
the output shape let's go.

34
00:02:27,050 --> 00:02:30,720
So let's create a function that does that.

35
00:02:30,770 --> 00:02:35,220
So what we might do is write out we'll make a little markdown cell.

36
00:02:35,360 --> 00:02:38,090
Change this into markdown.

37
00:02:38,360 --> 00:02:46,280
Now we've got our inputs outputs and model ready to go.

38
00:02:47,180 --> 00:02:54,620
Let's put them together into a carer's deep learning model.

39
00:02:54,680 --> 00:02:55,230
Wonderful.

40
00:02:55,880 --> 00:03:01,730
Now remember how right at the start we said we want to start getting functional about what we're doing.

41
00:03:01,940 --> 00:03:07,500
So we could write out the code line by line but we're going to put it into a function.

42
00:03:07,640 --> 00:03:25,720
So we go knowing this let's create a function which we go here takes the input shape output shape and

43
00:03:25,780 --> 00:03:31,330
the model we've chosen as input or as parameters.

44
00:03:31,330 --> 00:03:40,780
That's probably a better word to say and we go defines the layers in a carer's model in a sequential

45
00:03:41,680 --> 00:03:42,330
fashion.

46
00:03:43,170 --> 00:03:47,970
Okay do this first then this then that.

47
00:03:47,980 --> 00:03:54,640
So it's just like a linear step by step process he is the inputs he is the middle layer his the output

48
00:03:54,640 --> 00:03:54,970
layer.

49
00:03:55,150 --> 00:04:02,590
So just running sequentially from left to right or in in deep learning you often run like from top to

50
00:04:02,590 --> 00:04:03,450
bottom.

51
00:04:03,850 --> 00:04:16,540
We'll see that in a moment and then we go here compiles the model says how it should be evaluated and

52
00:04:16,540 --> 00:04:18,080
improved.

53
00:04:18,130 --> 00:04:20,400
We haven't seen that one before.

54
00:04:20,610 --> 00:04:27,240
That's a new term Don't worry we're gonna go through it and then we want to build the model tells the

55
00:04:27,240 --> 00:04:37,530
model the kind or the input shape better that's better the input shape it'll be getting and then finally

56
00:04:37,590 --> 00:04:40,050
returns the model.

57
00:04:40,530 --> 00:04:41,750
That's a fair few steps in there.

58
00:04:41,760 --> 00:04:44,180
But we can do it.

59
00:04:44,380 --> 00:04:50,890
And if you're wondering where I've got this one from builds the model we can come up here into oh we

60
00:04:50,890 --> 00:05:04,870
closed it CTF hub Dev go here back to mobile Net V2 this is that step there m dot build but we'll see

61
00:05:04,870 --> 00:05:06,110
this in a moment.

62
00:05:06,340 --> 00:05:12,250
And if you're wondering where any of these other steps are you could pause this video and have a read

63
00:05:12,250 --> 00:05:19,770
through this even if it doesn't make sense don't worry because we're gonna coded up in a second.

64
00:05:19,780 --> 00:05:23,680
Have a read through this and then come back here if not if you don't want to read through that we'll

65
00:05:23,680 --> 00:05:28,210
just keep going with the code here we'll go here.

66
00:05:28,260 --> 00:05:31,950
All of these steps can be found

67
00:05:34,590 --> 00:05:34,920
here.

68
00:05:35,950 --> 00:05:39,890
This is just a way of documenting for our own sake.

69
00:05:39,920 --> 00:05:47,900
All right so let's let's write the code first and then we'll discuss each part.

70
00:05:47,910 --> 00:05:49,950
I think that's a better way to go.

71
00:05:50,010 --> 00:05:55,690
So create a function which builds a carer's model.

72
00:05:55,860 --> 00:05:58,650
So def create model.

73
00:05:58,830 --> 00:06:00,230
This is our own custom function.

74
00:06:00,230 --> 00:06:02,590
This is what we want to get used to writing.

75
00:06:02,670 --> 00:06:12,790
So it's gonna take input shape which is just their wonderful output shape equals output shape.

76
00:06:14,550 --> 00:06:16,620
And then it's gonna take model U.R.L..

77
00:06:16,680 --> 00:06:23,220
This is handy because if we wanted to change the model we were using we could just update the model

78
00:06:23,220 --> 00:06:30,000
you are all variable and if we wanted to similarly change the input shape and the output shape we could

79
00:06:30,030 --> 00:06:32,160
we could also change those later on.

80
00:06:32,310 --> 00:06:35,810
So print we just want to find out what model we're using.

81
00:06:37,710 --> 00:06:47,990
So let's hope building model with just the model you are L here and now we're going to set up model

82
00:06:47,990 --> 00:06:53,900
layers so model equals t after Kerry's dot sequential

83
00:06:56,810 --> 00:07:05,740
and then we want to write hub dot layout layer and we're going to pass it model U.R.L.

84
00:07:08,740 --> 00:07:12,910
so this is layer 1 the input layer

85
00:07:16,020 --> 00:07:19,470
and then after that we want to do.

86
00:07:19,470 --> 00:07:28,630
TMF Kerry's layers don't dance and then the number of units equals our output shape.

87
00:07:31,800 --> 00:07:38,320
And the activation which is a word you probably haven't heard before equals soft Max

88
00:07:41,560 --> 00:07:42,330
layer to.

89
00:07:42,430 --> 00:07:43,590
This is the output layer.

90
00:07:45,270 --> 00:07:50,070
Now just bear with me if you don't understand it that's all right we're gonna go through it.

91
00:07:50,250 --> 00:07:52,470
This is just practicing writing the code.

92
00:07:52,470 --> 00:08:00,560
I'd like that to be over here actually I have a strange feeling collab uses two spaces instead of four

93
00:08:00,560 --> 00:08:02,860
spaces but we'll find out in a moment.

94
00:08:02,870 --> 00:08:03,380
There we go.

95
00:08:03,380 --> 00:08:04,780
That looks a bit better.

96
00:08:04,850 --> 00:08:07,550
So without even discussing what's going on there.

97
00:08:09,110 --> 00:08:10,590
Want you to just have are actually.

98
00:08:10,880 --> 00:08:12,380
That looks a bit better if it's over here.

99
00:08:12,500 --> 00:08:13,490
That's a bit more python.

100
00:08:14,180 --> 00:08:18,080
So I would just want you to have a think about what's happening here.

101
00:08:19,960 --> 00:08:26,850
And if you wanted to help your thought process don't forget you can always read through here.

102
00:08:26,860 --> 00:08:34,360
So now we want to compile the model again a term we haven't heard but we're going to discuss these shortly.

103
00:08:34,740 --> 00:08:39,960
So compile we just want to get used to writing this sort of code.

104
00:08:40,800 --> 00:08:47,510
So this is just instantiating a model and this is putting the model together essentially so carries

105
00:08:47,620 --> 00:08:51,960
dot losses dot categorical cross entropy.

106
00:08:51,960 --> 00:08:53,980
Well that's a big word.

107
00:08:53,980 --> 00:08:54,390
So right.

108
00:08:54,480 --> 00:09:01,650
If it's confusing to after carers the optimizer what is an optimizer.

109
00:09:01,860 --> 00:09:03,000
Adam.

110
00:09:03,000 --> 00:09:07,000
Adam and then metrics.

111
00:09:07,010 --> 00:09:09,030
This one will be familiar for sure.

112
00:09:09,050 --> 00:09:14,290
Because we're working with classification accuracy.

113
00:09:15,010 --> 00:09:22,210
And then finally you want to build the model so model to build input shape

114
00:09:25,080 --> 00:09:27,450
and then we're going to return model

115
00:09:31,720 --> 00:09:36,930
so now let's run the code if in doubt run the code.

116
00:09:36,930 --> 00:09:45,540
So model equals create model we can use all of the default parameters and then we're going to go model

117
00:09:46,050 --> 00:09:46,800
dot summary

118
00:09:50,090 --> 00:09:53,400
building model choses say you are.

119
00:09:53,670 --> 00:09:55,350
What have we missed here.

120
00:09:55,440 --> 00:10:01,560
No attribute optimizer optimize Zeus.

121
00:10:01,620 --> 00:10:03,660
Now we got.

122
00:10:03,870 --> 00:10:05,060
What else have we got wrong.

123
00:10:05,640 --> 00:10:10,140
All what is this.

124
00:10:10,310 --> 00:10:11,450
We haven't seen this before.

125
00:10:11,450 --> 00:10:17,310
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

126
00:10:17,310 --> 00:10:21,570
cliffhanger because in the next round we're going to go through this and discuss it.

127
00:10:21,690 --> 00:10:28,110
But in the meantime I'd like you to rewrite this at a bare minimum for yourself and to have a think

128
00:10:28,110 --> 00:10:29,880
about what's going on here.

129
00:10:31,190 --> 00:10:32,400
Also check out this.

130
00:10:32,420 --> 00:10:39,610
What do you think we've done here and after you've written the code and after you've gotten this output

131
00:10:40,850 --> 00:10:47,060
read a little bit through here especially the sequential model section and see if you can relate it

132
00:10:47,060 --> 00:10:48,830
back to what we're doing here.

133
00:10:49,070 --> 00:10:52,280
But otherwise I'll see you in the next video and we'll go through what's happening here.
