1
00:00:00,080 --> 00:00:06,080
We've just completed the section on pre-processing, and now we'll dive into data visualization.

2
00:00:06,080 --> 00:00:10,040
Getting back to the code, let's import matplotlib.

3
00:00:10,040 --> 00:00:17,270
So import matplotlib matplotlib pyplot as plt.

4
00:00:17,360 --> 00:00:18,260
There we go.

5
00:00:18,260 --> 00:00:23,930
And then we'll define or we'll create this figure and specify its figure size.

6
00:00:23,930 --> 00:00:28,880
So we have fixed size which will be 50 by 50.

7
00:00:28,880 --> 00:00:38,660
And then with this set we would go ahead and um plot out or visualize uh some elements in our validation

8
00:00:38,660 --> 00:00:39,110
data set.

9
00:00:39,110 --> 00:00:44,810
We'll start with the validation data set first because since we have no data augmentation, we will

10
00:00:44,810 --> 00:00:48,710
have the the images looking exactly like what we have in the data set.

11
00:00:48,710 --> 00:00:55,070
So we have for data in validation data set let's take out a single element.

12
00:00:55,250 --> 00:00:58,160
Um, and also note that the batch size is two for now.

13
00:00:58,160 --> 00:01:00,050
So we've set the batch size to two.

14
00:01:00,080 --> 00:01:03,200
So we could visualize, um, two samples from our data set.

15
00:01:03,200 --> 00:01:05,540
And then we would simply take the image.

16
00:01:05,540 --> 00:01:09,410
So we have data and then we specify the pixel values.

17
00:01:09,410 --> 00:01:15,020
Remember we had um created this dictionary made of pixel values and the labels.

18
00:01:15,020 --> 00:01:17,510
And then we also obtain the labels.

19
00:01:17,510 --> 00:01:20,420
Here we have data and then we have the labels.

20
00:01:20,420 --> 00:01:21,140
There we go.

21
00:01:21,140 --> 00:01:24,200
Now what we want to do is to create subplots.

22
00:01:24,230 --> 00:01:27,380
Now the way we want the subplots to look like is simple.

23
00:01:27,380 --> 00:01:29,660
We would have our image here.

24
00:01:29,660 --> 00:01:35,690
Let's say our image is in blue one image, and then we have another image like this in blue, and then

25
00:01:35,690 --> 00:01:39,080
we have the corresponding maps or the mask rather.

26
00:01:39,080 --> 00:01:41,990
So we have the corresponding mask in red.

27
00:01:42,290 --> 00:01:44,570
So we want to place the side by side.

28
00:01:44,900 --> 00:01:45,680
There we go.

29
00:01:45,680 --> 00:01:49,130
We have the, the the image and its corresponding mask.

30
00:01:49,130 --> 00:01:55,550
We just want to have two samples uh like this simply so or here we have the image and then we have the

31
00:01:55,550 --> 00:01:56,210
mask.

32
00:01:56,210 --> 00:02:01,370
And then we'll have another image and then its corresponding mask.

33
00:02:01,370 --> 00:02:04,310
And to build this we'll make use of subplots.

34
00:02:04,310 --> 00:02:08,810
So we'll define a subplot which is made of just one row.

35
00:02:08,840 --> 00:02:12,110
That's this row but for different columns.

36
00:02:12,110 --> 00:02:19,550
So it's going to be made of one row and four columns one, two, three and four columns.

37
00:02:20,110 --> 00:02:28,300
With that said, for I in range in in range for or better still, we could say batch size because our

38
00:02:28,300 --> 00:02:29,380
batch size is two.

39
00:02:29,410 --> 00:02:33,640
Now batch size by two because obviously we have the image and its mask.

40
00:02:33,640 --> 00:02:36,970
So that's why we have batch times batch size times two.

41
00:02:36,970 --> 00:02:42,730
And uh, if we have if I guess to four we just simply break.

42
00:02:42,730 --> 00:02:43,840
But in this case I'm not going to break.

43
00:02:43,840 --> 00:02:49,210
But if you have, uh, if we if you change the batch size, then you can have this case and we don't

44
00:02:49,210 --> 00:02:50,650
we just want to have two samples.

45
00:02:50,650 --> 00:02:53,920
So we we're going to break out, um, of the loop.

46
00:02:53,920 --> 00:02:56,890
And, and then now we create our subplot.

47
00:02:56,890 --> 00:03:04,690
So we have subplot and then we specify one row and four columns.

48
00:03:04,690 --> 00:03:10,150
So we have batch size times um two I plus one.

49
00:03:10,150 --> 00:03:11,770
So we keep there we go.

50
00:03:11,770 --> 00:03:12,550
Let's take that off.

51
00:03:12,550 --> 00:03:16,000
So we keep um incrementing I um that's it.

52
00:03:16,480 --> 00:03:22,210
Um, if now that's in the case where we want to plot the image, let's in this case, we want to plot

