In this lesson we're going to poke around a bit more and start exploring our data.
So far we formulated our question.
We know what we want to do.
We set out to classify images according to ten different categories or classes.
We've also gathered data and very very handily.
They've already been split into training and testing data.
Now we're getting to this data cleaning and processing and exploration stage back in our Jupiter notebook.
Let's insert a markdown cell here explore the data and the first thing I want to do is I want to pull
up some of these pictures.
So when I go back up to my inputs and I want input to things I want to see from eye Python dot display
import display and I want to see from Charisse dot pre processing dot image import array to image I
AMG and you know what I'm actually going to input a third thing I'm going to input that plot lib so
I'll add import matter plot lib dot pie plot as P.L. T.
And just below a lot.
Percent match.
Plot lib space inline shift enter.
And now let me come down here and let's throw some of these images up on screen and take a closer look
at them.
So the reason I imported I Python display and plot lib is because I wanted to show you two different
ways that you can display an image in Jupiter notebook.
So the first one is with a python display.
And what I'm going to do is actually look at the very first item in our training dataset.
So X train underscore all square brackets zero.
It's the very first item and shift enter will actually show us what this image looks like at the moment.
And if we wanted to see this whole thing as an actual image then we're going to make use of this array
to image functionality from Chris's pre processing module.
So what we can do is store that image in a variable called pick and that will be equal to array to image
parentheses and then we can pick one of the images from our training dataset.
See we picked the.
I don't know seventh image using a python display.
We can then throw that up on the screen with display parentheses and then supply our picture as an argument.
So this is what the seventh picture will look like now.
I hope you can tell it this is a very tiny picture of a horse and we should be able to verify that this
is indeed a horse.
By looking at the image labels which are found in the y values.
So why honest quatrain on a scroll all don't shape.
Well show us what are y values actually look like.
All right we've got a number higher rate of 50000 labels and it's two dimensional.
So if I wanted to pull up the y value at index 7 then I would write y on as Katrina and a square all
square brackets 7 and then another square brackets 0.
And what we get is the values 7 so it doesn't say horse.
It just says 7.
Now why is that.
Well let's pull up Alex's website again.
So if I look at his little breakdown here I think this is really handy.
These are in order right.
I can see that values 7 should correspond to 0 1 2 3 4 5 6 7 corresponds to a horse.
So what we've got here are the names for these different labels.
Label number 0 will be our plain label number 7 will be horse label number 9 will be truck.
Now it's no good just having this on this website.
I think what we should do is actually add these to our notebook.
So up here I'm going to add another markdown cell and I'm going to add some constants here so constants.
And among those constants will be this list of names because then we can easily refer to it later on.
So I'm just type label underscore names.
So here will create a list that contains all the label names in order plane car bird cat Dear Dog frog.
Horse ship and truck shift enter on that.
We can scroll back down and what we should be able to do is hit up our label names list open some square
brackets and we can put the label at the index number seven in here and I'll paste that right in it
shift into Astra get horse.
OK.
Brilliant.
So that makes sense to me.
But I think we should look at another image just to double check it works and look at this image.
Let's use matte plot lib so we can actually use matte plot lib and through the image onto a plot because
this image is actually just an array of pixels matte plot lib knows how to handle this.
So with Piti dot I am show parentheses x underscore a train underscore all and then say square brackets
and then let's pick the fifth image at index for close the parentheses and then on the next line will
at Peel T dot show and hit shift enter.
Let's throw this image up on screen.
So what we've got here is a chart every five pixels has got a tick mark.
And for our convenience this is a slightly enlarged but it's definitely a car right.
We can verify this by checking our list of label names right.
So with Peel T dot X label we can look towards our list of labels and then insert the label on the x
axis.
So peel teed up X label parentheses label names square brackets and then we'll use the same technique
as above.
Right.
We're going to look to our y underscore train underscore all umpiring could put some square brackets
there when you use the same index in x4.
And we're going to use another pair square brackets and then zero because we're quite a two dimensional
num pi array.
So I know it's a lot of nesting here but we're pulling out a value from our y unescorted train underscore
all and we're using that as the index in our list of label names and we're gonna display that on our
x axis.
And if this works we should see the word card written here.
If this is too small can of course enlarge the font size.
So an extra argument here and font size 15 will make this much much more legible.
So this is pretty cool right.
We've got our images that are stored as Num higher arrays in our data set and we've got two ways of
displaying them in our Jupiter notebook.
The first way is using a python display.
And the second way is actually throwing them up onto a mat plot lib chart.
Now I quite like Matt put lib actually one of the reasons is that's very easy to display these images
side by side and just take a look at a few more from this dataset.
So I might ask you to solve this as a challenge.
Can you write a for loop to display the first 10 images from the X underscore train underscore all the
data set.
Remember this is a number primary and I'd like you to display all these images in a row and I'd like
you to show the label below.
Each image and if you can format the images in such a way that we're not seeing any of these tick marks
here like we are in the cell above.
I'll give you a few seconds to pause the video and give this a go
ready.
Here's the solution.
The first thing I'm going to do is an asset the size of my chart or of my figure.
So PDT don't figure parentheses fixed size equals parentheses 15 by 5.
Well size my chart nicely and then I'm going to write this for loop.
For i in range 10.
This for loop will go through the numbers 0 through 9 and I can show you this if I print I here.
But inside my loop what I want to do is actually create some subplots using my plot lib.
This is what the challenge was about so I'll say BLT dot subplot and then my subplot will require three
inputs right.
One how many rows 10 how many columns and then because we're in a for loop we're going to have to figure
out which subplot we want to create at each iteration.
So in this case it's going to be I plus one because the first plot should be number one and the last
subplot should be number 10 but I starts from zero.
It goes up until 9.
So this is why if I plus one and then we'll use PDT dot I am show parentheses x underscore train underscore
all square brackets.
I let's see what this gives us what we see here is 10 images in a row in a figure that assigns 15 by
fives and number seven here.
So of course our horse and the image at index number four is our call to remove those tick marks.
We can do that with peeled T dot y ticks parentheses square brackets and peel T dot X takes parentheses
square brackets so square brackets are empty.
So this means that my tick marks will be blank.
Now all I have to do is insert those labels below the images.
So I want to do that with peeled T dot X label and then want to use the very same technique I've got
above.
I want to take my list of label names and in the square brackets I'm going to look towards my dataset
of training labels y on a squat train underscore all square brackets and again I for the index and square
brackets zero for that second dimension.
Let me hit shift enter on this.
And there we go.
There are our tiny little labels underneath our tiny little images.
And because that's very hard to read.
I'll increase the font size once again to say maybe 14.
Try that.
There we go.
That's a lot more legible.
Brilliant.
So what we see here is that our list of a label names matches up nicely with the numbers in the y underscore
train underscore all of an umpire Ray seems to be indeed a bird.
And this seems to be a ship and we've got a cat and a deer.
I think this sort of evil looking red eyed frog is a definitely a keeper.
But yeah what we're seeing here are indeed the first 10 images in our training dataset.
So the next thing to understand about this data set is how these images are formatted so x underscore
train underscore all square brackets zero.
That frog is formatted like so but if we look at the shape of it we see that it is 32 by 32 by 3.
Now this is interesting because 32 and 32 are the width and the height and three is the number of channels.
So when I say channels I'm talking about colors.
We've got a red channel.
We've got a green channel and we've got a blue channel.
So this is gonna be in our GP format.
If we look at our number higher rate as a whole so X and it's Katrina on the square all that shape we
get to see that this thing has actually four dimensions.
Right.
So we've got 50000 entries and each of these entries is 32 pixels by 32 pixels by three.
Let's make this more explicit.
Right.
So let's see number of images comma X come out.
Why comma.
C is equal to X and a quatrain underscore all that shape.
If we do this then we can add a nice little print statement here below with an F string so print open
parentheses f single quotes and then we can write images is equal to curly braces.
Number of images no underscore images.
And then we can insert some formatting so backslash T for a tab and then a pipe maybe and then we'll
see width is equal to curly braces.
X backslash t pipe height is equal to curly braces.
Y backslash t channels is equal to curly braces.
See me at that pipe symbol here and hit shift center.
I think this is a really nice thing to have in a notebook.
If you're going to take a break and come back to it later on to be reminded of the structure of the
data all in all we've got 50000 training images.
We've got a width in pixels of 32.
So this is our x value.
We've got a height in pixels of 32.
This is our y value and we've got three color channels per pixel.
So we've got three values per pixel now considering we've got 50000 training images.
How many testing images do we have on those for test that shape and shift into shows us that we've got
10000 testing images now that we know what our dataset consists of and how our information is formatted.
It's time to pre process our data for our neural network.
Considering that we loaded this data directly from cameras there's actually not much need for cleaning
but we will do some pre processing for our neural network to make our lives a little easier.
And we're going to cover all that and more in the next lesson.
I'll see you there.