Image Classification with Transfer Learning in ML.NET using a Tensorflow Model

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone so Annette is quite a bit versatile if especially if you've seen other videos on all the stuff that they can do but not only can you create your own machine learning pipelines you can also use tensorflow deep learning models to make predictions and that's what we're going to do in this video we'll use a pre trained tensor flow model and perform transfer learning within in Lynette so real quick and neat Microsoft documentation for what we're about to do here and just a little bit of graphic here just to show what all this is doing so when you call mo net you use this tensor flow package and what what that does is that it reads from the pre trained model that you will need to download and include in your project here so it reads from that and it does everything in there and then within a mod net it gives you everything you need to do within your C shortcut so in the same documentation it gives you a link to download the inception model which is what we'll be using and so I already have a done that core console project loaded and I have a few things in the solution file I have an images folder and these images are just a book a couple of cups and a sunflower and that we have this labels CSV file which is the path of the image and then the label and if we only have one cup here because we use the other one for prediction and when you both the images and the labels file as input to this model so to get started we need a couple of media packages here and by the way if you haven't heard or not sure what transfer learning is it basically uses a model that's already been pre trained to solve a similar problem to what you want and essentially it just takes that model and reuses parts of it to build the new model that you want so the inception model is an image classifier so we're going to use that to classify some more images so first i'm another net package using 1.3.1 here and then since we're doing tensor flow we're gonna be reading a tensor flow model I need that package as well and since we're doing dealing with images I need to do I need to give the image analytics package there we go so like usual we need to get started by creating our in-law context and for our data we are going to load in the labels file so we'll just reload from text file and we need to create an input schema class here and I'll name that image data not clear dad and in just a bit and that's gonna be labels that CSV and a separator there's going to be a comma there's no header on it so the default has header is already false so I'll create this class here and these are just have low column it's gonna be two items here string image path and then our second item is going to be the label so next we need to create our pipe on it's gonna be quite an evolved pipeline here and I try to explain everything that best as I can first thing I want to do is we're going to do the conversion and that value to key transform what we need to do here is we need to change the label to a label key says two labels are categorical need to change them to numerical representations the next we'll do the transforms or reload in our images and this comes in from that image analytics package that we downloaded and I'll map that to a column called input and then the image folder it's gonna be images that we have here in our solution input column name is going to be the image path and so I can just use the name of for the image path property that we created on the image data that's that we need to do another transform or we resize the images that's gonna replace that input output content that we have up here and the next we need to do image with an image height and to help us with a few of those settings here I'm gonna at another class do inception settings for the exception model and it's actually gonna be a struct so it's a value type instead of a reference type that we get with a class so first is an image height which would be 224 and then we'll do the same thing for the image width and they would need a mean value what you do is 117 and this is all from that documentation page and I'll link to that in the description so you can follow that as well and we'll give it a scale of 1 now we do a channels list I set that equal to true I back in our resize image transform here when used the exception settings to do the width and height of our image there you want to resize to and the input column is gonna be input as well this is gonna be from this transform we input into this transform but we also output the same name as input and next we need to extract the pixels from the images so we can train all those another transform is called extract pixels so the alpha colon a I'm going to continue outputting as input and it will set the interleave pixel colors to that channels list so it said that true and we do to offset the image using that mean value alright so next we actually load in our tensor flow model and almost forgot we have this model folder here and after you download the inception model you give these couple of fouls all you need are the label strings text file and a PD file just move those over and make sure they get copied over when you build so to load it in we did context of model that blowed tensorflow model and from here we'll just give the path of what the model is this is gonna be a PD file and passed actual model file and then on top of that load tensor flow model need to do score tend to flow to model that's gonna take in a new array of strings and what this is is we're gonna output the call name that we get that is from this model file so the output that we get from there it's going to be a soft max to free activation and no tools out there where you can pass in this file and you can get the name so the the actual input and upload layers and then the input when do another already here and just put input since that's what we're giving it from here and it will say add match dimensions to true all right so that's all the other things we need to do for the images and the tensor flow model next we will append on the multi-class classification trainer and we'll do the maximum entropy trainer here did a label name is labeled key since we mapped it to from categorical to a numerical value up here and we'll give this same call name since this is what comes back from the tensor flow model we'll get that as the future column name and then one more thing to do for the pipeline is need to do another transform week vert map key to value and we'll bring out the predicted label value and the three dated label alright that's all for our pipeline so record our model from it about fitting with our data that creates the model forest and so we can next is create our image data and to do that we can do file read all blogs from our label file and then we use some link here to split all the columns so that separates it all out then next we will for each of those items we'll create a new image data object we did the image path when they passed bomb and from here we're gonna start off and environment that current director given the images path and then it'll be the first item from the split here that's gonna be the path from there need to create a data field from that image data so do context data that load from innumerable just do the image data and they can infer what type that is next we can create our predictions a new model that transform on that image data view and then we can create our image predictions context they got create numerable and this is going to be reading pass in or kind of prediction scheme right here so already have our input schema this image data so let's create another one called image prediction and I'm going to inherit from image data so I can get those properties then I'll do a float of array Padre called score and a string predicted label value which is just the name that we used up here to get items from the predicted label to predicted label value and this what this does is that since we mat from categorical to numerical up here if we're doing the opposite from mapping from numerical to categorical appearance so we can get the extreme representation of our labels so the image prediction here and they give you the predictions totally use tell not to use the road objects and ignore some columns true thanks we can evaluate our model see how well it goes we do model that transform on our data our original data here from the label file and you get our metrics you need a context multi-class classification that evaluate give it the Federation predictions give it a label column name of the label key and then a predicted call name of predicted label and with those predictions we can write out the metric everyone to look at generally for image classification or just multi-class classification you look at the log laws and the log walls needs to be as close to zero for for more accurate predictions so do read on so it doesn't disappear on me so let's go ahead and run this and see what we get so instead of saying P B I put P D so let's change that and we'll try it again there we go forget log loss of point zero eight which is not too bad I say to do a prediction now we can create the prediction function in the context of model that clay prediction engine Mary puts the image data and I output the image prediction and we just pass it in the model and we can create a single prediction by doing prediction function that predict and we give it a new image data and we give the image path your path come back it'll be the same as before do it environment I current directory images and we'll do that second cup image and then we write out the prediction to do image when Jews path I give filename on the image path that we gave it that was predicted as with the predicted label value we get the label makers predicted as and we can say with the score of I'm used to score and that's gonna be remember that's an array of floats so we just get the max I had him a net that's gonna be a score it was predicted label value so we run that again you know soak up to what's with the predicted as a cup to score of 66 percent so there we go that's how you can use a pre-trained tensor flow model inside ml net to basically use transfer learn to create your own model to do image classification thanks for watching and we'll see you next time
Info
Channel: Jon Wood
Views: 12,188
Rating: undefined out of 5
Keywords: ml.net, transfer learning, c#, .net, machine learning, deep learning, tensorflow transfer learning, ml.net tutorial, transfer learning tutorial, deep learning tutorial, deep learning ml.net, deep learning c#, machine learning c#, transfer learning c#, image classification, image classification c#, image classification ml.net, tensflow scoring ml.net, tensorflow scoring c#
Id: tAiKAtmPaXU
Channel Id: undefined
Length: 15min 48sec (948 seconds)
Published: Mon Sep 02 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.