1
00:00:00,710 --> 00:00:01,590
All righty.

2
00:00:01,630 --> 00:00:07,210
So now we've got a function to pre process our images a.k.a. turn them into tenses.

3
00:00:07,210 --> 00:00:10,710
We can now start to figure out what we need to do next.

4
00:00:10,710 --> 00:00:15,150
So we've got get data ready turn it into tenses pick a model.

5
00:00:16,140 --> 00:00:19,170
Well we're not quite up to this.

6
00:00:19,170 --> 00:00:26,250
So if we come back we're going to read a little bit more into learning images intensive low we'd figure

7
00:00:26,250 --> 00:00:34,560
out that the flow likes to see things in the form of a data batch a.k.a. a tensor containing an image

8
00:00:34,560 --> 00:00:39,030
example or a piece of data for example remember this is data agnostic.

9
00:00:39,030 --> 00:00:42,440
We're just using images as our practical example.

10
00:00:42,510 --> 00:00:44,700
So it likes it in the form of.

11
00:00:44,730 --> 00:00:45,040
Okay.

12
00:00:45,050 --> 00:00:49,760
Give me a piece of data and it's label as a combined tensor.

13
00:00:50,070 --> 00:00:53,130
So I can process them really fast.

14
00:00:53,130 --> 00:00:55,550
And if you're wondering what a batch is.

15
00:00:55,560 --> 00:01:01,100
Well it's also called a mini batch which is a small portion of your data.

16
00:01:01,140 --> 00:01:09,300
Now generally if you're wondering what a good batch size is or how much is a small portion 32 is generally

17
00:01:09,300 --> 00:01:13,350
the default batch size with most deep learning models and I'll show you.

18
00:01:13,650 --> 00:01:15,150
This is how I figure out a lot of things.

19
00:01:15,150 --> 00:01:20,400
So we go John McCain that size and you might be wondering who the hell is John McCain.

20
00:01:20,400 --> 00:01:22,480
What is batch size all these things you know to me.

21
00:01:22,500 --> 00:01:29,070
But I want to show you a little trick when you find or when you hear of someone who is let's say a figure

22
00:01:29,070 --> 00:01:34,710
in the field of machine learning or Deep Learning a trick that I use to figure out what they think of

23
00:01:34,710 --> 00:01:41,250
a certain topic is I google their name and I Google the concept I'm looking for another one is Jeremy

24
00:01:41,250 --> 00:01:42,360
Howard.

25
00:01:42,360 --> 00:01:49,710
So John McCain and Jeremy Howard you could go Jeremy Howard batch size Google that I'm just telling

26
00:01:49,710 --> 00:01:53,630
you these two people off the top of my head John McCain I'll let you research him.

27
00:01:53,640 --> 00:01:58,200
But he is one of the founders of convolution on neural networks which is kind of what we're going to

28
00:01:58,200 --> 00:02:06,160
use to process our images but getting sidetracked here if we Google John McCain batch size and then

29
00:02:06,160 --> 00:02:13,020
we come to to Twitter to it is actually an amazing resource to figure things out well goodness training

30
00:02:13,020 --> 00:02:15,030
with large mini batches is bad for your health.

31
00:02:15,030 --> 00:02:18,040
More importantly it's bad for your test error.

32
00:02:18,060 --> 00:02:24,090
Friends don't let friends use mini batches larger than 32 then we've got a paper here linked on different

33
00:02:24,090 --> 00:02:28,200
batch sizes so I'll let you look into that.

34
00:02:28,210 --> 00:02:31,950
I'll link this tweet in the resources section so you can check out that paper.

35
00:02:31,960 --> 00:02:38,230
But this is not going to get worked towards we're going to transform our data into batches of size 32

36
00:02:38,560 --> 00:02:40,980
so they process really efficiently intensive flow.

37
00:02:41,000 --> 00:02:49,590
So let's make a little heading turning our data into batches and these little tidbits.

