Process Images for Fine-Tuned MobileNet with TensorFlow's Keras API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey I'm Mandy from deep lizard in this episode we'll be preparing and processing a custom data set that we'll use to a fine-tuned mobile net using tensor flows Paris API previously we saw how well vgg 16 was able to classify and generalize on images of cats and dogs but we noted that vgg 16 was actually already trained on cats and dogs so it didn't take a lot of fine-tuning at all to get it to perform well on our cat and dog data set now with mobile net will be going through some fine tuning steps as well but this time we'll be working with a data set that is completely different from the original image net library for which mobile net was originally trained on this new data set that we'll be working with is the data set of images of sign language digits there are ten classes total for this data set ranging from zero to nine where each class contains images of the particular sign for that digit this data set is available on cackle as grayscale images but it's also available on github as RGB images and for our particular task we'll be using the RGB images so check out the corresponding blog for this episode on V Blizzard comm to get the link for where you can download the data set yourself so after downloading the data set the next step is to organize the data on disk and this will be a very similar procedure to what we saw for the cat and dog data set earlier in the course so once we have the download this is what it looks like it is a zip folder called sign language digits data set master and the first thing we want to do is extract all the contents of this directory and when we do that we can navigate inside until we get to the data set directory and inside here we have all of the classes and each of these directories has the corresponding images for this particular class so what we want to do is we want to grab zero through nine and we are going to control X or cut these directories and we're going to navigate back to the root directory which is here we're going to place all of the directories 0 through 9 in this route and then we're going to get rid of everything else by deleting so now one last thing is I'm just going to delete this master I don't necessarily like that so we have sign language digits data set and directly within we have our nested directories consisting of 0 through 9 each of which has our training data inside then the last step is to move the sign language digits data set directory to where you're going to be working so for me that is relative to my Jupiter notebook which lives inside of this deep learning with Karis directory I have a data directory and I have the sign language digits data set located here now everything else that will do to organize and process the data will be done programmatically in code so we are in our Jupiter notebook make sure that you do have the imports that we brought in last time still in place because we'll be making use of those now this is just the class breakdown to let you know how many images are in each class so across the class of 0 through 9 the there are anywhere from 204 to 208 samples in each class and then here I have just an explanation of how your data should be structured up to this point now the rest of the organization that we will do programmatically with this script here so this script is going to organize the data into trained valid and test directories so recall right now we just have all the data located in the corresponding classes of 0 through 9 but the data is not broken up yet into the separate data sets of trained tests and validation so to do that we are first changing directory into our sign language digits data set directory and then we are checking to make sure that the directory structure that we're about to set up is not already in place on disk and if it's not then we make train valid and test directory right within sign-language digits data set so next we are then iterating over all of the directories within our sign language digits data set directory so we're called those our directories is labeled 0 through 9 so that's what we're doing in this for loop with this range 0 to 10 that's going from directory 0 to 9 and moving each of these directories into our train directory and after that we're then making two new directories one inside of valid with the directory for whatever place we're at in the loop so if we are on run number 0 then we are making a directory called zero with invalid and a directory called 0 within test and if we are on run number 1 then we will be creating a directory called one with invalid and one within test so we do this whole process of moving each class in to train and then creating each class directory empty within valid and test so at this point let's suppose that we are on the first run in this for loop so in this range here we are following at number 0 so here on this line what we are doing is we are sampling 30 samples from our train / 0 directory because up here we created or we moved the class directory 0 into train and now we are going to sample 30 random samples from the 0 directory within train then so we're calling these valid samples because these are going to be these samples that we move into our validation set and we do that next so for each of the 30 san that we collected from the training set randomly in this line we're now going to be moving them from the training set to the validation 0 set to the validation set in class 0 and then we do similarly the same thing for the test samples we randomly select 5 samples from the train / 0 directory and then we move those 5 samples from that train / 0 directory into the test 0 directory so we just ran through that loop using the class 0 as an example but that's going to happen for each class 0 through 9 and just in case you have any issue with visualizing what that script does if we go into sign language digits data set now let's check out how we have organized the data so recall we previously had classes 0 through 9 all listed directly here within the this root folder now we have train valid and test directories and within train we moved the original 0 through 9 directories all into train and then once that was done then we sampled 30 images from each of these classes and moved them into the valid directory classes and then similarly we did the same thing for the test directory and then once we look in here we can see that the test directory has 5 samples for 0 we see that it has 5 samples for 1 if we go check out the valid directories look at 0 it should have 30 zeros so we see that here 30 so every valid directory has 30 samples and the training directory classes have not necessarily uniform samples because remember we saw that the number of samples in each class range anywhere from 204 to 209 think so the the number of images within each class directory for the training sample will differ slightly by maybe one or two images but the number of images in the classes for the validation and test directories will be uniform since we did that programmatically with our script here so checking this data set out on disk we can see that this is exactly the same format for which we structured our cat-and-dog image data set earlier in the course now we're just dealing with ten classes instead of two and when we downloaded our data it was in a slightly different organizational structure than the cat-and-dog data that we previously downloaded all right so we have obtained the data we've organized the data now the last step is to pre-process the data so we do that first by starting out by defining where our trained valid and test directories live on disk so we supply those paths here and now we are setting up our directory iterators which we should be familiar with at this point given this is the same format that we processed our cat and dog images whenever we built our CNN from scratch and we use the fine-tuned vgg 16 model so let's focus on this first variable train batches first we are calling image data generator dot flow from directory which we can't quite see here but we'll scroll in just a minute to image data generator we are passing this pre-processing function which in this case is the mobile net pre-processing function recall we saw that already in the last episode and there we discussed how this pre processes images in such a way that it scales the image data to be rather than on a scale from 0 to 255 to instead be on a scale from minus 1 to 1 so then on image data generator we call slow from directory which is flowing off the screen here and we set the directory equal to train path which we have defined just above saying where our training data resides on disk we are setting the target size to 224 by 224 which recall just resizes any training data to be a height or to have a height of 224 in a width of 224 since that is the image size that mobile net expects and we are setting our batch size equal to 10 so we've got the same deal for valid batches and for test batches as well everything exactly the same except for the paths differing to show where the validation and test sets live on disk and we are familiar now that we specify shuffle equals false only for our test set so that we can later appropriately plot our prediction results to a confusion matrix so we run this cell and we have output that we have 1700 and 12 images belonging to 10 classes so that corresponds to our training set 300 images to 10 classes for our validation set and 50 images belonging to 10 classes for our test set so I have this cell with several assertions here which just assert that this output that we find or that we have right here is what we expect so if you are not getting this then it's perhaps because you are pointing to the wrong location on disk so a lot of times if you're pointing to the wrong location then you'll probably get found at 0 images belonging to 10 classes so you just need to check your path to where your data set resides if you get that all right so now our data set has been processed we're now ready to move on to building and fine-tuning our mobile net model for this data set by the way we are currently in Vietnam filming this episode if you didn't know we also have a vlog channel where we document our travels and share a little bit more about ourselves so check that out at people's our vlog on YouTube also be sure to check out the corresponding blog for this episode along with other resources available on B+ or comm and check out the details or type mine where you can gain exclusive access to perks and rewards thanks for contributing to collective intelligence I'll see you next time [Music] [Music]
Info
Channel: deeplizard
Views: 14,604
Rating: undefined out of 5
Keywords: deep learning, pytorch, cuda, gpu, cudnn, nvidia, training, train, activation function, AI, artificial intelligence, artificial neural network, autoencoders, batch normalization, clustering, CNN, convolutional neural network, data augmentation, education, Tensorflow.js, fine-tune, image classification, Keras, learning, machine learning, neural net, neural network, Python, relu, Sequential model, SGD, supervised learning, Tensorflow, transfer learning, tutorial, unsupervised learning, TFJS
Id: R39bFP1UCyk
Channel Id: undefined
Length: 13min 40sec (820 seconds)
Published: Mon Sep 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.