1
00:00:00,270 --> 00:00:07,160
Now we've got our data in batches but it could be a little bit hard to understand what's going on in

2
00:00:07,160 --> 00:00:07,750
a batch.

3
00:00:07,790 --> 00:00:14,480
So let's build a little function which is going to explore what's in our batch so we can visualize what's

4
00:00:14,480 --> 00:00:19,250
happening because if we have this little output here we know deep down that these are actually images

5
00:00:19,250 --> 00:00:22,770
and these labels it would be good to see them.

6
00:00:22,820 --> 00:00:25,220
So let's make a little heading here.

7
00:00:25,340 --> 00:00:34,670
Visualizing data batches command Imam to turn it into markdown and let's give ourselves a little bit

8
00:00:34,670 --> 00:00:37,370
of communication.

9
00:00:37,490 --> 00:00:40,120
A data is now in batches.

10
00:00:41,540 --> 00:00:51,440
However these can be a little hard to understand slash comprehend.

11
00:00:51,860 --> 00:00:59,630
Let's visualize them because I'm not sure about you but I like to see things in action.

12
00:00:59,630 --> 00:01:03,370
So to do that we'll import our trusty map plot lib.

13
00:01:03,380 --> 00:01:15,530
Look at that auto suggestion and then we'll go create a function for viewing images in a data match

14
00:01:15,680 --> 00:01:22,490
or a data batch data we Australians the Australian accent liked to throw us onto the end of vowels wherever

15
00:01:22,490 --> 00:01:23,510
they are.

16
00:01:23,510 --> 00:01:30,800
We might do it to show 25 images because if we're doing too many like we have 10000 plus so we might

17
00:01:30,800 --> 00:01:37,700
just show twenty five at a time and we want images and labels because what we're going to do is basically

18
00:01:37,820 --> 00:01:51,680
plot an image and then above it put the label and nice and simple window displays a plot of twenty five

19
00:01:51,710 --> 00:01:58,230
images and name labels from a data batch.

20
00:01:58,440 --> 00:01:59,770
Wonderful.

21
00:01:59,790 --> 00:02:06,650
All right so let's set up the figure peyote dot figure will make it big size.

22
00:02:06,660 --> 00:02:12,000
Now I've had a little bit of experience with setting up this plot size so hopefully ten by 10 is good

23
00:02:12,000 --> 00:02:12,240
enough.

24
00:02:12,240 --> 00:02:13,870
If not we can change that.

25
00:02:13,950 --> 00:02:21,920
Then we'll go loop through twenty five for displaying twenty five images.

26
00:02:22,230 --> 00:02:29,910
So we'll just set up a simple loop for i in range twenty five then what can we do.

27
00:02:29,910 --> 00:02:31,890
Well we need to create a subplot.

28
00:02:31,890 --> 00:02:38,160
Let's make it five rows five columns because that's twenty five and then we'll have to display an image

29
00:02:38,160 --> 00:02:43,740
on each of the subplots and then add a title to each of the images.

30
00:02:44,220 --> 00:02:45,270
That shouldn't be too hard.

31
00:02:45,720 --> 00:02:54,690
So create subplots we'll go five rows five columns.

32
00:02:54,750 --> 00:03:02,900
AX equals penalty dot subplot five five I plus one.

33
00:03:02,910 --> 00:03:04,610
So this is God's.

34
00:03:04,620 --> 00:03:06,550
Because we have an imported map plot lib yet.

35
00:03:06,630 --> 00:03:09,950
That's what the doctoring isn't showing up.

36
00:03:09,980 --> 00:03:10,460
There we go.

37
00:03:12,000 --> 00:03:14,160
Parameters.

38
00:03:14,240 --> 00:03:14,770
Where do we go.

39
00:03:14,800 --> 00:03:15,600
A couple rows.

40
00:03:15,650 --> 00:03:17,410
Column.

41
00:03:17,440 --> 00:03:18,590
So this is number rows.

42
00:03:18,600 --> 00:03:20,250
This is columns and this is index.

43
00:03:20,310 --> 00:03:26,340
That's where you need to know display an image some of the map plot lib docs strings can be a bit annoying.

