1
00:00:01,260 --> 00:00:07,770
Hi and welcome back in this lesson, we'll take a look at the PyTorch implementation of nine old style

2
00:00:07,770 --> 00:00:08,340
transfer.

3
00:00:08,850 --> 00:00:11,730
So open this notebook and we'll begin to listen.

4
00:00:12,150 --> 00:00:15,380
So in this lesson, we're doing it from scratch.

5
00:00:15,390 --> 00:00:19,770
We're not going to be loading a pre-trained model like we did with TensorFlow hub.

6
00:00:20,280 --> 00:00:25,530
And we're going to basically build the components from scratch like we did in the second half of that

7
00:00:25,530 --> 00:00:26,280
last lesson.

8
00:00:26,880 --> 00:00:28,110
So let's take a look.

9
00:00:28,170 --> 00:00:33,750
So I'm not going to read through all of these explanation notes here, but lengthy, and you can do

10
00:00:33,750 --> 00:00:34,920
that on your own time.

11
00:00:35,310 --> 00:00:37,590
So let's import these functions that we'll be using.

12
00:00:38,070 --> 00:00:43,490
You can see we're using the regular watch functions, as well as some towards vision models.

13
00:00:43,500 --> 00:00:48,300
That's that's that gives us the pre-trained Kijiji model that we will we will be using of that pre-treatment

14
00:00:48,300 --> 00:00:48,630
model.

15
00:00:48,640 --> 00:00:53,730
We're not going to be using specific, stylized model like we used in TensorFlow Arab.

16
00:00:54,600 --> 00:01:00,960
Let's double check that we're using our GPU and we just print this out.

17
00:01:04,820 --> 00:01:05,870
We are using energy for you.

18
00:01:05,900 --> 00:01:06,290
Great.

19
00:01:07,010 --> 00:01:13,760
Now let's load our test images here of we're going to take a look at so the content image is going to

20
00:01:13,760 --> 00:01:14,630
be a difference.

21
00:01:15,020 --> 00:01:22,730
In this case, I wanted to show you that we can actually apply neural style transfer to a style, an

22
00:01:22,730 --> 00:01:27,490
auto image so you can copy the artistic style of one image onto another image.

23
00:01:27,500 --> 00:01:29,570
So we'll take a look and I'll show you what I mean.

24
00:01:30,410 --> 00:01:33,020
You can use any of the any images you want here.

25
00:01:33,320 --> 00:01:36,950
Just point a URL to it to upload it to your GitHub and point of view URL here.

26
00:01:37,790 --> 00:01:43,880
So I'm using the one on the PyTorch tutorial site to demonstrate this because I think it's a good example

27
00:01:43,880 --> 00:01:44,810
and it works well.

28
00:01:45,350 --> 00:01:49,610
So this is the image loader here where we convert into a pill image.

29
00:01:50,060 --> 00:01:54,170
This is a plotting function, and let's take a look at those test images.

30
00:01:54,650 --> 00:02:00,260
So this is a content image, and we're going to apply this artistic style onto this image.

31
00:02:00,470 --> 00:02:02,510
So that should lead to a very cool result.

32
00:02:03,140 --> 00:02:06,170
So now we have to define our lost functions.

33
00:02:06,680 --> 00:02:14,090
So, you know, we have our content loss here, which we create does a small little function that calculates

34
00:02:14,090 --> 00:02:16,430
the MSI loss between the input and the target.

35
00:02:17,310 --> 00:02:20,240
Then we have a star loss along with our grand matrix.

36
00:02:20,240 --> 00:02:24,650
So in this one, we are using the grand matrix and you can see and PyTorch.

37
00:02:25,010 --> 00:02:28,020
It's actually fairly easy to implement some of these functions.

38
00:02:28,040 --> 00:02:29,540
Not as confusing as to Carrasco.

39
00:02:29,550 --> 00:02:30,050
No, is it?

40
00:02:31,790 --> 00:02:34,540
So now we can take a look at star loss here.

