Now we've got our data in batches but it could be a little bit hard to understand what's going on in
a batch.
So let's build a little function which is going to explore what's in our batch so we can visualize what's
happening because if we have this little output here we know deep down that these are actually images
and these labels it would be good to see them.
So let's make a little heading here.
Visualizing data batches command Imam to turn it into markdown and let's give ourselves a little bit
of communication.
A data is now in batches.
However these can be a little hard to understand slash comprehend.
Let's visualize them because I'm not sure about you but I like to see things in action.
So to do that we'll import our trusty map plot lib.
Look at that auto suggestion and then we'll go create a function for viewing images in a data match
or a data batch data we Australians the Australian accent liked to throw us onto the end of vowels wherever
they are.
We might do it to show 25 images because if we're doing too many like we have 10000 plus so we might
just show twenty five at a time and we want images and labels because what we're going to do is basically
plot an image and then above it put the label and nice and simple window displays a plot of twenty five
images and name labels from a data batch.
Wonderful.
All right so let's set up the figure peyote dot figure will make it big size.
Now I've had a little bit of experience with setting up this plot size so hopefully ten by 10 is good
enough.
If not we can change that.
Then we'll go loop through twenty five for displaying twenty five images.
So we'll just set up a simple loop for i in range twenty five then what can we do.
Well we need to create a subplot.
Let's make it five rows five columns because that's twenty five and then we'll have to display an image
on each of the subplots and then add a title to each of the images.
That shouldn't be too hard.
So create subplots we'll go five rows five columns.
AX equals penalty dot subplot five five I plus one.
So this is God's.
Because we have an imported map plot lib yet.
That's what the doctoring isn't showing up.
There we go.
Parameters.
Where do we go.
A couple rows.
Column.
So this is number rows.
This is columns and this is index.
That's where you need to know display an image some of the map plot lib docs strings can be a bit annoying.
Like when they go args keyword ARGs and it just inherits all some other class and you can't really find
it if you need to check out what this actually does.
Check out the map slightly full blown documentation.
We want to plot the IFE image.
So because we're looping through.
This is gonna be a data bunch of images and labels.
So we want to show the IFE image.
So the IFE index my saying that right the image and add the image label as the title.
So we appeal to you not title and then unique braids because that's our list.
Remember if it still lives in memory it should.
Unique braids is our list of unique dog names get the unique breeds label we want to index that where
it labels the label is the maximum value.
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
up their unique braids.
So this is this line here is the title of our plot boom.
See what I mean by D function izing functions to really explore what's going on.
So if you want to figure something out.
Remember always you can just pull the function apart rewrite the code for yourself because that's how
you're going to understand something.
Turn the red lines off actually.
We might see it with them on before.
So we know exactly what this is doing rotate on axis.
That's a nice simple function show 25 images.
What do you need to know now.
So because our data is in a batch we need to essentially on batch it to visualize it so we can do that
by going train images.
Let's see the code first.
Then we'll see what's actually happening.
Train labels equals next.
So what next year is it.
It returns the next item from an iterator.
Oh well thank you Dr. King for that because train data is in the format of a batch.
So if we go train data we need to turn it into an iterator There we go.
So we can do that by calling the method as Num pi iterator and once is going to say returns and iterator
which converts all elements of the data set to num pi.
So basically what this is going to do is turn Oh there we go.
We got some information here.
Those docs strings are a little bit hard to read.
They're for me.
Let's just go through here what's it gonna do.
This is gonna take our batch dataset.
It's gonna unwind it from a batch and turn it into a num PI.
It's right up and then thanks to next it's going to grab the first batch off the top of this out of
this iterator and then because it's split it it's unbalanced it training images.
So this one here this shape here is going to be the first thing that gets returned and train labels
is going to be the next thing that gets returned.
So don't take my word for it.
If in doubt run the code.
Now the reason this might take a little while to run is because if you remember when we batch you fired
our data set up here.
We've got this map function.
Get image label which is going to process our images.
So that's why when we're working with batches now because whenever we run it it's going to process our
images in the background.
So there we go.
So instead of dealing with file names now we're actually dealing with processed images.
So a little bit more data.
This is a massive array right because we've got train images.
This should be.
Let's see how long it is.
Can you guess how long.
If it's in a batch if it's a single item in a batch and how long is train labels
should have really run that in the next cell.
So it didn't have to batch ify our data 32 32.
There we go.
So this is where next comes in.
So we've taken our train data unmatched it using as Num pi iterator or turned it into an iterator.
We've taken the next.
So the one off the top.
So essentially just taken the batch off the top and return the images and the labels whatever batch
you're working with where we can with images.
So this is why this is train images.
If you're working with some other type of data this would be that other type of data and this would
probably still be your labels but they are of length 32 because our batch size is 32.
So now let's use our code net out.
Sorry.
Now visualization function.
Now let's visualize the data in a training batch.
What do we call it show 25 images show 25 images.
Train images
train labels
wonderful.
So this is the data we're working with.
This is our training day.
Notice how they're all squares because we've resize them to 4 and 2 to 4.
And this is why I wanted to plot the Axis off because we want to get rid of that junk around the side.
So let's do that because we're trying to display images here.
Let's plot it again.
Awesome.
This is our training batch.
If we come up here
let's do the same for visualizing a validation batch.
We run this again.
Well actually I want to show you something that's going to highlight the difference if we copy this
down here.
We can remove that as well.
This is what I was looking for.
Every time we run this.
So take note of this one here.
So Lukey Tibetan terrier.
Just remember these five images here.
Now let's try run this again.
We see how the top row is different and you'd notice the rest would actually be different as well.
Now why do you think that is.
It's because if we come up here when we create a training batch every time we call the training batch
it's going to shuffle the data so if we were to go through this again while that's running we'll write
out one for the validation set.
Now let's visualize our validation set.
So we'll go.
Val images vow labels equals next.
Val data dot as Num pi iterator.
Wonderful.
And then we'll go show twenty five images and we'll go Val images Val labels so we'll run that and we
notice that we've got some different ones here.
Hey look at that.
That is holding that puppy.
I could do this all day.
Just look at that thing.
How cute is that poppy so we'll run this one more time.
Take note of this one remember this guy holding his dog here.
Remember this one that looks kind of like a a shower curtain so we'll run that training and notices
for validation as well.
So remember this dog in the bathtub.
And this one under the chair.
We see the train images have changed because if we go back out when we created our data batch we shuffled
the training images every time we create a batch and for our validation this one in the bathtub.
Still here because we come up to where we created our validation batch we don't shuffle the validation
data.
Now keep thinking about why that might be important.
We'll get to that in a moment.
I know I've said that a few times now but just want to have you.
Have you think about it for the time being.
And so now that we've visualized we've created data batches and now we visualize them to make a bit
more sense in our head I think the only next step is to see what we can do about building and training
a model.
Let's get onto that in the next video.