44
00:03:26,370 --> 00:03:31,890
Like when they go args keyword ARGs and it just inherits all some other class and you can't really find

45
00:03:31,890 --> 00:03:34,820
it if you need to check out what this actually does.

46
00:03:35,100 --> 00:03:38,130
Check out the map slightly full blown documentation.

47
00:03:38,160 --> 00:03:40,740
We want to plot the IFE image.

48
00:03:40,740 --> 00:03:42,170
So because we're looping through.

49
00:03:42,170 --> 00:03:45,250
This is gonna be a data bunch of images and labels.

50
00:03:45,360 --> 00:03:48,290
So we want to show the IFE image.

51
00:03:48,420 --> 00:03:56,830
So the IFE index my saying that right the image and add the image label as the title.

52
00:03:58,630 --> 00:04:04,390
So we appeal to you not title and then unique braids because that's our list.

53
00:04:04,410 --> 00:04:08,010
Remember if it still lives in memory it should.

54
00:04:08,100 --> 00:04:17,530
Unique braids is our list of unique dog names get the unique breeds label we want to index that where

55
00:04:17,540 --> 00:04:22,440
it labels the label is the maximum value.

56
00:04:22,890 --> 00:04:35,300
So in other words if we go y 0 Max 19 this is just exactly what we're going to be doing with that line

57
00:04:35,300 --> 00:04:37,390
up their unique braids.

58
00:04:37,400 --> 00:04:44,890
So this is this line here is the title of our plot boom.

59
00:04:44,930 --> 00:04:50,520
See what I mean by D function izing functions to really explore what's going on.

60
00:04:50,540 --> 00:04:52,370
So if you want to figure something out.

61
00:04:52,370 --> 00:04:57,710
Remember always you can just pull the function apart rewrite the code for yourself because that's how

62
00:04:57,710 --> 00:04:59,120
you're going to understand something.

63
00:04:59,120 --> 00:05:04,160
Turn the red lines off actually.

64
00:05:04,360 --> 00:05:06,330
We might see it with them on before.

65
00:05:06,340 --> 00:05:11,520
So we know exactly what this is doing rotate on axis.

66
00:05:11,570 --> 00:05:16,840
That's a nice simple function show 25 images.

67
00:05:16,920 --> 00:05:17,900
What do you need to know now.

68
00:05:17,910 --> 00:05:26,370
So because our data is in a batch we need to essentially on batch it to visualize it so we can do that

69
00:05:26,400 --> 00:05:28,050
by going train images.

70
00:05:28,050 --> 00:05:29,150
Let's see the code first.

71
00:05:29,160 --> 00:05:31,830
Then we'll see what's actually happening.

72
00:05:31,890 --> 00:05:35,270
Train labels equals next.

73
00:05:35,280 --> 00:05:37,310
So what next year is it.

74
00:05:37,320 --> 00:05:39,600
It returns the next item from an iterator.

75
00:05:39,710 --> 00:05:46,110
Oh well thank you Dr. King for that because train data is in the format of a batch.

76
00:05:46,290 --> 00:05:52,790
So if we go train data we need to turn it into an iterator There we go.

77
00:05:53,910 --> 00:06:03,910
So we can do that by calling the method as Num pi iterator and once is going to say returns and iterator

78
00:06:03,910 --> 00:06:08,230
which converts all elements of the data set to num pi.

79
00:06:08,230 --> 00:06:13,920
So basically what this is going to do is turn Oh there we go.

80
00:06:13,920 --> 00:06:16,000
We got some information here.

81
00:06:16,290 --> 00:06:18,470
Those docs strings are a little bit hard to read.

82
00:06:18,690 --> 00:06:19,420
They're for me.

83
00:06:20,610 --> 00:06:22,280
Let's just go through here what's it gonna do.

84
00:06:22,340 --> 00:06:25,830
This is gonna take our batch dataset.

85
00:06:25,890 --> 00:06:29,100
It's gonna unwind it from a batch and turn it into a num PI.

86
00:06:29,100 --> 00:06:35,850
It's right up and then thanks to next it's going to grab the first batch off the top of this out of

