1
00:00:01,110 --> 00:00:07,050
And welcome back in this lesson, we'll take a look at executing the Google deep dream algorithm using

2
00:00:07,050 --> 00:00:07,640
Keros.

3
00:00:07,710 --> 00:00:08,760
So let's get started.

4
00:00:08,970 --> 00:00:14,910
Open Notebook 25, which I've already done here, actually changed us to 25.

5
00:00:14,940 --> 00:00:15,780
Sorry about that.

6
00:00:16,560 --> 00:00:18,540
So let's take a look at this lesson.

7
00:00:18,660 --> 00:00:20,010
So what we'll do?

8
00:00:20,160 --> 00:00:26,370
Firstly, I'll just say one thing, though, because implementing these algorithms like Google Live

9
00:00:26,370 --> 00:00:33,600
Stream and neural style transfer in a few of these fluid projects, in this course, they can get quite

10
00:00:33,630 --> 00:00:37,410
technical because you're now implementing real research papers.

11
00:00:37,590 --> 00:00:40,920
These researchers have spent years or months working on.

12
00:00:41,430 --> 00:00:49,860
So to do justice to explain these, these theycould and their methods in a short space of time is often

13
00:00:49,860 --> 00:00:50,730
quite difficult.

14
00:00:50,760 --> 00:00:56,340
So what I will do, though, is I'll explain it at a very high level and try to put a lot of comments

15
00:00:56,340 --> 00:00:59,280
in the code to help you understand what's going on.

16
00:00:59,700 --> 00:01:04,140
I'm not going to do a line by line explanations because that can get very tedious.

17
00:01:04,140 --> 00:01:09,600
And to be quite fair, I don't actually fully understand every single thing that they do.

18
00:01:10,200 --> 00:01:12,080
So I apologize for that.

19
00:01:12,090 --> 00:01:15,480
And now we can get started after that disclaimer warning.

20
00:01:16,110 --> 00:01:17,850
So what we're doing here?

21
00:01:17,880 --> 00:01:19,980
We're loading our modules and this image here.

22
00:01:20,460 --> 00:01:23,220
Also, what we're doing, we're setting two layer settings here.

23
00:01:23,700 --> 00:01:26,790
Remember, these are represent different layers of the network.

24
00:01:27,150 --> 00:01:35,130
And this this, which we attribute here, basically see how much we want to this way to contribute to

25
00:01:35,130 --> 00:01:38,070
the visual effect so you can mess with these parameters.

26
00:01:39,020 --> 00:01:44,460
Um, I tend to actually like the scaling it up like this, but you can mess with those parameters to

27
00:01:44,460 --> 00:01:46,320
get different types of effects.

28
00:01:46,980 --> 00:01:49,330
Next, we can do a number of octaves.

29
00:01:49,350 --> 00:01:52,830
This is the skills that you run gradient descent up to more octaves you do.

30
00:01:53,190 --> 00:01:58,230
The more time it takes, however, that you at some point you're not going to see much difference because

31
00:01:58,590 --> 00:02:01,180
when it's too small, it's hard to see that on the image.

32
00:02:01,200 --> 00:02:03,090
So Tree is a good number to use.

33
00:02:03,660 --> 00:02:08,330
The ratio between scales is 1.4 and iterations will do.

34
00:02:08,350 --> 00:02:12,360
That's the Ascend steps, but scale would be 20.

35
00:02:12,480 --> 00:02:15,480
And then we use a max loss of 15 to stop that.

36
00:02:16,050 --> 00:02:19,890
So let's run this and we'll get started.

37
00:02:20,790 --> 00:02:21,240
There we go.

38
00:02:21,330 --> 00:02:24,720
So it's we've loaded an image and we've floated all libraries.

39
00:02:25,320 --> 00:02:27,270
Now let's take a look at our test image to test.

40
00:02:27,270 --> 00:02:33,580
Image we've been using for this lesson is a beautiful picture of a beach in the island of Tobago.

41
00:02:34,050 --> 00:02:36,790
That's like home country of Trinidad and Tobago.

42
00:02:37,320 --> 00:02:38,310
It's a star.

43
00:02:38,490 --> 00:02:42,360
It's actually a heavenly bay, which is a bay next to costar a beach.

44
00:02:43,110 --> 00:02:45,780
So it's a very, very beautiful spot that I love.

45
00:02:46,560 --> 00:02:49,520
So now let's take a look at the deep dream process.

46
00:02:49,560 --> 00:02:52,770
So remember, we're first loading our original image.

47
00:02:53,370 --> 00:02:58,620
Then we define the number of processing skills which you have seen above in those parameters from small

48
00:02:58,620 --> 00:02:59,340
astrologers.

49
00:02:59,820 --> 00:03:03,450
Then we recites the original image to to the smallest skill.

50
00:03:03,900 --> 00:03:08,400
And then for every skill, starting with the smallest one, we run gradient descent.

51
00:03:08,850 --> 00:03:14,250
We upskill the image to the next skill and then re-injected the detail that was lost to the upskilling

52
00:03:14,280 --> 00:03:14,670
time.

53
00:03:15,240 --> 00:03:16,290
And then we stop.

54
00:03:16,470 --> 00:03:18,660
When we cook, we are back to the original skill.

55
00:03:19,170 --> 00:03:22,620
So now add them to obtain the detail lost during the upsampling.

56
00:03:23,040 --> 00:03:24,990
We simply take the original image.

57
00:03:25,140 --> 00:03:30,750
Shrink it down and then upskill it again and then compare the results of the original resized image.

