1
00:00:00,270 --> 00:00:06,690
Welcome back in this section, we'll take a look at how we can use CNN as a feature extractor increase.

2
00:00:06,840 --> 00:00:08,610
So let's open this notebook here.

3
00:00:09,480 --> 00:00:15,000
I believe this thing is still going on to keep you from the previous lesson, so let's stop this and

4
00:00:15,000 --> 00:00:15,840
close it.

5
00:00:18,730 --> 00:00:23,320
So now we have our feature extraction that books, you know, that make don't make the same mistake,

6
00:00:23,320 --> 00:00:25,320
let's make this short for you.

7
00:00:25,960 --> 00:00:26,740
And it is.

8
00:00:26,860 --> 00:00:29,080
So let's take a look at what we're going to do here.

9
00:00:29,560 --> 00:00:35,680
So in this dataset, we're going to use a Big 16 to extract features from our base dataset, and that's

10
00:00:35,680 --> 00:00:37,420
going to be our dogs in this cats dataset.

11
00:00:37,930 --> 00:00:38,770
Not the same one.

12
00:00:38,780 --> 00:00:44,920
We took them from the Keros TensorFlow sorry to TensorFlow datasets package that we used in the previous

13
00:00:44,920 --> 00:00:49,620
lesson that we're going to use our own Catzavelos dogs that said that we download.

14
00:00:51,700 --> 00:00:53,740
And then we just set this up here.

15
00:00:54,160 --> 00:00:56,640
This is we put everything into a pandas data frame.

16
00:00:56,650 --> 00:01:04,000
The graph, should you before and now what we do, that's load our big network with all the top.

17
00:01:04,660 --> 00:01:07,090
So we get our network there.

18
00:01:07,510 --> 00:01:08,590
This will finish.

19
00:01:08,770 --> 00:01:13,820
This will run when this dataset has been finished, downloading it on something and it is now.

20
00:01:13,840 --> 00:01:15,490
So yep, it's going to run.

21
00:01:15,970 --> 00:01:22,450
It's going to download a Big 16 image net, which which doesn't take too long and we're ready to go.

22
00:01:22,900 --> 00:01:27,790
So now we can take a look at the model summary here you can see we have 14 million parameters right

23
00:01:27,790 --> 00:01:30,550
now, so it's a fairly big network, as you can see.

24
00:01:30,880 --> 00:01:33,940
So let's see what else we're going to do now.

25
00:01:34,390 --> 00:01:37,930
So just fix this diagram in the code because the link was broken before.

26
00:01:38,380 --> 00:01:39,920
So let's go back to this.

27
00:01:39,940 --> 00:01:41,240
What are we doing here?

28
00:01:41,260 --> 00:01:48,040
Well, we're using the 5G network as a feature extractor, so ignoring this densely ahead is green nodes

29
00:01:48,040 --> 00:01:48,280
here.

30
00:01:48,760 --> 00:01:57,700
We're just passing all of the images into this network here and extracting this seven by seven by 512.

31
00:01:58,000 --> 00:02:01,270
That's the outputs from this node we're going to be extracting.

32
00:02:01,270 --> 00:02:08,100
That would basically imagine this seven by seven by five 12 isn't, including from the full image of

33
00:02:08,150 --> 00:02:09,790
four images by the CNN.

34
00:02:10,180 --> 00:02:11,380
That's exactly what it is.

35
00:02:11,830 --> 00:02:18,130
So we're doing this running this loop here that basically runs through all of the batches here and extracts

36
00:02:18,130 --> 00:02:22,140
the features and stores that in this image, which is very hip.

37
00:02:22,300 --> 00:02:23,470
That's all that we're doing here.

38
00:02:23,470 --> 00:02:29,740
We're just taking images, setting them up so we can pre-purchase them to the network using the image

39
00:02:29,740 --> 00:02:33,940
that utility is to pre process and passing it to the model predicts.

40
00:02:33,960 --> 00:02:36,460
Remember which model is just a convolutional model?

41
00:02:36,460 --> 00:02:40,010
It has not fully connected layers at the top, and that's it.

