A.I. models with C# ML .NET & Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm going to show you how to leverage powerful AI models into your net application so we can use the well-known YOLO you only look once model for object detection classification segmentation or post detection so I'll use a yolu V8 model for classification and detection and throughout multiple Industries you could apply it to Medical imagery for cell detection for example for safety in any industry to detect for helmets you could apply it to all kinds of textual documents for example invoices and you can even turn sounds into images and uh detect patterns in there or in the stock market you could detect Head and Shoulders patterns for example so classification is more like what is this image about is it about an apple is it about an orange will give a probability of what the image is about detection would be more like where is the Apple located in the image if there is one it's going to detect all of those objects in that image and give you the uh position in the shape of a bounding box so the coordinates within the image so now I'm going to show you how to leverage a YOLO model in your net applications with just a few lines of code and I'll be using it simply to recognize which Pokémon this is so I'll be using a classification model I could simply download a YOLO model and try to uh classify the image of Pikachu and see what it outputs it's unlikely that it's going to tell me it's Pikachu it's May tell me it's a mouse or some kind of animal because because these base models are not specifically trained on Pokemon uh imagery so I've got at least two options now either I start with the YOLO model and I retrain it on a lot of imagery of Pokemon to make it more accurate in detecting or classifying Pokemon or I could find a model that has already done that so I'll take you to the candy shop of machine learning models which is hugging phas and here you can simply search for all kind of models um so I typed in Yolo V8 and then you see YOLO V8 models but specifically trained to class classify paintings chest x-rays Pokemon um even helmet detection or blood cell detection and CS goo player detection all kinds of detection or classification in sports imagery or video and so on so I took the Pokemon classification model and then I went to the files and version and I downloaded that model but that model is built with well using the pytorch framework which is a python specific framework which I unfor un fortunately cannot use as is in a net application so I'll need to convert that PT model into a nnx model which is more like the crossplatform version of the model I can simply do that with a few lines of python code so I'm going to set up a minimal python environment with a Jupiter notebook to export that model that YOLO model into an an an X YOLO model I'll leave that python setup for the end of the video uh but I highly recommend you to follow along so you can uh experiment with all kinds of models export all kinds of models so now I should be able to go back to my polyglot notebook with net code install the yo V8 package which is a some kind of a wrapper around ml.net uh specifically for the YOLO V8 model switch so and the polyot notebook YOLO V8 and then the image sharp from six labors which is a useful n package to um transform pictures images do note this package is I think some functionality is behind some kind of license so it's not all and that's why I mentioned the C project it's kind of trying to create open source projects and so installing the packages using the packages loading Pokemon images imagery which I downloaded take that oh and an X model go back to my.net ml space paste it in ml models folder and I O that's console then I have all these images so that's all of these and these are loaded fine and then I'll need to load the model or and an X model using that YOLO V8 package and I can just call Simply call detect classify segment or POS detection I think in our case since it's a classification model and not an object detection model we're going to call classify a you got async one but let's first run into the on and runtime error which makes it unusable in the polyot notebook so I'm going to continue in a simple console application I have to my microphone is blocking the screen okay so I scaffolded a simple um console application net 8 I installed the CompuNet and image sharp in there so you'll see ULU V8 yeah which also has the image sharp dependency and I'm doing the same in here Bookman images create the model going to have to verify if the paths are correct and then classify async and then plot image async that's going to so like I just mentioned if I call classify and save it might also do that plot plotting I'll have to copy the model or included in in here so it gets copied to the bin folder we'll see so if I'm not mistaken that's something as follows okay I'm going to copy the images of the Pokemon to the bin folder and the Machine learning model as well and then I'll have to fortunately get rid of all of these and of course and that seems to think it's a Kangas Kang let's see what the result is so image Dimensions probabilities okay it's giving me a probability for each Pokemon picture 001 one 0 0 0 okay that's not good of course it's an outline of pure but it should be able to detect that structure those outlines to the shape of Pikachu let's try that again on an actual Pikachu and it's giving me duct Trio okay so either the model is just really poorly trained with uh yeah not enough uh variations of Pikachu because the image is pretty clear so I added this transparent Pikachu in there but it's not that accurate okay so that did that model didn't perform as well as I hoped um because yeah I've built a Pokemon classification model myself in the past with tensorflow a convolutional neural network and it was able to distinguish these uh Pokemon outlines I did only train it on the data set with only five different types of Pokémon um but the results were accurate I'd recommend you to check out all of the other models so now you could try classify and save a sync or you could do it in multiple steps classify and save is Sy should um so do the prediction I think also draw the so plot the image a sync and then save it to a directory well image and then maybe we could just save that one wait save a sync let's make that image five to be the same one and then in the bin folder it created this result.png and you see the duct Trio label which is of course wrong but if this was an object detection model then you would see a bounding box around the object it detected of all the objects it detected so I'll start with installing python 3.9 since I found that the most compatible version with a lot of the machine learning work out there and you could simply install that from python.org or whatever the website is or you could go to the Microsoft Store and install python 3.9 so once installed I'll verify my python installation and command line interface simply type python okay seems good let's now install a use pip which is kind of the package manager for the python space install virtual environment this virtual environment is going to be a Project Specific environment in which we'll install all their required python packages and that's useful because now we can have so such an environment per project instead of installing all of those packages onto my computer which would yeah cause a collision create encapsulated or isolated uh environments to in which will'll install the required packages I'm simply following a blog post to install this virtual environment and the jupter notebook I'll leave the links down in this polyglot notebook and I'll drop that one onto my gcode patreon which is G code.com stupid and I'll include the machine learning models and all of the other code I'll produce in this videoos so this is the blog post I'm talking about and we just installed the virtual environment so I just went through all the steps of installation but I was filming the wrong screen so I'll quickly go through the steps with you so pipol virtual n we already did that then we go to the our project directory for me that is in uh code SL Python and I called it export. yulu if we're on that pad we'll create that virtual environment I called it V EnV instead of instead of my EnV um so that's the V EnV and then that should be created after running that and that that part then you can activate the virtual environment by typing vv/ script activate and once that's activated you can start installing all of the project dependencies all of the specific python packages so yeah okay on the Mac and Linux it's with the source command I'm on the windows and then I went ahead and installed inside of that virtual environment F install Jupiter the kernel kernel install with the name of VV instead of my and the same for this one install the bash kernel and then ultimately run the Jupiter notebook which opens up a local environment in which you can create a new notebook by selecting the virtual environment you just created because in that environment we're going to install all of those specific project packages so I created that let's open then I went back to the [Music] folder and added this requirements.txt in which we're going to specify the packages that we would like to use uh the packages I'll need need to export that P torch model to a onnx model so I'll install the ultral litics package python package in there if you click on the YOLO and then import that line let's just take it all see don't need to load it just export so I'll copy all of that in there this PT should be loaded from the package so that's fine but that's going to be one of those base models those YOLO V8 models will need to replace that by this specific Pokemon classifier first things first let's install that ultr litics package I hope that's the only thing I'll need and then I'll go back to the terminal I'll open a new one and then I'm going to run well I need to activate that virtual environment again let's see V uh script activate come on and then say bip install I'm going to say DHR and then requirements.txt and then it should install all of the packages speci specified in the requirements.txt which is for now only the ultral litics package but that seems to have some other dependencies below for images pandas for data frames open CV for plotting and stuff M plot lip as well well for image transformation and all a lot more and I have to mention C sharp is trying to Port all of these or convert all of these packages to the net space with tflow nsharp kasas all kinds of machine learning Frameworks numpy catalyst is a bit like Spacey that's really cool uh NLP package for [Music] entity named entity recognition and so on let's see and then it's working on p.net so that data frames one M plot lip py could learn for machine learning statistical models B Sharp really cool stuff so kind of the counterparts of the B the most used python machine learning packages I'm going to Kernel restart if I need it to anyway it does work so now I could export a base model or I could go to the Pokemon classification one I have to copy it to the project I'll put it in here ml models and uh so I showed you how to Simply download it by going to the files on version and click download but I already did that let's see it is however n the so I've got this yolu classification I'm going to copy Bo let's see is it's an ml models not t it successfully downloaded that exported that model [Music] to hopefully the same directory but sometimes you may need to look for it it's not always able to do it so now we have that yulu v8m Pokemon classification. nnx and that one I can use in theet application so that's all for this video I showed you how to add a rather powerful YOLO model into your net applications with just a few lines of code and I showed you how to set up a minimal python environment for all kinds of experimentation and to export the models you would like to use in your net apps so it's rather unfortunate that that Pokemon classification model didn't perform as I would have hoped but I can assure you that there are many models on the hugging phas PL form that do perform very well I'll leave all of the code produced in this video on my patreon slus stupid and you can check out kod.com to get access to the my best nued packages the source code and the version one of the brand website I'll soon release version two of this brand website I'm just finishing up the last features slowly but surely and I hope I see you in the next video don't forget to like And subscribe
Info
Channel: Keep it simple, stupid.
Views: 831
Rating: undefined out of 5
Keywords: web, app, development, dotnet, pwa, ml, ai, frontend, backend, cloud, azure, fullstack, .NET, C#, machine learning, artificial intelligence
Id: hO7tXh4N0OY
Channel Id: undefined
Length: 20min 33sec (1233 seconds)
Published: Sun May 26 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.