Data Augmentation with TensorFlow's Keras API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey I'm Mandy from D Blizzard and in this episode we're going to learn how we can use data augmentation on images using tensor flows Karis API data augmentation occurs when we create a new data by making modifications to some existing data we're going to explain the idea a little bit further before we jump into the code but if you want a more thorough explanation then be sure to check out the corresponding episode in the deep learning fundamentals course on B+ or comm for the example that we'll demonstrate in just a moment the data we'll be working with is image data and so for image data specifically data augmentation would include things like flipping the image either horizontally or vertically it could include rotating the image it could include changing the color of the image and so on one of the major reasons we'd want to use data augmentation is to simply just get access to more data so a lot of times not having access to enough data is an issue that we can run into and we can run into problems like overfitting if our training data set is too small so that is a major reason to use data augmentation is to just grow our training set adding augmented data to our training set can in turn reduce overfitting as well all right so now let's jump into the code to see how we can augment image data using Kerris alright so the first thing that we need to do of course is import all of the packages that we will be making use of for this data augmentation next we have this plot images function which we've introduced earlier in the course this is directly from tensor flows website and it just allows us to apply images to our Jupiter notebook so check out the corresponding vlog for this episode on V Blizzard comm to get the link so that you can go copy this function yourself alright so next we have this variable called Jin which is an image data generator and recall we've actually worked with image data generators earlier in the core whenever we create our train tests and valid batches that we were using for training CNN's with this so we are using image data generator in a different way here we are creating this generator that we are specifying all of these parameters like rotation range width shift range height shift range share range zoom range channel shift range and horizontal flip so these are all options that allow us to augment our image data so you need to check the documentation on teaser flows website to get an idea of the units for these parameters because they're not all the same so for example rotation range here I believe is measured in radians whereas like this width shift range is measured as a percentage of the width of the image so these are all ways that we can augment image data so this is going to be rotating the image by 10 radians this is going to be shifting the width of the image by 10% the height by 10% zooming in shifting the color channels flipping the image so all sorts of things so just all different ways that we can augment image data so there are other options to just be sure to check out the image data generator documentation if you want to see those options but for now these are the ones that we'll be working with so we store that in our gen variable next we are going to choose a random image from a dog directory that we had set up earlier in the course under the dogs vs. cats data set we're going to go into train into dog and then we are going to choose a random image from this directory and then we're going to set this image path accordingly so we're just going to set this to point to whatever that chosen image was on disk then we have this assertion here just to make sure that that is indeed a valid file before we proceed with the remaining code now we're just going to plot this image to the screen and I'm not sure what this is going to be since it is a random image from disk so that is a cute looking I don't know beagle beagle basset hound mix I don't know what do you guys think so this is the random dog that was selected from from our dog train directory now we are creating this new variable called Agadir and to our image data generator that we created earlier called gin we are calling this slowed function and passing our image in to flow and this is going to generate a batch of augmented images from this single image so next we are defining this aughh images variable which is going to give us 10 samples of the augmented images created by OGG itter here lastly we are going to plot these images using the plot images that we defined just above all right so let's zoom in a bit all right we can see now that first let's take a look at our original dog alright so that is the original image now we can look and see that given those things like rotation and width shift and everything that we defined earlier whenever we defined whenever we defined our image data generator that has now been done to all of these images in one a random way or another so we can see kind of what's happening here so for example this particular image looks like it has been shifted up some because we can see that the head of the dog is being cut off a little bit and this image or let's see which way was the dog originally facing so its head is facing to the right so yes so this image here has been flipped the dog is now facing to the left and this image appears to be shifted down some and so some of these like this one looks like it's been rotated so we can get an idea just by looking at the images the types of data augmentation that have been done to them and we can see how this could be very helpful for growing our dataset in general because for example say that we have a bunch of images of dogs but for whatever reason they're all facing to the left and we want to deploy our model to to be some general model that will classify different dogs but the types of images that will be accepted by this model later might have dogs facing to the right as well well maybe our model totally implodes on itself whenever it receives a dog facing to the right so through data augmentation given the fact that it is very normal for dogs to face left or right we could augment all of our dog images to have the data or to have the dogs also face in the right direction as well as the left direction to have a more to have a more dynamic data set now there is a note in the corresponding blog for this episode on D poster calm giving just the brief instruction for how to save these images to disk if you want to save the images after you augment them and then add them back to your training set so check that out if you're interested in doing that to actually grow your training set rather than just plot the images here and your Jupiter notebook 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 blog on YouTube also be sure to check out the corresponding blog for this episode along with other resources available on V Plus or comm and check out the people's 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] you [Music]
Info
Channel: deeplizard
Views: 25,110
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: WSvpLUietIM
Channel Id: undefined
Length: 8min 45sec (525 seconds)
Published: Wed Oct 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.