42
00:02:40,030 --> 00:02:41,470
So this takes a while to run.

43
00:02:41,740 --> 00:02:45,970
So I'm leaving it here to run, but I run to the lesson as well.

44
00:02:46,000 --> 00:02:50,020
So you can see the rest of the output, so the image features that we get.

45
00:02:50,500 --> 00:02:55,710
Remember, there are going to be a seven by seven where it is a tier, seven by seven by five 12.

46
00:02:55,720 --> 00:03:01,960
It's quite a large number, but that's what we're going to be using as the input to our new classifier.

47
00:03:02,770 --> 00:03:05,230
So this is what it looks like has quite a few big.

48
00:03:05,440 --> 00:03:06,760
You can see it actually right now.

49
00:03:07,180 --> 00:03:11,830
This is a batch right here to the to by 250000.

50
00:03:11,830 --> 00:03:13,420
Actually, that's 25000 sorry, idiots.

51
00:03:13,420 --> 00:03:15,910
So that's what that this number means.

52
00:03:16,090 --> 00:03:21,430
So you can see we have this batch of 32 images and these are the encoding for them.

53
00:03:22,030 --> 00:03:26,110
And you can see the image labels what they look like cats, first dogs for each batch.

54
00:03:26,140 --> 00:03:29,830
That's why there's this array of 32 here.

55
00:03:31,120 --> 00:03:36,760
So now what we're going to do, we're going to train a logistic regression classifier on those features.

56
00:03:37,360 --> 00:03:45,430
So we use a list comprehension here just to get the image levels, detailed image features data and

57
00:03:45,430 --> 00:03:46,270
then we can visit.

58
00:03:46,960 --> 00:03:52,270
This should be can fit to Nampai areas here.

59
00:03:52,900 --> 00:03:58,360
So then we can now use this as an input into the logistic regression classifier.

60
00:03:58,570 --> 00:04:06,400
So we just use train to splitter because remember, a dataset was just all those images we set up from

61
00:04:06,400 --> 00:04:08,800
before those training images.

62
00:04:09,400 --> 00:04:16,300
So we just split it into 80 percent, 20 percent, which is set up a logistic regression here using

63
00:04:16,300 --> 00:04:20,590
the logistic regression object here, said C Equal 2.1.

64
00:04:21,160 --> 00:04:23,410
That's one of the parameters for logistic regression.

65
00:04:23,860 --> 00:04:28,780
And in the end, you can see I'm going to run this now because this also takes quite a while because

66
00:04:28,780 --> 00:04:29,820
it's quite big.

67
00:04:30,370 --> 00:04:37,450
Remember, this is 25000 of features in that dataset, so it's quite big.

68
00:04:37,540 --> 00:04:40,870
So you can see we got an accuracy of ninety eight point four percent.

69
00:04:41,440 --> 00:04:42,400
That is really high.

70
00:04:42,430 --> 00:04:43,630
It's actually remarkably high.

71
00:04:44,290 --> 00:04:46,450
So let's take a look at some of this here.

72
00:04:46,450 --> 00:04:48,100
Let's let's test this network now.

73
00:04:48,610 --> 00:04:54,400
So to test inferences on this network, we basically just set our test territory here, ghetto image

74
00:04:54,400 --> 00:04:57,910
parts here, which members names here and get the parts I would fit here.

75
00:04:58,990 --> 00:05:03,130
Then we just pull a random sample from those parts that we have given it.

76
00:05:03,130 --> 00:05:08,620
Here we're going to take 12 random samples here, and then we're going to loop through those 12 images

77
00:05:08,620 --> 00:05:08,860
here.

78
00:05:08,860 --> 00:05:12,580
So we load the image, change it into 24 by 224 sites.

79
00:05:12,580 --> 00:05:14,980
That's what we expects in this case.

80
00:05:15,520 --> 00:05:17,060
And then we just run it through.

81
00:05:17,480 --> 00:05:21,920
To get the predictions out of it, then this is no, this is not a predictions.