38
00:02:49,590 --> 00:02:51,780
The one I just showed you like searching someone's name.

39
00:02:51,810 --> 00:02:54,650
These kind of things I think are important right.

40
00:02:54,660 --> 00:02:58,950
How would you know that if I didn't sort of tell you or you sort of didn't stumble across it.

41
00:02:59,040 --> 00:03:03,540
The only way I found that was by stumbling across hey there's all this great information that people

42
00:03:03,540 --> 00:03:04,700
are sharing.

43
00:03:04,770 --> 00:03:10,320
How do I find that every so often and again my way is not perfect but it's helpful.

44
00:03:10,320 --> 00:03:14,190
I google someone's name and a certain concept I want to find out about more.

45
00:03:14,370 --> 00:03:16,560
This is why it's important to share your work.

46
00:03:16,560 --> 00:03:18,460
If you find something valuable.

47
00:03:18,570 --> 00:03:19,830
OK.

48
00:03:19,920 --> 00:03:21,690
Getting sidetracked once again.

49
00:03:21,840 --> 00:03:25,170
But why would we turn our something into batches.

50
00:03:25,170 --> 00:03:26,040
Well let's say

51
00:03:29,510 --> 00:03:36,350
we turn our data into batches and if you're still confused on batches we're just taking a small portion

52
00:03:36,500 --> 00:03:43,970
32 images and calculating on those 32 images at one time and then the next loop the next training session

53
00:03:44,360 --> 00:03:50,810
we calculate on the next 32 because if we tried to calculate patterns in all 10000 images.

54
00:03:50,810 --> 00:03:57,980
So here let's say you're trying to process 10000 plus images in one go

55
00:04:00,800 --> 00:04:04,940
they all might not fit into memory.

56
00:04:05,780 --> 00:04:10,900
So what I mean by that is that a GP you has although it's really fast computing.

57
00:04:10,910 --> 00:04:13,580
It still has a limited amount of memory.

58
00:04:13,760 --> 00:04:19,520
And so my computer has 16 gigabytes of ran the GPO backing this might have eight gigabytes of RAM.

59
00:04:20,000 --> 00:04:25,700
So if we have 10000 plus images and we're trying to process the patents on that in one go that may be

60
00:04:25,700 --> 00:04:31,180
more than eight gigabytes which is going to slow down our training process it's going to break everything.

61
00:04:31,220 --> 00:04:33,810
So that's why we do 32 at a time.

62
00:04:34,700 --> 00:04:41,450
So that's why we do about 32 images at a time.

63
00:04:41,450 --> 00:04:50,840
You can do two images batch size that's right here.

64
00:04:51,200 --> 00:04:58,490
This is batch size you can manually adjust the batch size if need be.

65
00:04:58,490 --> 00:04:59,810
All right.

66
00:04:59,810 --> 00:05:03,410
So I spent enough time talking let's start writing some code.

67
00:05:03,410 --> 00:05:04,160
What do we need.

68
00:05:04,160 --> 00:05:11,160
So write it here in order to use tensor flow effectively.

69
00:05:11,840 --> 00:05:27,200
We need our data in the form of tensor topples which look like this so image in the form of a tensor

70
00:05:27,920 --> 00:05:31,620
and label so as pairs.

71
00:05:32,030 --> 00:05:37,580
So then we'd pass thirty two of these at a time to our machine learning model and it would figure out

72
00:05:37,610 --> 00:05:42,680
the patterns in this image that relate to this label and then it would end up doing that in a sort of

73
00:05:42,680 --> 00:05:47,270
loop fashion until it gets through all ten thousand plus images proof.

74
00:05:47,990 --> 00:05:54,780
All right let's build some functionality but first we need a way to get topples.

75
00:05:54,790 --> 00:06:00,210
So we need before we can turn them into batches of 32 we need to get a top all that looks like this

76
00:06:00,220 --> 00:06:02,220
so let's write a little function.