58
00:03:31,260 --> 00:03:34,380
So that's basically the process in the overview.

59
00:03:34,860 --> 00:03:40,320
You can go back to the slides if you want to get a recap, more detailed recap with more, more visual

60
00:03:40,590 --> 00:03:41,280
explanation.

61
00:03:42,000 --> 00:03:47,970
So here we create a pre processing function for the image that we load, and this uses the Inception

62
00:03:47,980 --> 00:03:51,070
version three pre processes because that's the model will be loading.

63
00:03:51,090 --> 00:03:53,880
That's a pre-trained model that we've been using.

64
00:03:54,840 --> 00:03:59,730
And then we also have a deep process function image, which is what we need to do when we do the mixing

65
00:03:59,730 --> 00:04:04,950
of the images, and that's specific to the inception of each processing.

66
00:04:04,950 --> 00:04:06,540
That's where these values come from.

67
00:04:07,110 --> 00:04:09,270
So don't worry about these too much.

68
00:04:09,780 --> 00:04:13,490
And no, we compute the gibbering loss.

69
00:04:13,500 --> 00:04:15,000
So we load on that to work here.

70
00:04:15,600 --> 00:04:22,530
We get upwards to orleaneans here in this and then we just create a feature extract extractor here using

71
00:04:22,530 --> 00:04:26,250
those layers that we've loaded because we don't include the top layer.

72
00:04:26,430 --> 00:04:28,200
That means that's a fully connected layers.

73
00:04:28,620 --> 00:04:33,150
So it's basically a feature extract, a big feature extractor network.

74
00:04:33,810 --> 00:04:36,900
So that's how we create this model, this feature to model here.

75
00:04:37,860 --> 00:04:41,040
And now the most common computation is actually very simple.

76
00:04:41,580 --> 00:04:45,000
We just promises how we run the gradient ascent part of it here.

77
00:04:45,930 --> 00:04:47,520
So let's create that function.

78
00:04:48,240 --> 00:04:51,730
And then we set up the gradient descent loop for one octave here.

79
00:04:51,750 --> 00:04:53,490
So this is the gradient descent setup.

80
00:04:54,000 --> 00:04:59,880
We're using TensorFlow as gradient to appear to run to compute these gradients at some.

81
00:04:59,960 --> 00:05:06,020
Butterfly torches, Auchterarder, and then we just get to gradients normalized to gradients as we said

82
00:05:06,020 --> 00:05:07,100
we would have to do.

83
00:05:07,730 --> 00:05:14,150
And then this is the gradient descent loop that executes everything here next.

84
00:05:14,300 --> 00:05:18,830
Now we can actually start the training loop and iterating over different octaves.

85
00:05:19,280 --> 00:05:25,130
So this takes a little while to run when when it's finished running, we can display all final deep

86
00:05:25,130 --> 00:05:25,880
dream output.

87
00:05:26,480 --> 00:05:29,730
So let's go ahead and run this feature.

88
00:05:29,740 --> 00:05:34,520
Extract is not defined within run this block of code on top here.

89
00:05:34,820 --> 00:05:36,020
Let's do that now.

90
00:05:36,890 --> 00:05:39,590
OK, so now we can run this.

91
00:05:41,860 --> 00:05:47,440
So it's going to take a while, as they said, so we'll sit back and relax, go have a cup of tea or

92
00:05:47,440 --> 00:05:49,120
coffee for the time being.

93
00:05:50,020 --> 00:05:53,470
And then maybe in about a few minutes, it should be finished.

94
00:05:56,490 --> 00:05:59,820
OK, actually, that took a lot shorter than expected 22 seconds.

95
00:06:00,390 --> 00:06:07,320
Maybe we can actually use the parameters and tweak them to get the more fancy results, so let's take

96
00:06:07,320 --> 00:06:08,010
a look at the output.

97
00:06:08,760 --> 00:06:09,750
This should be exciting.

98
00:06:11,760 --> 00:06:14,130
Let's see our first Google deep dream.

99
00:06:14,220 --> 00:06:14,790
Here we go.

100
00:06:15,570 --> 00:06:17,870
So you can see this is actually quite a way continues.

101
00:06:17,880 --> 00:06:23,700
There's a weird little ES pattern that it created here.

102
00:06:23,750 --> 00:06:26,100
I'm not entirely sure what it looks like.

103
00:06:26,880 --> 00:06:28,620
It looks like a fish head, isn't it?

104
00:06:29,610 --> 00:06:31,890
And then just some generic patterns here.

105
00:06:32,370 --> 00:06:36,090
These patterns are due to the filters that we've we looked at.

106
00:06:36,510 --> 00:06:42,000
You can you can feel free to change the mixing change a lot of those different parameters in the beginning

107
00:06:42,000 --> 00:06:46,170
of the notebook and see if you get any other cool results.

108
00:06:46,380 --> 00:06:47,070
Let's see.

109
00:06:48,330 --> 00:06:50,040
Yeah, some of the cool patterns here.

110
00:06:50,040 --> 00:06:55,560
Something trippy, not super trippy, but you can experiment and run this for longer with more iterations

111
00:06:55,560 --> 00:06:58,320
as well to get even more color effects.

112
00:06:58,950 --> 00:07:02,940
So that's it for the cameras, Google's deep dream algorithm.

113
00:07:03,780 --> 00:07:07,920
Next, we'll take a look at how we do this and PyTorch, so I'll see you there.

114
00:07:08,220 --> 00:07:08,490
But.