82
00:05:21,940 --> 00:05:23,410
Actually, this is a features.

83
00:05:23,920 --> 00:05:25,620
So the futures are basically this.

84
00:05:25,620 --> 00:05:30,610
So this is how we just reshape this rule here and now we can take this input.

85
00:05:30,730 --> 00:05:36,850
That's the features from our CNN and pass it to a logistic regression classifier that we made previously.

86
00:05:37,450 --> 00:05:42,010
And if the result is still we see it all else is on the point five.

87
00:05:42,010 --> 00:05:42,670
It's a cut.

88
00:05:42,670 --> 00:05:48,820
That's the biggest logistic regression gives a probability output and then we distort distorted results

89
00:05:48,820 --> 00:05:49,050
here.

90
00:05:49,060 --> 00:05:53,800
So you can see after that, we can visualize these results here where by printing them.

91
00:05:54,250 --> 00:06:01,510
But let's actually see them on the images so we can use map plot lib here just to generate these nice

92
00:06:01,510 --> 00:06:01,960
plots.

93
00:06:02,560 --> 00:06:08,560
And we can see a guide dog, correct cat, correct cat, correct dog, dog.

94
00:06:09,490 --> 00:06:11,740
This is actually a dog that's acting as a cat.

95
00:06:12,340 --> 00:06:13,270
This is a cat.

96
00:06:13,330 --> 00:06:16,600
This is a dog, dog, cat, dog, cat.

97
00:06:17,140 --> 00:06:23,890
So you can see it's it's doing fairly well, as you would expect if we got 90 percent accuracy on the

98
00:06:23,890 --> 00:06:28,180
training dataset and the cat under test data so that we split up here.

99
00:06:28,490 --> 00:06:33,230
So now let's see how it compares to Cargill's top 10 leaderboard.

100
00:06:33,250 --> 00:06:34,510
You can see that network.

101
00:06:34,930 --> 00:06:36,970
We just got ninety eight point three for technically.

102
00:06:37,540 --> 00:06:39,390
So you can see we're actually doing quite well.

103
00:06:39,400 --> 00:06:42,820
We're in Cargo's top 10, so you can see this simple network.

104
00:06:42,820 --> 00:06:49,540
The simple design is able to get achieve very, very good performance on this cat's first dog's dataset.

105
00:06:49,900 --> 00:06:51,190
So I hope you enjoyed this lesson.

106
00:06:51,640 --> 00:06:54,280
That's actually see if this has finished front.

107
00:06:55,540 --> 00:06:56,560
Yep, it's this.

108
00:06:56,830 --> 00:06:59,710
This takes a few minutes to run, actually, just just two minutes.

109
00:07:00,280 --> 00:07:04,780
So you can run this code yourself and get the results I just showed you.

110
00:07:04,930 --> 00:07:09,940
So thank you for watching, and I'll see you in the next lesson where we implement these two things.

111
00:07:10,450 --> 00:07:14,140
Fine tuning as well as feature extraction and transfer learning.

112
00:07:14,140 --> 00:07:17,140
And PyTorch without without using PI to watch lightning.

113
00:07:17,740 --> 00:07:19,750
So thank you for watching and I'll see you there.

114
00:07:19,930 --> 00:07:20,350
Thank you.

115
00:07:20,770 --> 00:07:24,340
So I just fixed this diagram in the code because the link was broken before.

116
00:07:24,790 --> 00:07:26,310
So let's go back to this.

117
00:07:26,350 --> 00:07:27,640
What are we doing here?

118
00:07:27,670 --> 00:07:34,450
Well, we're using the 5G network as a feature extractor, so ignoring this densely ahead as green nodes

119
00:07:34,450 --> 00:07:43,030
here, we're just passing all the images into this network here and extracting the seven by seven by

120
00:07:43,030 --> 00:07:44,080
512.

121
00:07:44,410 --> 00:07:45,970
That's the outputs from this node.

122
00:07:46,360 --> 00:07:51,640
We're going to be extracting that it would basically imagine this seven by seven by five 12 isn't,

