‫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
‫are labels.
‫It would be good to see them.
‫So let's make a little heading here.
‫Visualizing data batches command on M 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 a create a function for viewing images in a data batch
‫or data batch data.
‫We Australians, the Australian accent like to throw R's onto the end of vowels wherever they are.
‫We might do it just show 25 images because if we're doing too many, like we have 10,000 plus, so we
‫might just show 25 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.
‫Go displays a plot of 25 images and their labels from a data batch.
‫Wonderful.
‫All right, so let's set up the figure.
‫Go figure.
‫We'll make it fig size.
‫Now, I've had a little bit of experience with setting up this plot size, so hopefully ten by ten is
‫good enough.
‫If not, we can change that.
‫Then we'll go loop through 25 for displaying 25 images.
‫So we just set up a simple loop for I in range 25.
‫Then what can we do?
‫Well, we need to create a subplot.
‫Let's make it five rows.
‫Five columns, because that's 25.
‫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, go x equals plot dot subplot, five, five plus one.
‫So this is oh, it's because we have an imported map plot lib yet that's why the docstring isn't showing
‫up.
‫There we go.
‫Parameters.
‫Where do we go?
‫It got Rose column.
‫So this is a number of rows.
‫This is columns and this is index.
‫That's all you need to know.
‫Display an image.
‫Some of the map plot lib dot strings can be a bit annoying like when they go args keyword args and it
‫just inherits some other class and you can't really find it.
‫If you need to check out what this actually does, check out the map.
‫Plot lib full blown documentation.
‫We want to plot the image.
‫So because we're looping through, this is going to be a data bunch of images and labels.
‫So we want to show the image.
‫So the index we're saying that write the image and add the image label as the title.
‫So we're going to plot title and then unique breeds because that's our list.
‫Remember, if it still lives in memory, it should unique breeds is our list of unique dog names.
‫Get the unique breeds label.
‫We want to index that where labels the label is the maximum value.
‫So in other words, if we go why zero arg max?
‫19.
‫This is just exactly what we're going to be doing with that line up there.
‫Unique breeds.
‫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.
‫PLT axis.
‫That's a nice simple function.
‫Show 25 images.
‫What do we need to do now?
‫So because our data is in a batch, we need to essentially UN 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 is is it's it returns the next item from an iterator.
‫Oh well thank you docstring 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 NumPy.
‫Iterator.
‫And what's it's going to say returns an iterator which converts all elements of the data set to numpy.
‫So basically what this is going to do is turn.
‫Oh, there we go.
‫We've got some information here.
‫Those doc strings are a little bit hard to read there for me.
‫But let's just go through here.
‫What's it going to do?
‫So it's going to take our batch data set.
‫It's going to unwind it from a batch and turn it into a numpy iterator.
‫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 unmatched 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 beatified
‫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 backfire.
‫Our data.
‫32, 32.
‫There we go.
‫So this is where Nex comes in.
‫So we've taken our train data unpatched it using as numpy iterator or turned it into an iterator.
‫We've taken the next so the one off the top.
‫So essentially just taken that batch off the top and returned the images and the labels.
‫Whatever batch you're working with, we're working 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 like 32 because our batch size is.
‫32.
‫So now let's use our code, our sorry, our visualization function.
‫Now, let's visualize the data in a training batch.
‫What did we call it?
‫Show 25 images.
‫Train images.
‫Train labels.
‫Wonderful.
‫So this is the data we're working with.
‫This is our training data.
‫Notice how they're all squares because we've resized them 2 to 4 and 2 to 4.
‫And this is why I wanted to plot the access 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.
‫Now, if we come up here.
‫Let's do the same for visualizing a validation batch.
‫We run this again.
‫Oh, 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, Saluki, Tibetan Terrier.
‫Just remember these five images here.
‫Now let's try to 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 do 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.
‫Val Labels equals next validator dot as num py iterator.
‫Wonderful.
‫And then we'll go show 25 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 dude's holding that puppy.
‫I could do this all day.
‫Just look at that thing.
‫How cute is that puppy?
‫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 shower curtain?
‫So we'll run that training.
‫And notice this for validation as well.
‫So remember this dog in the bathtub and this one under the chair.
‫Ah, we see the train images have changed because if we go back up, 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 visualized, we've created data batches and now we've visualized 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 on to that in the next video.