We've just completed the section on pre-processing, and now we'll dive into data visualization.
Getting back to the code, let's import matplotlib.
So import matplotlib matplotlib pyplot as plt.
There we go.
And then we'll define or we'll create this figure and specify its figure size.
So we have fixed size which will be 50 by 50.
And then with this set we would go ahead and um plot out or visualize uh some elements in our validation
data set.
We'll start with the validation data set first because since we have no data augmentation, we will
have the the images looking exactly like what we have in the data set.
So we have for data in validation data set let's take out a single element.
Um, and also note that the batch size is two for now.
So we've set the batch size to two.
So we could visualize, um, two samples from our data set.
And then we would simply take the image.
So we have data and then we specify the pixel values.
Remember we had um created this dictionary made of pixel values and the labels.
And then we also obtain the labels.
Here we have data and then we have the labels.
There we go.
Now what we want to do is to create subplots.
Now the way we want the subplots to look like is simple.
We would have our image here.
Let's say our image is in blue one image, and then we have another image like this in blue, and then
we have the corresponding maps or the mask rather.
So we have the corresponding mask in red.
So we want to place the side by side.
There we go.
We have the, the the image and its corresponding mask.
We just want to have two samples uh like this simply so or here we have the image and then we have the
mask.
And then we'll have another image and then its corresponding mask.
And to build this we'll make use of subplots.
So we'll define a subplot which is made of just one row.
That's this row but for different columns.
So it's going to be made of one row and four columns one, two, three and four columns.
With that said, for I in range in in range for or better still, we could say batch size because our
batch size is two.
Now batch size by two because obviously we have the image and its mask.
So that's why we have batch times batch size times two.
And uh, if we have if I guess to four we just simply break.
But in this case I'm not going to break.
But if you have, uh, if we if you change the batch size, then you can have this case and we don't
we just want to have two samples.
So we we're going to break out, um, of the loop.
And, and then now we create our subplot.
So we have subplot and then we specify one row and four columns.
So we have batch size times um two I plus one.
So we keep there we go.
Let's take that off.
So we keep um incrementing I um that's it.
Um, if now that's in the case where we want to plot the image, let's in this case, we want to plot
the image since we're going from zero to or it's actually I goes from 0 to 4, so it's actually zero.
This is zero.
This is one.
This is two.
And then this is three and not four.
So we have 012, three.
So when whenever we plot images we will notice that this uh value that's zero modulo two zero mod two
is equal zero.
So zero mod two is equal zero and two mod two is equal zero.
But one mod two is equal one and three mod uh two is equal one.
So we just test if, um, the value of I modulo two is equal to zero, then we know that we are printing
out or we are going to, uh, plot out the image.
So let's get back to the code.
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,
then in this case we are going to be plotting out the image.
So we have image show um images.
So you see here we have images.
And then um we give it the title.
So the title will title it the image.
And then um else that's in the case where this modulo zero that if this modulo two I modulo two is not
equal zero, that's equal one.
Then we would instead plot out the labels.
So here we have him show um him show.
And then we plot out the labels.
So let's have the title title.
And then there we go.
We have labels.
That's it.
So we also do plot axis of.
So we don't want to have the axis shown.
And then we end up with plot um show.
There we go.
So that's it.
And let's run this and see what we obtain.
Now checking out uh, the reason why we have this error we see here invalid shape, um, two by three
by 512 by 512 for image data.
So clearly we needed to specify the batch.
So we have here I and then here we have I.
So let's run that again and then see what we get.
Um invalid shape for image data.
Now with matplotlib the inputs needs to be h by w by c.
That's height by weight by number of channels instead of instead of number of channels by width by uh
by rather by height.
By width.
So again, as we had seen last time, given that we're going from zero, this is zero, this is one.
And then this is two.
And we want to end up at this is zero, this is one year and this is two.
So we want to go.
We want to go from this position below to this other position above.
So now given that we want to move from c h w to h w c we are going to have two.
So this h previously was one.
So it's one.
And then the w previously was two.
So two.
And then the c previously was zero.
So zero.
Since we're going from this position to this position we just have to look at what this different um
values were before or they are different positions before.
So we have 1 to 0 and then we transpose.
So again here we're going to transpose um our image.
We have transpose.
Um and then we specify 120.
That's it.
Um that looks fine.
Let's run this again and see what we get.
There's a bracket that was never closed.
Let's close that up and run that again.
And we should get our.
Image is plotted.
We still have an error.
This time around, we have an image and its label.
And then the next time we get in this error, slide through.
Slide through and see what we get.
The error we get in is slice index two of dimension zero is out of bounds.
And when we look at the code we have written here is clear that, uh, when I goes, let's say to two,
then we'll be looking for images two.
And when I go to three looking for images three, whereas the batch size is just two and we want to
or we have only images or we only have two options, that's zero and one.
So one thing we could do is let's print this out so you understand why we make this modification.
Um, if we print this out, you would find that dividing and taking the whole value and not the remainder
makes or ensures that zero one is still zero, and then two three is still one.
So with this in mind, we would always have the first two samples simply.
Um, so let's just divide by two.
And then here we divide by two.
We run that and then we should have our images, um, and the masks printed correctly or output it correctly.
So there we go.
We see we have the image and then its corresponding mask.
Then here we have this image and also its corresponding mask.
Now let's change this a little.
Let's let's get to the train.
Let's have the train run that again and see what we get.
Could increase this so we could see that much clearer.
Um, there we go.
Okay, so we see now that our inputs have changed, uh, have been modified.
As you can see, we have this image.
You you could also see notice the shadow which we've added here.
Um, we also have the mask which matches up with the image.
We have this image which has been rotated, um, and we also have the mask which matches up.
So this is what we're going to train our models with.
Now let's, um, run this again because we have shuffling normally we should have different images printed
out so we could see, um, other options you see here.
Um, again, you have this rotated sort of direction, this rotate in this direction and that's it.
But you notice that the head is cut off the in both cases.
Anyways, um, you have an idea of, of the data.
You, you're dealing with.
Another way in which we could visualize our data is by making use of a specialized tool like voxel 51.
And this takes us to our visualization part two, where we are going to be making use of voxel or the
voxel 51 platform.