123
00:07:51,640 --> 00:07:56,170
including from the full image of all images by the CNN.

124
00:07:56,590 --> 00:07:57,760
That's exactly what it is.

125
00:07:58,240 --> 00:08:04,510
So we're doing this running this loop here that basically runs through all of the batches here and extracts

126
00:08:04,510 --> 00:08:08,530
the features and stores that in this image, which is already here.

127
00:08:08,710 --> 00:08:09,870
That's all that we're doing here.

128
00:08:09,880 --> 00:08:16,150
We're just taking images, setting them up so we can pre-processed them to the network using the image

129
00:08:16,160 --> 00:08:20,380
that utility is to pre process and passing it to the model predicted.

130
00:08:20,380 --> 00:08:26,140
Remember, our model is just a convolutional model has not fully connected layers at the top, and that's

131
00:08:26,140 --> 00:08:26,400
it.

132
00:08:26,410 --> 00:08:27,880
So this takes a while to run.

133
00:08:28,150 --> 00:08:33,970
So I'm leaving it here to run, but I run to the lesson as well so you can see the rest of the output.

134
00:08:33,970 --> 00:08:36,430
So the image features that we get.

135
00:08:36,910 --> 00:08:42,130
Remember, there are going to be a seven by seven, where is a tier, seven by seven by five 12?

136
00:08:42,130 --> 00:08:48,370
It's quite a large number, but that's what we're going to be using as input to our new classifier.

137
00:08:49,180 --> 00:08:50,510
So this is what it looks like.

138
00:08:50,530 --> 00:08:51,610
It's quite a bigger.

139
00:08:51,850 --> 00:08:53,170
You can see it actually right now.

140
00:08:53,560 --> 00:08:59,680
This is a batch right here to the to by 250000, actually, that's twenty five dollars and targeting

141
00:08:59,680 --> 00:08:59,800
it.

142
00:08:59,800 --> 00:09:02,290
So that's what that this number means.

143
00:09:02,470 --> 00:09:07,840
So you can see we have this batch of 32 images and these are the in coatings for them.

144
00:09:08,440 --> 00:09:12,520
And you can see the image labels what they look like cats, first dogs for each batch.

145
00:09:12,550 --> 00:09:16,210
That's why there's this array of 32 here.

146
00:09:17,500 --> 00:09:23,140
So now what we're going to do, we're going to train a logistic regression classifier on those features

147
00:09:23,770 --> 00:09:30,280
so we can use this list comprehension here just to get the image levels, detailed image features,

148
00:09:30,280 --> 00:09:32,680
data and then we converted.

149
00:09:33,370 --> 00:09:38,680
This should be can fit to Nampai areas here.

150
00:09:39,310 --> 00:09:44,770
So then we can now use this as an input into our logistic regression classifier.

151
00:09:44,950 --> 00:09:52,770
So we just use Trenta Splitter because remember, data set was just all those images we set up from

152
00:09:52,780 --> 00:09:55,210
before those training images.

153
00:09:55,810 --> 00:10:02,710
So we just split it into 80 percent, 20 percent, which is set up a logistic regression here using

154
00:10:02,710 --> 00:10:07,000
the disk regression object here, said C Equal 2.1.

155
00:10:07,540 --> 00:10:09,820
That's one of the parameters for logistic regression.

156
00:10:10,270 --> 00:10:15,190
And in the end, you can see I'm looking to run this, and I guess this also takes quite a while because

157
00:10:15,190 --> 00:10:16,130
it's quite big.

158
00:10:16,800 --> 00:10:17,250
Remember, this is.

159
00:10:17,390 --> 00:10:23,870
Twenty five thousand of features in that dataset, so it's quite big.

160
00:10:23,930 --> 00:10:27,290
So you can see we got an accuracy of ninety eight point four percent.

161
00:10:27,830 --> 00:10:28,760
That is really high.

162
00:10:28,850 --> 00:10:30,050
It's actually remarkably high.

163
00:10:30,680 --> 00:10:32,870
So let's take a look at some of this here.

164
00:10:32,870 --> 00:10:34,520
Let's let's test this network now.