77
00:06:02,860 --> 00:06:11,800
So create a simple function to return a topple a couple of tenses that rolls off the tongue nicely.

78
00:06:12,430 --> 00:06:17,110
So we want to go def get image label

79
00:06:19,840 --> 00:06:23,460
cause we've got a function here that's going to return our image.

80
00:06:23,590 --> 00:06:30,310
So all we want to do is just basically get the label associated to whatever path we pass this function

81
00:06:31,670 --> 00:06:32,610
so we get here.

82
00:06:32,660 --> 00:06:37,190
Image path and now really you're going to laugh at me for how simple this function is because all we're

83
00:06:37,190 --> 00:06:45,420
doing is passing it the image path the actual label and the image pre processing function we just write

84
00:06:46,110 --> 00:06:54,710
so process image image path and then we want to go return image label.

85
00:06:54,870 --> 00:07:10,270
Look at that how nice is that so takes an image file path name and the ASO she added liable process

86
00:07:10,300 --> 00:07:18,000
is the image and returns a topple of image label.

87
00:07:18,580 --> 00:07:20,320
The doc string is longer than the function

88
00:07:24,780 --> 00:07:25,560
beautiful.

89
00:07:25,950 --> 00:07:29,220
We didn't even need that line we could have just done it I'll return here.

90
00:07:29,250 --> 00:07:31,470
Now let's just give a a quick example there.

91
00:07:31,950 --> 00:07:41,640
Let's just see exactly what this would look like process image we want file names let's get forty to

92
00:07:42,090 --> 00:07:44,940
our favorite number and what is it.

93
00:07:44,940 --> 00:07:45,460
What's it called.

94
00:07:45,470 --> 00:07:48,720
Boolean labels.

95
00:07:48,730 --> 00:07:50,620
We could just use X and Y couldn't we.

96
00:07:50,620 --> 00:07:53,820
That's probably a bit better ex

97
00:07:56,540 --> 00:08:02,610
y 22 demo of the above

98
00:08:05,510 --> 00:08:12,650
beautiful so that's in a topple out image is in a tensor because we pass it to process image.

99
00:08:12,680 --> 00:08:19,070
But our label is not yet in a tensor but that's a right we could turn it into a tensor by just going

100
00:08:19,070 --> 00:08:23,960
to f constant.

101
00:08:24,160 --> 00:08:24,760
There we go.

102
00:08:25,420 --> 00:08:32,400
So now we've got a couple of an image and label pair in the form of tenses.

103
00:08:32,470 --> 00:08:35,660
Now we're making some good progress here and getting our data ready.

104
00:08:35,660 --> 00:08:40,390
I remember how I said a lot of machine learning is just pre processing your data into a format that

105
00:08:40,390 --> 00:08:42,210
fits into a machine learning model.

106
00:08:42,310 --> 00:08:44,640
That's what we're doing here and now.

107
00:08:44,740 --> 00:08:52,750
Again this process we're sort of taking getting our data into the format of data label in a table of

108
00:08:52,750 --> 00:08:57,610
tenses is agnostic to whatever data you're using.

109
00:08:57,610 --> 00:09:01,930
So if you're not using images you're using something like text.

110
00:09:01,930 --> 00:09:08,410
This would be a very similar process except the way you pre process the text will be different to the

111
00:09:08,410 --> 00:09:11,470
image you still have to get it into tenses.

112
00:09:11,470 --> 00:09:19,990
All right so we've got a little function to get image and label pairs in the form of topples.

113
00:09:20,050 --> 00:09:26,830
Write a function in the next video to turn our image and label pairs into batches and there's a few

114
00:09:26,830 --> 00:09:32,360
little tidbits that we need to pay attention to depending on if our images are in a training batch of

115
00:09:32,400 --> 00:09:34,990
validation batch and a test batch.

116
00:09:34,990 --> 00:09:37,080
But we'll see that in the next video.