87
00:06:35,850 --> 00:06:43,020
this iterator and then because it's split it it's unbalanced it training images.

88
00:06:43,510 --> 00:06:49,360
So this one here this shape here is going to be the first thing that gets returned and train labels

89
00:06:49,540 --> 00:06:52,360
is going to be the next thing that gets returned.

90
00:06:52,360 --> 00:06:54,100
So don't take my word for it.

91
00:06:54,280 --> 00:07:02,160
If in doubt run the code.

92
00:07:02,320 --> 00:07:07,300
Now the reason this might take a little while to run is because if you remember when we batch you fired

93
00:07:07,330 --> 00:07:09,340
our data set up here.

94
00:07:11,250 --> 00:07:12,860
We've got this map function.

95
00:07:13,020 --> 00:07:17,400
Get image label which is going to process our images.

96
00:07:17,430 --> 00:07:24,600
So that's why when we're working with batches now because whenever we run it it's going to process our

97
00:07:24,630 --> 00:07:25,860
images in the background.

98
00:07:26,790 --> 00:07:27,440
So there we go.

99
00:07:30,430 --> 00:07:34,420
So instead of dealing with file names now we're actually dealing with processed images.

100
00:07:34,420 --> 00:07:36,720
So a little bit more data.

101
00:07:36,790 --> 00:07:40,780
This is a massive array right because we've got train images.

102
00:07:40,780 --> 00:07:41,670
This should be.

103
00:07:41,680 --> 00:07:43,600
Let's see how long it is.

104
00:07:43,660 --> 00:07:44,610
Can you guess how long.

105
00:07:44,620 --> 00:07:49,870
If it's in a batch if it's a single item in a batch and how long is train labels

106
00:07:57,980 --> 00:07:59,660
should have really run that in the next cell.

107
00:07:59,660 --> 00:08:04,820
So it didn't have to batch ify our data 32 32.

108
00:08:04,820 --> 00:08:05,320
There we go.

109
00:08:05,320 --> 00:08:07,560
So this is where next comes in.

110
00:08:07,610 --> 00:08:15,710
So we've taken our train data unmatched it using as Num pi iterator or turned it into an iterator.

111
00:08:15,710 --> 00:08:16,920
We've taken the next.

112
00:08:16,940 --> 00:08:18,170
So the one off the top.

113
00:08:18,170 --> 00:08:24,920
So essentially just taken the batch off the top and return the images and the labels whatever batch

114
00:08:24,920 --> 00:08:26,470
you're working with where we can with images.

115
00:08:26,470 --> 00:08:28,090
So this is why this is train images.

116
00:08:28,100 --> 00:08:32,420
If you're working with some other type of data this would be that other type of data and this would

117
00:08:32,420 --> 00:08:40,790
probably still be your labels but they are of length 32 because our batch size is 32.

118
00:08:40,970 --> 00:08:44,560
So now let's use our code net out.

119
00:08:44,660 --> 00:08:45,490
Sorry.

120
00:08:45,530 --> 00:08:48,310
Now visualization function.

121
00:08:48,350 --> 00:08:58,820
Now let's visualize the data in a training batch.

122
00:08:58,920 --> 00:09:04,440
What do we call it show 25 images show 25 images.

123
00:09:04,440 --> 00:09:05,670
Train images

124
00:09:08,310 --> 00:09:09,930
train labels

125
00:09:17,070 --> 00:09:19,500
wonderful.

126
00:09:19,550 --> 00:09:22,430
So this is the data we're working with.

127
00:09:22,460 --> 00:09:23,290
This is our training day.

128
00:09:23,310 --> 00:09:27,510
Notice how they're all squares because we've resize them to 4 and 2 to 4.

129
00:09:27,800 --> 00:09:33,620
And this is why I wanted to plot the Axis off because we want to get rid of that junk around the side.

130
00:09:34,010 --> 00:09:39,090
So let's do that because we're trying to display images here.

131
00:09:39,650 --> 00:09:40,850
Let's plot it again.

132
00:09:44,040 --> 00:09:45,080
Awesome.

133
00:09:45,120 --> 00:09:47,920
This is our training batch.