53
00:03:22,210 --> 00:03:28,510
the image since we're going from zero to or it's actually I goes from 0 to 4, so it's actually zero.

54
00:03:28,540 --> 00:03:29,710
This is zero.

55
00:03:29,740 --> 00:03:31,060
This is one.

56
00:03:31,060 --> 00:03:32,500
This is two.

57
00:03:32,500 --> 00:03:35,800
And then this is three and not four.

58
00:03:35,800 --> 00:03:37,930
So we have 012, three.

59
00:03:37,930 --> 00:03:48,580
So when whenever we plot images we will notice that this uh value that's zero modulo two zero mod two

60
00:03:49,210 --> 00:03:51,580
is equal zero.

61
00:03:51,580 --> 00:03:55,930
So zero mod two is equal zero and two mod two is equal zero.

62
00:03:55,930 --> 00:03:59,530
But one mod two is equal one and three mod uh two is equal one.

63
00:03:59,530 --> 00:04:05,800
So we just test if, um, the value of I modulo two is equal to zero, then we know that we are printing

64
00:04:05,800 --> 00:04:09,430
out or we are going to, uh, plot out the image.

65
00:04:09,760 --> 00:04:11,380
So let's get back to the code.

66
00:04:11,380 --> 00:04:19,420
And what we'll do here is if I modulo two is equal to zero, that's if I modulo two is equal to zero,

67
00:04:19,420 --> 00:04:22,480
then in this case we are going to be plotting out the image.

68
00:04:22,480 --> 00:04:25,990
So we have image show um images.

69
00:04:25,990 --> 00:04:27,730
So you see here we have images.

70
00:04:27,730 --> 00:04:31,030
And then um we give it the title.

71
00:04:31,030 --> 00:04:33,730
So the title will title it the image.

72
00:04:33,850 --> 00:04:43,210
And then um else that's in the case where this modulo zero that if this modulo two I modulo two is not

73
00:04:43,210 --> 00:04:44,950
equal zero, that's equal one.

74
00:04:44,950 --> 00:04:48,430
Then we would instead plot out the labels.

75
00:04:48,430 --> 00:04:53,140
So here we have him show um him show.

76
00:04:53,140 --> 00:04:55,090
And then we plot out the labels.

77
00:04:55,090 --> 00:04:59,350
So let's have the title title.

78
00:04:59,350 --> 00:05:01,030
And then there we go.

79
00:05:01,030 --> 00:05:02,560
We have labels.

80
00:05:02,590 --> 00:05:03,310
That's it.

81
00:05:03,310 --> 00:05:08,800
So we also do plot axis of.

82
00:05:08,800 --> 00:05:11,230
So we don't want to have the axis shown.

83
00:05:11,230 --> 00:05:17,830
And then we end up with plot um show.

84
00:05:17,920 --> 00:05:18,730
There we go.

85
00:05:18,730 --> 00:05:19,480
So that's it.

86
00:05:19,480 --> 00:05:22,300
And let's run this and see what we obtain.

87
00:05:22,480 --> 00:05:28,810
Now checking out uh, the reason why we have this error we see here invalid shape, um, two by three

88
00:05:28,810 --> 00:05:31,780
by 512 by 512 for image data.

89
00:05:31,780 --> 00:05:36,250
So clearly we needed to specify the batch.

90
00:05:36,250 --> 00:05:40,990
So we have here I and then here we have I.

91
00:05:41,020 --> 00:05:43,930
So let's run that again and then see what we get.

92
00:05:44,290 --> 00:05:46,390
Um invalid shape for image data.

93
00:05:46,420 --> 00:05:52,150
Now with matplotlib the inputs needs to be h by w by c.

94
00:05:52,180 --> 00:05:59,500
That's height by weight by number of channels instead of instead of number of channels by width by uh

95
00:05:59,500 --> 00:06:00,820
by rather by height.

96
00:06:00,820 --> 00:06:01,570
By width.

97
00:06:01,780 --> 00:06:08,380
So again, as we had seen last time, given that we're going from zero, this is zero, this is one.

98
00:06:08,380 --> 00:06:09,730
And then this is two.

99
00:06:09,790 --> 00:06:15,640
And we want to end up at this is zero, this is one year and this is two.

100
00:06:16,030 --> 00:06:17,620
So we want to go.

101
00:06:17,620 --> 00:06:23,530
We want to go from this position below to this other position above.

102
00:06:23,530 --> 00:06:31,600
So now given that we want to move from c h w to h w c we are going to have two.

103
00:06:31,630 --> 00:06:34,420
So this h previously was one.

104
00:06:34,420 --> 00:06:35,470
So it's one.

105
00:06:35,470 --> 00:06:39,340
And then the w previously was two.

106
00:06:39,370 --> 00:06:40,660
So two.

107
00:06:40,810 --> 00:06:43,630
And then the c previously was zero.

108
00:06:43,630 --> 00:06:44,650
So zero.

