1
00:00:00,390 --> 00:00:01,230
And welcome back.

2
00:00:01,830 --> 00:00:06,900
What we're going to do now is we're going to actually use transfer learning by feature extraction,

3
00:00:07,320 --> 00:00:13,800
which means that all we do is we freeze all the convolutional layers, all the first block of layers

4
00:00:13,800 --> 00:00:17,430
and the network that we loaded and then just trained the top players.

5
00:00:17,520 --> 00:00:19,830
So let's take a look and see how we do that.

6
00:00:20,610 --> 00:00:28,080
So firstly, we load our net model here that we've done previously, and we set pre-trained equals true,

7
00:00:28,080 --> 00:00:30,660
which means that we're loading the image net with here.

8
00:00:31,470 --> 00:00:35,220
Then what we do, this is the part where we freeze the layers here.

9
00:00:35,760 --> 00:00:42,720
So we set for the parameter of whatever we call this variable in the model convolutional parameters,

10
00:00:43,230 --> 00:00:47,070
we can set the required ingredients here to be false.

11
00:00:47,730 --> 00:00:50,610
This is this was what how we freeze layers in part to it.

12
00:00:50,610 --> 00:00:55,410
So it's basically all the convolutional layers here in the network.

13
00:00:56,100 --> 00:00:59,220
All the trouble is we're setting it to.

14
00:00:59,850 --> 00:01:01,620
We're freezing them here effectively.

15
00:01:02,550 --> 00:01:04,030
Next, what do we do?

16
00:01:04,050 --> 00:01:06,420
We're going to create a fully connected layer here.

17
00:01:07,050 --> 00:01:11,850
So we just take the model uploaded the convolutional layers of the resonant.

18
00:01:12,540 --> 00:01:19,050
And we just take the fully connected features here, the last layer features, and then we add on to

19
00:01:19,050 --> 00:01:23,010
our output output class here, basically.

20
00:01:23,670 --> 00:01:28,020
So what this does, this is going to keep this is this these are the Trinamool is here.

21
00:01:28,740 --> 00:01:35,100
So these are newly constructed modules and by default requires graphical true meaning that they're not

22
00:01:35,100 --> 00:01:37,590
going to be frozen, they're going to be trainable at that point.

23
00:01:38,340 --> 00:01:42,810
So we just passed this model to a GPUs set across them to be lost criterion.

24
00:01:43,860 --> 00:01:49,840
And then we just use again or living with Cedillo along with us, took us to Gradient Descent Optimizer

25
00:01:49,880 --> 00:01:51,810
and put these settings here for good.

26
00:01:52,500 --> 00:01:54,770
And then let's just create that.

27
00:01:54,780 --> 00:02:00,060
Actually, this wouldn't run right now because I am still training this model.

28
00:02:00,720 --> 00:02:01,500
It's almost done.

29
00:02:01,560 --> 00:02:07,020
Hopefully, by the end of this lesson, we'll have the results and then what you can do, you can just

30
00:02:07,350 --> 00:02:09,240
finally just train that model.

31
00:02:09,240 --> 00:02:14,910
Here you pass the mode that optimizes learning, which had you lose the model criterion.

32
00:02:15,480 --> 00:02:16,460
And that's it.

33
00:02:16,470 --> 00:02:18,270
And no one can take a look at her results.

34
00:02:18,270 --> 00:02:20,740
And you can see again, it's a bit spiky.

35
00:02:20,760 --> 00:02:24,150
We put up a ninety four point seven percent accuracy.

36
00:02:24,810 --> 00:02:27,030
So that means that we're going to get that.

37
00:02:27,030 --> 00:02:32,610
This model that's been returned here will be the best model unless there's some better results in this

38
00:02:32,610 --> 00:02:34,080
25, and I don't see it.

39
00:02:34,680 --> 00:02:39,990
So that's going to be the best model, and I don't have individualized predictions for those results

40
00:02:39,990 --> 00:02:44,760
here generated so you can experiment and visualized out on your own.

41
00:02:45,540 --> 00:02:46,020
All right.

42
00:02:46,020 --> 00:02:47,640
So that's it for this lesson.

43
00:02:48,030 --> 00:02:53,810
This is quite simple and actually do train most of my image classifiers in this method here by either

44
00:02:53,850 --> 00:02:59,970
combination of transfer learning, which feature extraction or fine tuning by freezing different layers.

45
00:03:00,330 --> 00:03:06,840
It's very good to experiment with freezing different layers and PyTorch and seeing how it affects the

46
00:03:06,840 --> 00:03:08,340
results on your dataset.

47
00:03:09,180 --> 00:03:12,750
So I hope you enjoyed it and we'll stop there for now and then.

48
00:03:12,750 --> 00:03:19,350
Next, we'll continue with using a pre trained model as a as a feature extractor like we just did.

49
00:03:19,890 --> 00:03:26,070
However, instead of having a fully connected neural network on top, we're going to use a linear network

50
00:03:26,070 --> 00:03:32,760
like a logistic regression to use the inputs from our previous layer as inputs to that model.

51
00:03:33,240 --> 00:03:35,700
And then and then create a model out of that.

52
00:03:36,150 --> 00:03:37,740
So I'll see you in the next lesson.

53
00:03:37,920 --> 00:03:38,370
Thank you.