134
00:09:47,940 --> 00:09:48,960
If we come up here

135
00:09:52,950 --> 00:09:57,830
let's do the same for visualizing a validation batch.

136
00:09:57,990 --> 00:09:58,970
We run this again.

137
00:10:02,350 --> 00:10:05,980
Well actually I want to show you something that's going to highlight the difference if we copy this

138
00:10:05,980 --> 00:10:06,820
down here.

139
00:10:06,820 --> 00:10:09,350
We can remove that as well.

140
00:10:09,400 --> 00:10:10,530
This is what I was looking for.

141
00:10:11,710 --> 00:10:14,290
Every time we run this.

142
00:10:14,290 --> 00:10:16,070
So take note of this one here.

143
00:10:16,240 --> 00:10:18,060
So Lukey Tibetan terrier.

144
00:10:18,070 --> 00:10:19,690
Just remember these five images here.

145
00:10:20,780 --> 00:10:21,960
Now let's try run this again.

146
00:10:28,750 --> 00:10:33,670
We see how the top row is different and you'd notice the rest would actually be different as well.

147
00:10:33,670 --> 00:10:37,770
Now why do you think that is.

148
00:10:38,050 --> 00:10:43,850
It's because if we come up here when we create a training batch every time we call the training batch

149
00:10:43,850 --> 00:10:51,990
it's going to shuffle the data so if we were to go through this again while that's running we'll write

150
00:10:51,990 --> 00:10:54,990
out one for the validation set.

151
00:10:54,990 --> 00:10:59,020
Now let's visualize our validation set.

152
00:10:59,100 --> 00:11:00,080
So we'll go.

153
00:11:00,960 --> 00:11:06,030
Val images vow labels equals next.

154
00:11:06,860 --> 00:11:12,120
Val data dot as Num pi iterator.

155
00:11:12,120 --> 00:11:12,960
Wonderful.

156
00:11:12,960 --> 00:11:23,930
And then we'll go show twenty five images and we'll go Val images Val labels so we'll run that and we

157
00:11:23,930 --> 00:11:26,490
notice that we've got some different ones here.

158
00:11:26,510 --> 00:11:27,050
Hey look at that.

159
00:11:27,050 --> 00:11:28,730
That is holding that puppy.

160
00:11:28,730 --> 00:11:29,530
I could do this all day.

161
00:11:29,540 --> 00:11:31,710
Just look at that thing.

162
00:11:31,880 --> 00:11:35,580
How cute is that poppy so we'll run this one more time.

163
00:11:35,580 --> 00:11:38,580
Take note of this one remember this guy holding his dog here.

164
00:11:38,640 --> 00:11:47,860
Remember this one that looks kind of like a a shower curtain so we'll run that training and notices

165
00:11:47,880 --> 00:11:49,090
for validation as well.

166
00:11:49,090 --> 00:11:51,260
So remember this dog in the bathtub.

167
00:11:51,490 --> 00:11:57,150
And this one under the chair.

168
00:11:57,420 --> 00:12:03,330
We see the train images have changed because if we go back out when we created our data batch we shuffled

169
00:12:03,330 --> 00:12:08,950
the training images every time we create a batch and for our validation this one in the bathtub.

170
00:12:08,960 --> 00:12:17,060
Still here because we come up to where we created our validation batch we don't shuffle the validation

171
00:12:17,060 --> 00:12:17,720
data.

172
00:12:17,720 --> 00:12:20,140
Now keep thinking about why that might be important.

173
00:12:20,150 --> 00:12:21,140
We'll get to that in a moment.

174
00:12:21,140 --> 00:12:24,220
I know I've said that a few times now but just want to have you.

175
00:12:24,330 --> 00:12:27,030
Have you think about it for the time being.

176
00:12:27,200 --> 00:12:32,570
And so now that we've visualized we've created data batches and now we visualize them to make a bit

177
00:12:32,570 --> 00:12:38,090
more sense in our head I think the only next step is to see what we can do about building and training

178
00:12:38,090 --> 00:12:39,020
a model.

179
00:12:39,170 --> 00:12:40,520
Let's get onto that in the next video.