165
00:10:35,000 --> 00:10:40,790
So to test inferences on this network, we basically just set up a test out a Tree Hill ghetto image

166
00:10:40,790 --> 00:10:44,300
parts here, which members names here and get the parts of it here.

167
00:10:45,380 --> 00:10:49,790
Then we just pull a random sample from those parts that we've given it here.

168
00:10:50,240 --> 00:10:55,250
We're going to take 12 random samples here, and then we're going to loop through those 12 images here.

169
00:10:55,250 --> 00:10:58,970
So we'll know the image change of that to 24 by 24 sites.

170
00:10:58,980 --> 00:11:01,370
That's what widget expects in this case.

171
00:11:01,910 --> 00:11:04,000
And then we just run it through a model.

172
00:11:04,030 --> 00:11:05,480
Get the predictions out of it.

173
00:11:06,020 --> 00:11:08,330
Then this model, this is not a predictions.

174
00:11:08,330 --> 00:11:09,830
Actually, this is a features.

175
00:11:10,340 --> 00:11:12,010
So the features are basically this.

176
00:11:12,010 --> 00:11:17,030
So this is how we just reshape this real here and now we can take this input.

177
00:11:17,120 --> 00:11:23,240
That's the features from our CNN and pass it to a logistic regression classifier that we made previously.

178
00:11:23,840 --> 00:11:29,050
And if the result is still, we see a this on under point five, it's a cat.

179
00:11:29,060 --> 00:11:31,130
That's the cause.

180
00:11:31,230 --> 00:11:35,440
Logistic regression gives their probability output and then we just results here.

181
00:11:35,450 --> 00:11:40,190
So you can see after that, we can visualize these results here where by printing them.

182
00:11:40,640 --> 00:11:47,900
But let's actually see them on the images so we can use map plot lib here just to generate these nice

183
00:11:47,900 --> 00:11:48,380
plots.

184
00:11:48,980 --> 00:11:55,050
And we can see a got dog correct cat, correct cat, correct dog, dog.

185
00:11:55,880 --> 00:11:58,130
This is actually a dog that success as a cat.

186
00:11:58,730 --> 00:11:59,660
This is a cat.

187
00:11:59,720 --> 00:12:02,990
This is a dog, dog, cat, dog, cat.

188
00:12:03,530 --> 00:12:10,280
So you can see it's it's doing fairly well, as you would expect if we got 90 percent accuracy on the

189
00:12:10,280 --> 00:12:14,590
training dataset and the cat under test data so that we split up here.

190
00:12:14,880 --> 00:12:19,630
So now let's see how it compares to Cable's top 10 leaderboard.

191
00:12:19,640 --> 00:12:20,900
You can see that network.

192
00:12:21,350 --> 00:12:23,360
We just got ninety eight point three for technically.

193
00:12:23,960 --> 00:12:29,250
So you can see we're actually doing quite well in Cargill's top 10, so you can see this simple network.

194
00:12:29,250 --> 00:12:35,930
The simple design is able to get achieve very, very good performance on this cat's philstocks dataset.

195
00:12:36,290 --> 00:12:37,610
So I hope you enjoyed this lesson.

196
00:12:38,030 --> 00:12:40,670
That's actually see if this has finished run.

197
00:12:41,930 --> 00:12:42,950
Yep, it's this.

198
00:12:43,250 --> 00:12:46,100
This takes a few minutes to run, actually just just two minutes.

199
00:12:46,670 --> 00:12:51,170
So you can run this code yourself and get the results I just showed you.

200
00:12:51,350 --> 00:12:56,330
So thank you for watching, and I'll see you in the next lesson where we implement these two things.

201
00:12:56,870 --> 00:13:00,560
Fine tuning as well as feature extraction and transfer learning.

202
00:13:00,560 --> 00:13:03,560
And PyTorch without without using pretty much lightning.

203
00:13:04,160 --> 00:13:06,140
So thank you for watching, and I'll see you there.

204
00:13:06,320 --> 00:13:06,740
Thank you.