109
00:06:44,650 --> 00:06:50,680
Since we're going from this position to this position we just have to look at what this different um

110
00:06:50,680 --> 00:06:54,160
values were before or they are different positions before.

111
00:06:54,160 --> 00:06:56,740
So we have 1 to 0 and then we transpose.

112
00:06:56,740 --> 00:07:00,370
So again here we're going to transpose um our image.

113
00:07:00,370 --> 00:07:02,830
We have transpose.

114
00:07:03,190 --> 00:07:07,720
Um and then we specify 120.

115
00:07:07,750 --> 00:07:08,500
That's it.

116
00:07:08,980 --> 00:07:10,060
Um that looks fine.

117
00:07:10,060 --> 00:07:11,950
Let's run this again and see what we get.

118
00:07:12,340 --> 00:07:14,530
There's a bracket that was never closed.

119
00:07:14,530 --> 00:07:17,290
Let's close that up and run that again.

120
00:07:17,440 --> 00:07:19,270
And we should get our.

121
00:07:19,430 --> 00:07:20,630
Image is plotted.

122
00:07:21,020 --> 00:07:22,400
We still have an error.

123
00:07:22,640 --> 00:07:24,800
This time around, we have an image and its label.

124
00:07:24,800 --> 00:07:28,730
And then the next time we get in this error, slide through.

125
00:07:29,420 --> 00:07:32,330
Slide through and see what we get.

126
00:07:32,330 --> 00:07:38,060
The error we get in is slice index two of dimension zero is out of bounds.

127
00:07:38,060 --> 00:07:46,340
And when we look at the code we have written here is clear that, uh, when I goes, let's say to two,

128
00:07:46,370 --> 00:07:48,260
then we'll be looking for images two.

129
00:07:48,260 --> 00:07:55,940
And when I go to three looking for images three, whereas the batch size is just two and we want to

130
00:07:55,940 --> 00:08:00,860
or we have only images or we only have two options, that's zero and one.

131
00:08:00,860 --> 00:08:06,230
So one thing we could do is let's print this out so you understand why we make this modification.

132
00:08:06,500 --> 00:08:13,610
Um, if we print this out, you would find that dividing and taking the whole value and not the remainder

133
00:08:13,850 --> 00:08:19,790
makes or ensures that zero one is still zero, and then two three is still one.

134
00:08:19,790 --> 00:08:25,730
So with this in mind, we would always have the first two samples simply.

135
00:08:26,090 --> 00:08:28,340
Um, so let's just divide by two.

136
00:08:28,340 --> 00:08:30,680
And then here we divide by two.

137
00:08:30,740 --> 00:08:38,270
We run that and then we should have our images, um, and the masks printed correctly or output it correctly.

138
00:08:38,270 --> 00:08:39,200
So there we go.

139
00:08:39,200 --> 00:08:42,680
We see we have the image and then its corresponding mask.

140
00:08:42,680 --> 00:08:46,340
Then here we have this image and also its corresponding mask.

141
00:08:46,340 --> 00:08:48,380
Now let's change this a little.

142
00:08:48,380 --> 00:08:50,180
Let's let's get to the train.

143
00:08:50,390 --> 00:08:54,650
Let's have the train run that again and see what we get.

144
00:08:55,970 --> 00:08:58,340
Could increase this so we could see that much clearer.

145
00:08:59,240 --> 00:09:02,120
Um, there we go.

146
00:09:02,120 --> 00:09:07,580
Okay, so we see now that our inputs have changed, uh, have been modified.

147
00:09:07,580 --> 00:09:09,350
As you can see, we have this image.

148
00:09:09,770 --> 00:09:13,040
You you could also see notice the shadow which we've added here.

149
00:09:13,520 --> 00:09:16,880
Um, we also have the mask which matches up with the image.

150
00:09:16,880 --> 00:09:21,980
We have this image which has been rotated, um, and we also have the mask which matches up.

151
00:09:21,980 --> 00:09:24,860
So this is what we're going to train our models with.

152
00:09:24,860 --> 00:09:30,920
Now let's, um, run this again because we have shuffling normally we should have different images printed

153
00:09:30,920 --> 00:09:34,130
out so we could see, um, other options you see here.

154
00:09:34,610 --> 00:09:40,160
Um, again, you have this rotated sort of direction, this rotate in this direction and that's it.

155
00:09:40,160 --> 00:09:44,660
But you notice that the head is cut off the in both cases.

156
00:09:44,780 --> 00:09:48,920
Anyways, um, you have an idea of, of the data.

157
00:09:48,920 --> 00:09:50,390
You, you're dealing with.

158
00:09:50,390 --> 00:09:58,820
Another way in which we could visualize our data is by making use of a specialized tool like voxel 51.

159
00:09:58,820 --> 00:10:05,720
And this takes us to our visualization part two, where we are going to be making use of voxel or the

160
00:10:05,720 --> 00:10:07,250
voxel 51 platform.