41
00:02:34,550 --> 00:02:36,560
So this is a Star Wars class.

42
00:02:36,560 --> 00:02:40,700
I should say that it keeps track of both of these things with the ground matrix.

43
00:02:41,330 --> 00:02:45,140
And now we just import or model set it to evaluation mode.

44
00:02:45,650 --> 00:02:52,670
So we download a model from Dubai to its repo and then now we just have a normalization means a standard

45
00:02:52,670 --> 00:02:59,810
deviation for the image net pre-processing, and we create another normalization function here.

46
00:03:00,680 --> 00:03:04,310
And then, no, this is a big class that this is what it's doing.

47
00:03:04,790 --> 00:03:06,290
Most of the heavy lifting here.

48
00:03:06,920 --> 00:03:10,880
We basically run the the neural cell transfer algorithm right here.

49
00:03:11,390 --> 00:03:15,680
So this is going to step true for all of the different layers we want to specify.

50
00:03:16,250 --> 00:03:21,650
And this is going to basically get the content layers, get the star layers and then trim off the layers

51
00:03:21,650 --> 00:03:25,430
of last content and style and return our model.

52
00:03:25,520 --> 00:03:28,610
So this basically is the core of our network.

53
00:03:29,300 --> 00:03:30,260
So let's run that.

54
00:03:30,950 --> 00:03:38,060
And no and no, we can just take a look at our test image just again did with image, just so content

55
00:03:38,060 --> 00:03:38,390
image.

56
00:03:39,020 --> 00:03:40,760
And here we have a optimizer.

57
00:03:40,760 --> 00:03:44,580
We're using the LBC's algorithm, so optimizer.

58
00:03:44,580 --> 00:03:48,230
It's recommended for neural cell transfer to get these people.

59
00:03:49,400 --> 00:03:55,430
And then we can now finally step through the network because we had the class above that basically extracted

60
00:03:55,430 --> 00:03:59,150
all the layers that we're working with and now and and losses.

61
00:03:59,150 --> 00:04:03,380
And no, we can actually compute everything with our training steps.

62
00:04:03,380 --> 00:04:09,770
So that's run that we have everything in our PyTorch setup optimizes.

63
00:04:09,770 --> 00:04:10,370
You agreed.

64
00:04:11,090 --> 00:04:12,710
So everything should be fine.

65
00:04:12,980 --> 00:04:21,870
So let's create this and now we can do to run out and run style transfer function and implement our

66
00:04:21,890 --> 00:04:23,870
new rules to transfer using by touch.

67
00:04:24,030 --> 00:04:24,890
So let's take a look.

68
00:04:26,910 --> 00:04:28,500
You can see it's running fine.

69
00:04:29,310 --> 00:04:30,750
We don't see an output yet.

70
00:04:31,320 --> 00:04:37,590
So we're running for the default of 200 steps here, and these are some of the content with some weight

71
00:04:37,590 --> 00:04:39,600
ratios and you can change as well.

72
00:04:40,140 --> 00:04:45,370
So you can see after running for those 200 iterations, we get this nicely generated image here.

73
00:04:45,900 --> 00:04:46,890
So that's pretty cool.

74
00:04:47,130 --> 00:04:49,410
And you can experiment with different weights to try it.

75
00:04:50,190 --> 00:04:52,270
But this one actually looks quite good, in my opinion.

76
00:04:52,290 --> 00:04:56,910
It looks like it actually was painted in that style that autistic.

77
00:04:56,910 --> 00:04:57,240
So.

78
00:04:57,840 --> 00:05:04,380
So that's it for the PyTorch implementation of neural cell transfer and the next lesson, we'll start

79
00:05:04,380 --> 00:05:10,140
taking a look at auto incluidas and then micho it again, which is a really cool part of the course.

80
00:05:10,680 --> 00:05:12,000
So I'll see you then.

81
00:05:12,210 --> 00:05:12,480
But.
