Getting Started with Python Deep Learning for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you're scrolling through reddit and all of a sudden you see a mind-blowing example of what ai can do maybe you saw what dali 2 is doing when it comes to image generation or you might have seen what gpt-3 was doing for text generation well how exactly is it that you get started well it all starts with deep learning and in this video we're going to be focused on what you need to do in terms of getting set up and started so this includes what do you need to install how do you need to install it as well as going through an end-to-end image classification example towards the end of this tutorial ready to do it let's get to it [Music] what's happening guys my name is nicholas renaud and in this tutorial we are going to be focused on deep learning basics now i've just gone and taken a little bit of a risk and uninstalled everything that i use in my day-to-day life when it comes to deep learning but i really wanted to show you what you need to do in order to get started from scratch like we're talking bare bones nothing pre-installed we're going to go from the ground up so that you can follow along if you want to start your journey yourself so first things first what we're going to do is install the environment that we're going to need so we're going to do this by installing anaconda and anaconda's going to come pre-packaged with a version of python that we can use we're then also going to take a look at installing cuda and cudn so this is going to allow us to perform gpu acceleration but if you don't have a gpu that's perfectly fine you can still keep going with this i'm also going to show you the flow that i have when it comes to setting up environments and getting them up and running with jupiter but we'll talk about that a little bit more later and last but not least right towards the end i'm actually going to step you through an entire deep learning workflow so you can see how it actually works and how to give it a go you ready to do it let's get to it hey nick you do deep learning right is lewis hamilton the greatest driver of all time uh yeah yeah yeah i dabbled got it wanna show me how to set up my computer for it sure first thing we need to do is install anaconda python and jupyter all right let's kick it off alrighty so deep learning basics so this entire tutorial is going to be very much focused on getting you up and running with at least one deep learning use case now rather than starting with all the installers i wanted to show you what the end goal is so the goal is to be able to run this entire image classification pipeline which i've pre-written which we're going to go into way more detail in an upcoming tutorial but the goal is to get your computer up and running so that you can go and run through this to be able to perform a or build a deep learning model which performs image classification so you can see all of the deep learning layers there now i'm going to show you how to do this from scratch and how to do it in a good way that's just going to make your life a whole bunch easier so we're also going to leverage this code a little bit later on but we are going to go completely from scratch so if you are just starting out this is going to be the tutorial for you because it's going to go all the way from the ground up okay so the first thing that we need to do is recognize that this is currently inside of a jupiter notebook so the fact that it's got this extension here so dot i pi nb stands for ipython notebook so we can run that inside of two different types of servers either a jupyter notebook server or a jupyter lab server so what we actually need to do is get that up and running now if we take a look at our to-do list step one is exactly that so we are going to be installing python and jupyter using anaconda so anaconda is a big package repository that contains everything that you need in terms of getting started with data science deep learning machine learning all that good stuff so we can actually just go to this link here and i'll make this entire to-do list available through github as well so i'll include that in the link below so we are going to go to https colon forward slash forward www.anaconda.com forward slash products forward slash distribution so we can go to this link and that is going to allow us to get anaconda now if you the link may have changed when you do finally watch this tutorial but if you just type in anaconda python you should get to the same link so you can see it's going to anaconda distro there now first thing to note is that this is going to install or download this particular installer so you can see it says for windows python 3.9 and it's a 64-bit graphical installer it's about 510 megabytes in size by default it should pick up the operating system that you're working on so mine's picked up for windows if you're running on mac then you're going to want to go to the mac installer if you're running on linux you can also go to the linux installer now even though it is installing using python 3.9 you can inside of anaconda switch over the python version so if you've got a really specific requirement for it not you can solve that for now what we're going to go ahead and do is download anaconda and you can see that that is going to go on ahead and download that now i've already gone and downloaded this so i can go and kill it so you can see it's downloading let me zoom in on that so you can see it it's downloading a file called anaconda3-2021.1 so i've already gone and downloaded that particular file but that is the first thing that we need to go on ahead and download so once we've got that downloaded we can actually go and install it so if i go over here so you can see i've got that file there so anaconda 3 2021-11 windows x86 64. so this is going to install python 3.9 on a 64-bit machine now by default it should pick up the relevant version but as soon as you've got that downloaded all you need to do is double click on the installer hit next hit i agree and then in my particular case i'm going to install it for all my users so if i log in as a guest user or a different user i can still use anaconda so we're going to hit all users hit next then this should go black just for a second okay so we're back so that's just the security pop up perfectly fine and then you can see that we've got a destination folder here so you can see it's going into c program data anaconda 3. if you've got a previous installation it might still have a folder there so if we go next okay that looks alright so it's going to go into c drive program data for backward slash anaconda 3. feel free to name that or put it into a different location if you want to this is the default tends to work fine so we're going to hit next and then this is really critical so this tab over here allows you to add anaconda 3 to your path environment variable which means you're going to be able to launch it from your command line makes your life a ton easier so make sure you tick this even though it's red so in spite of the fact it says not recommended perfectly fine make sure you tick that flag and then hit install and that's going to go on ahead and install anaconda for you so let's give that a sec and then we should be good to go five minutes later all righty that is anaconda now installed so you can see it says it has completed so we're looking good in that particular space no i don't want quick assistant cool so we're looking good we can hit next and then next again and then we don't need to launch either of these so you can deselect anaconda individual edition tutorial and deselect getting started with anaconda and hit finish cool all right so that is the first thing now done so if we type in done we are done with that first task so before we jump back on over to our client let's actually take a look at what we can now do so previously i had no python environment inside of my computer but now what i can do because i've gone and installed anaconda i can actually launch a jupyter notebook server or a jupyter lab server so if i want to type in or launch jupyter i can type in jupyter notebook and this will actually launch a server it's going to ask me how i want to open this file i'm going to just select my default browser so google chrome and this is open on another screen so if i bring that over this is what jupyter server looks like now the biggest thing to note is that we use typically use this to open up jupyter notebook so if i wanted to go and open up an image classification notebook i could definitely go and do that so this is just one that i've currently got on my desktop but i could go and open up one that i've got for a what is where are some of my youtube ones so for example web game so i've got one that i was building for a dyno ai tutorial now ignore this for now i'm going to show you how to solve this in a second just know that we can actually start leveraging this jupyter notebook server to do stuff but in terms of what we do with it we'll come back to that in a second now if it doesn't open up by default when you do run the jupyter notebook command you're actually going to have this link generated here so you can just copy this link so you can see it's saying i'm serving notebooks from local directory jupyter notebook 6.4.5 is running at this link so if we copy that we can actually go back to our browser paste that in you can see we're back to the same spot now we can also stop that server so all we need to do is hit control c and that's going to stop it so you can see it's shut it down so we've got no terminals running now i also mentioned that we can start up jupiter lab so jupiter lab is another way that we can open up jupiter notebooks and tends to be the way that i use it because i just find it looks a little bit nicer we can go to dark mode as well so we can type in jupiter lab at the command prompt and it is j-u-p-y-t-e-r-l-a-b that's how we start up either jupiter notebook or jupiter lab and again so if i wanted to go into my dyno ai tutorial i could go and do that right so i've got a web game environment i can open up this notebook now and again we'll just ignore that for now you can see that this is how we can actually leverage a notebook now if we wanted to we could actually create a new notebook and let me show you how to do that so all you need to do is hit this blue button over here and well that's going to open up the launcher and then from there what we can do is actually start up a notebook so we can just choose what kernel we want to actually leverage but again more on that in a second so if we open up that kernel we can actually write python inside of these cells so i can type in print hello world right and this is actually running our output so you can see that this is my python code this is the output from that particular line of code let's zoom in on that so you can see it a little bit better now we could do a whole bunch of stuff if i wanted to write a loop so 4x in range 10 so again it's just running python i could print x pretty cool right now these cells can be a bunch of different types of cells so say for example you can see i could i've got this current cell set to code i could convert that to markdown and this is going to operate as markdown rather than a code cell now we can navigate through these cells let's say for example we wanted to convert that cell back to code all you need to do is hit y on your keyboard and it's going to convert it back to code if i wanted to convert it to markdown i can hit m it's going to convert it to markdown and this is because the cell is selected but not currently active so you can see that it's blue as soon as i step into that if i hit m i'm actually going to be writing code so what i need to do is hit escape and that means that i've currently got it selected but i'm not coding inside of it and i can toggle right my my my mi so on and so forth you can hit shift enter to actually run that so you can see i'm running these lines of code if i wanted to add a cell above i can just hit a if i wanted to delete a cell i hit dd on my keyboard so these are just a couple of shortcuts now there are a whole bunch of additional shortcuts i can never remember where they are all right they're over here um so there's a jupiter reference does that actually give us all our shortcuts i can never remember where these actually are but there's a whole bunch of shortcuts that you've actually got available through here and a whole bunch of documentation for i actually use jupiter i tend to use shift enter to actually run a cell um a to add a cell d to delete a cell now if you wanted to delete the output from a particular cell you can also go to edit and you can go to uh where is it clear output so that will get rid of the output of a cell right so you can see it's deleted the hello world if i step out of this one and do it on this one again i'm clearing the output okay that is jupiter in a bit of a nutshell let's jump back on over to our client and have a quick chat to see what's next so that's now done noise what's next well we're going to create an environment for our deep learning project um why didn't we just set up python isn't that enough getting python up and running is a great first step but having an environment is going to make your life a billion times simpler particularly when it comes to working with multiple projects think of an environment as a little world for your project everything it needs to live breathe and survive is going to be encapsulated inside of it this means that all of the extra modules and dependencies are going to be there when you need them it also means that there's going to be less conflict with other stuff that you might have on your computer ah got it does it work with jupiter as well sure does i'll show you how to get them synced up with your jupyter server as well alrighty and we're back so now what we're on to is actually creating some environments now you would have seen previously when i was opening up this notebook i was getting this weird pop-up saying um there's no kernel or there's no kernel attached to this particular notebook and that is actually referring to the environment that our particular jupiter notebook is actually working with now before we get to that let's actually get the proper notebook that we're going to be working with so remember i said that we were going to be going on and working with this image classification notebook that i had up on the screen now you might be super familiar with this so if you're really if you're experienced and you've worked with git you can probably skip this step but for those of you that are completely new to this i wanted to give you a little bit of a background so github is a place where you can store your code your data your different models and it's a really popular way for sharing these with other people around the world now i tend to upload virtually all of my code that i write for youtube inside of github so if ever you wanted to or you saw a tutorial and you're like nick i just want to try the code i don't want to go and do it step by step normally they're all available here pretty much 99 of the time that that other one is me generally forgetting so we've got this image classification repository that we've got here and this has got data it's got models it's got a git ignore file it's got some pictures and it's got that jupyter notebook that i showed briefly now let's say that we actually wanted to start leveraging this well the first thing that we need to do is we actually need to go on ahead and install git now by default this is going to be available on a mac machine but if you're on a windows machine you actually need to go on ahead and set it up so first thing that we're going to go ahead and do is set this up for our windows machine so we can actually go to this link so git for windows so we can go to https colon forward slash forward slash git scm.com and what we can do is download git right so over here you can see we can go and download that particular source and we can hit download for windows and we are going to choose the 64-bit get for windows setup and that's going to go on ahead and download now again i've already gone and pre-downloaded this because my internet is slow as hell so let's go on over to that so i've got git over here so git 2.36.0 dash 64-bit so you can see that over there so what we're going to do is double-click that and install git and again we can just hit next next so it looks like we've already got it installed so we're going to install it again hit next hit next hit next up yeah you can pretty much just leave all of these by default uh so we're going to leave git on the command line so we can hit next there leave that next next there's a lot of these right call next um yep next next and then yeah next all right cool so that's going to go ahead and source that will allow us to be able to leverage git so let's let that install and we should be able to use it in a second julio that is git now installed so again we can hit finish it's going to open the old release notes we don't really need to delve too much on that so let's take a look so we've now gone and installed git what we actually want to go ahead and do is get that repository from github so in order to do that we are going to open up a new command prompt or we can actually stop our existing one that we had from jupiter's notebook jupiter lab we can type in cls on windows to clear that and we are going to clone this down so there's a really simple command to be able to clone this from github onto our local machine so and that command is git clone so i'm going to copy this link and over here i'm going to open up so we're currently in our d drive you can see that there what i'm going to do is i'm going to clone that repository so i can type in git clone and you can see there's no folder called image classification here yet so if i type in git clone and then the link to that github repo and it looks like it's saying git is not recognized let's open up a new command prompt because remember we installed it now we and we still had the old command prompt installed so if you've gone and installed it and it's not showing up that's probably actually good that you've seen that that's fine close down your command prompt open up a new one so we'll try it again so git clone paste that link and you can see it's working now so the reason that we had that little pop-up is we'd installed it but we hadn't reopened up our command prompt so it wouldn't have actually known what that git command is but you can see it is successfully cloning down and what you can see there is that we've actually got that repository cloning oh that's going crazy you can see that we've got image classification over here and it's starting to clone down all the stuff that's inside of that github repository so in a second what you shall see is all of this stuff available all over here so again let's give that a second and let it finish cloning and then we'll be able to create our environment for it a little longer than a few minutes later cool that is now cloned and you can see that we've got a data folder which has a bunch of images of happy people we've got a sad folder which has a bunch of images of sad people because our deep learning model is going to classify as people being sad or happy and we've got a folder called models and we've got this h5 file we'll talk about that a little bit later we've got a git ignore file which you can just ignore for now we've also got a couple of images so these are just going to be testing images and we've got our jupyter notebook file so again remember how do we start up our jupyter notebook server we can either type in jupyter notebook or jupyter lab so we're going to use jupyter lab so i can type in jupiter lab and that's opened up we can close these old ones cool so again we're inside of jupiter lab now we are going to go inside of our image classification folder which we just cloned down and we can open up this jupyter notebook now we've got an error how are we actually going to solve this so i actually wrote this jupyter notebook probably two or three days ago and when i was doing that i was actually coding it up inside of python 3.7 now this particular error is telling me that we can't actually go ahead because this notebook is attached to a jupyter notebook environment which was authored in python 3.7 but that's perfectly fine all we need to do is change the environment that this particular notebook is running on now inside of jupiter environments are referred to as kernels so all we need to do is jump on over to here which over here which you can say see it says kernel and if we go to change kernel let's move this out of the way we can go to let's say for example let's go to a generic kernel so right now generic kernel is just python 3 i pi kernel so we can select that and hit select and then if i hit ok that error is now gone now over here you'll see that our jupyter notebook is now running off our python 3 environment or python 3 kernel but this can get a little bit messy because we're gonna go and install tensorflow opencv and a whole bunch of other stuff which may start conflicting with the other environments or with the other projects that may be using that particular environment so let's say for example one project needs tensorflow 2.4.1 which is a really specific version and we're going to go on ahead and overwrite this so right now this would go and well assuming there was no other tensorflow installation this would go and install the latest version of tensorflow which might screw up our other projects this is where environments come in so we can isolate all the stuff that we're going to need for this particular jupyter notebook or this particular project now if we go to kernel and hit change kernel you can actually see all of the different kernels or environments that are attached to our particular jupyter notebook so we've got one called deep learning ds course eye track finarell learning that's our generic one we've got one called started one called super res and one called toxic now we actually want to go and create one for our image classification project because right now we don't actually have one that we can associate to our notebook sometimes what actually happens is people will go and create an environment then go and run this notebook and be like nick it's not working i've been i'm installing stuff and the notebook's still not picking it up well that's because we need to create the environment but then associate it to jupiter so we can actually pick it up now i'm going to actually walk you through this because i do this every single day and it's quite possibly one of the most important skills that i've picked up in terms of being productive when it comes to machine learning deep learning and all that good stuff cool so what are we going to do let's quickly take a look at our to-do list so we've now gone and installed git so we're good with that we are now going to go through our environment creation workflow which are these steps over here so this should be lowercase lowercase let's go on ahead and do it so i'm going to hit cancel and we are just going to stop jupyters for now so we're going to go back to our command prompt and we're going to clear it so on windows i can type in cls and let's go on ahead and create an environment the first thing that we want to do is we want to create the environment inside of the same folder that we are going to be doing all of our work in and just keep stuff a little bit nicer i know i'm a little bit ocd but that's just me so i'm going to type in dr so right now we've got a folder called image classification so deer allows us to see all of the folders that we've currently got so we are going to go into that folder first up so i can type in cd image classification let's hit cls so we can clear all of that and then we're going to create our virtual environment in here so the command to create a virtual environment is python dash m v e n v and then the name of the environment so i'm going to call it uh image classification and that's pretty much it so python dash m v and v image classification so if i go and run this now and this is for windows so if you do need a mac equivalent or a linux equivalent just type in v and v python and you'll be able to get the documentation up here so over here you can see that we are creating it as follows so what you can see there now in terms of activating it we'll come back to that in a second but for now just know to create a virtual environment it's python dash m v e n v image classification so if i go and run this all things holding equal it should create a image classification virtual environment so again we've got no errors there now inside of our image classification folder we actually have a virtual environment called image classification this might get we are inside it should be okay all right so what we're going to do now is we are going to go on ahead and activate this particular environment because right now we're not actually using it right so we are going to activate it so if i type in dot backward slash image classification so whatever the name of the virtual environment is then backward slash scripts then backward slash activate this is going to activate my environment and this is specific for a windows machine for a mac it's slightly different and i'll show you where to get that particular command if i go and run this you can see that we are now inside of that virtual environment so we've got a set of parentheses with the name of our virtual environment over here so our virtual environment is called image classification a folder that we are currently working in is called image classification we could call this whatever we wanted to it could be called deep learning project one for example in our particular case that's what we've called it if you are running this on a mac these are the commands that you're going to need so typically you'll be running it on bash so the command will be source the name of the virtual environment forward slash bn forward slash activate so that's that over there can you see that so source the name of your environment so don't include the the what is it the arrows get rid of that what you want to do is put in the name of your environment forward slash bin forward slash activate and that should effectively do that the one that we just run is this over here so we would be running dot backwards slash the name of our environment scripts activate and we drop the bat you don't need that okay so we have gone and successfully activated our environment let me zoom out now what's the next thing that we need to do so we've activated it but now we actually need to go and attach it to our jupyter notebook so if we go and type in jupyter lab and this is where a lot of people go wrong and they'll go and create the virtual environment then open up jupiter lab and just because they've activated or started up jupiter lab inside of the activated environment doesn't mean anything right so if i went and installed a random library over here it is still running inside of that default kernel so if you've ever installed something inside a jupyter notebook and then you're like nick it's not picking it up this is why because even though you've activated it you haven't associated it to jupiter that's why you're getting those problems but i'm going to show you how to do that so not an issue so we are going to stop our jupiter lab server and we need to go and install it so to install it first what we need to do is install a library called ipi kernel so let me show you where this is at inside of our to-do list so we've now gone and created our virtual environment so this is done so remember to create it's python dash m-v-e-n-v and then the name of your virtual environment this one here says image classification or image class then you need to activate it so we've done that as well and to activate it it's dot backward slash the name of your virtual environment backward slash scripts backwards activate again it's slightly different from mac i'll link to the documentation in the description below then we need to go on ahead and install ipi kernel so let's actually do that so i can type in pip let's clear this keep it a little bit neater hip install i pi kernel and this is going to install it inside of our virtual environment that we've just gone and created and ipi kernel allows us to attach a virtual environment to the jupyter notebook kernel that we actually want to go on ahead and run and that's what does that linking so that means when we install stuff inside of our virtual environment it's going to be showing up inside of our jupiter notebook kernel so let's give that a second to finish running and then we can go oh well it's done now so it looks like we've got a warning you're using pip version 2.2 21.2.3 have version whatever that's just telling us there's in your version of pip you can ignore that for now so we now have ipi kernel available inside of our virtual environment now we can verify this by running pip list and we should see ipi kernel so we can see that there so pip list shows you all of the different libraries that you've got available inside of your environment now because we've got a virtual environment activated this is showing us the stuff that's available inside of our virtual environment okay but now what we need to do is actually go ahead and use that so to use it we can type in python dash m ipi kernel install dash dash name and then the name of our virtual environment so dash dash name equals and then we are going to name it image classification so the full line is python python dash m ipi kernel install dash dash name equals image classification so if i go and run this now you can see it's actually gone and installed it says installed kernel spec image classification in blah blah now if we actually wanted to go and check what the or all of the different environments or kernels that we've got available inside of jupiter we can run jupiter kernel spec list so this should actually show us all of the different kernels available so jupyter kernel spec list shows us the different kernels that we've got available so you can see we've got our default one which is python three we've got deep learning ds course eye track finral image classification which is the one that we just created learning started super resin toxic now if we wanted to go and delete one we could do that as well so we could type in jupiter kernel spec uninstall and then i think what is it do you pass name no you just pass in the name of the kernel so you don't need to actually name it so let's say for example we wanted to get rid of our image classification one let's do that so jupyter kernel spec uninstall image classification it's going to ask us whether or not we want to delete it or uninstall it we can hit yes it's now removed so if we again go and type in jupyter kernel spec list image classification is no longer there now if we go let's go ahead and install it again so again python dash m and it's good practice guys python dash m uh what is it ipi kernel install dash dash name equals image classification all right so that's our line to go ahead and install it let's install cool so no errors we can verify so jupyter kernel spec list we've got it there all right now if we go and run jupiter lab check this magic out guys if we go and open it up and if we go to kernel change kernel we are going to set it to our virtual environment so if we go you can see that we've got image classification now available magic right but this is great so we can now use this virtual environment inside of our jupiter notebook which means that if we go and install stuff inside of that virtual environment we're going to pick it up inside of our jupyter notebook cool and again we can hit save and that's going to save it so if i go and write a new lines remember a gives me a new cell so let's type in a print blah blah blah you can see that we've got this circle here this full circle that means that our notebook is not saved so if we want to save it ctrl s that saves it okay let's go back to our to-do list and see how we're doing so we've now gone and installed git we've now gone and created a virtual environment we've now gone and activated it we've installed ipi kernel we've gone and attached or installed our virtual environment to our jupyter notebook and we've also gone and taken a look at how we can delete environment so this is done this is done and this is done so this entire task is now done let's jump back on over to our client and see how we're doing so what's next well now that we've got jupyter and our environment set up it's time to install a deep learning framework sweet which one well the choice is yours but we're going to be working with tensorflow and keras it's straightforward to work with and makes integration and deployment into apps and edge devices a ton easier nice let's do it alrighty cool so we're back so we've now gone and done steps one and two so install python with anaconda we've gone and taken a look at environment creation and i've shown you my workflow so that's actually what i do in real life every single day when i'm building deep learning stuff now the good bit the juicy bit installing tensorflow for deep learning so there is a great guide on doing this over on the tensorflow website so let's go and take a look at that this is available at https tensorflow.org forward slash install and we are looking at the windows version if you wanted to take a look at the mac version you've got that available over here as well call windows mac windows map all right now there are a couple of key things that we need to go on ahead and install when we are using so we're going to be doing it with pip over here as well a couple of key things that we actually need to go and use when it comes to getting tensorflow up and running so pay attention to this so the system requirements so if we're going to be you or we need to be using python 3.7 to 3.10 python 3.10 supports tensorflow 2.8 or later so we are using python 3.9 remember when we went in and stored anaconda let's go back we downloaded python 3.9 so python 3.9 requires tensorflow 2.5 or later that's fine we'll download the latest when we go and run a pip install we need pip that's fine it comes with anaconda you need to either be running ubuntu mac os or windows 7. later so again we're going to be doing it with windows if you are installing on windows you need to install the microsoft visual c plus plus redistributable for visual studio 2015 2017 and 2018 but that's fine i'm going to show you how to do that as well and if you're going to be using a cuda enabled machine then you need to go and set up the cuda bit but we're going to come back to that a little bit later so let's take a look at what we actually need to do here so first up what we're going to do is run a pip install and then we're going to go ahead and set up the microsoft visual c plus plus build tool so we can actually do this side by side so if we go over to here we are going i've actually got the commands inside of the notebook for you so i'm going to go ahead and step out of that cell delete add random print delete that delete that delete that and because we are inside of our virtual environment inside of jupyter we can actually go on ahead and run this command so exclamation mark pip install tensorflow tensorflow dash gpu opencv dash python and matplotlib so this is going to tensorflow and tensorflow dash gpu are going to install tensorflow into your virtual environment so we can actually run shift enter and kick that off now that will take a while because it's going to download all of tensorflow which is quite a large file in the meantime let's go ahead and install the microsoft visual c plus plus redistributable i've already got that bit installed because it takes a ton of time to download but i'm going to show you exactly how to do it so if we go to the links that are supported here uh no that's not the link that i wanted to give you so there is an easier one so if we go to over here https colon forward slash forward slash visual studio dot microsoft.com forward slash downloads what you need to do is download this bad boy so over here all you need to do is select community so that is going to download visual studio 2022 and through that what you need to do is install the desktop c plus dev tools so i'm going to show you how to do this so if we hit download here that's going to download the downloader because there's a separate set of downloads so we can open that up hit yes and in this particular case we are going to hit continue so that's going to download the full blown installer so we'll give that a sec all right now when it comes to installing so we i've already got it installed so there's a little bit of pain let's actually go and hit modify right so when it comes to installing what you're going to do is open it'll open up to a screen that looks like this what you're going to need to do is go to this bit here which says desktop development with c plus and make sure you tick that that is what is going to give you those build tools needed for tensorflow so tick that and then hit install so i don't have anything new to install here because i've already got it ticked and installed if you're doing it for the first time it's going to open up to this screen you need to select that so desktop development c plus plus then hit install this is needed if you are installing on a windows machine doesn't apply to a mac i don't think it applies to linux machines either that's just an important thing to note you need to go through this process and install that and you should be good to go once that's installed you should have visual studio community 2022 is that supported what does it say we actually need 2019 so ideally you want to be downloading 2019 let's go back so over here we've got 2019 let's actually find the 2019 visual studio 2019 2019 is not appearing there it's not available to uh let's find it we'll go older downloads there we go 2019 so you're going to be wanting this one so visual studio 2019 hit download and that is going to include those build tools as well so then you can log in do all those downloads and remember ensure that you're just double ticking that c plus plus development set i think it might work with 2022. i don't know maybe it hasn't been updated on the website but in my particular case it is working it says 2019 so follow the steps but i've used 2022 still seems to work okay because it is leveraging the build tools not visual studio itself so remember you need those desktop development tools with c plus and that is going to get you up and started cool all right so oh tensorflow's finished installing okay so that happened reasonably quickly all right so in the meantime while we're taking a look at visual c plus plus build tools this command over here has finished running so our exclamation mark pip install tensorflow tensorflow-gpu opencv-python and matplotlib command is now done so if we go and run pip list let's go on ahead and take a look do we have tensorflow there take a look at that tensorflow 2.8.0 and tensorflow gpu 2.8.0 so that is looking well and good let's just jump back on over to our to-do list and see what else do we have to do so we need to install tensorflow for deep learning we've gone through the pip install we've gone through the visual c plus build tools so this step is now done now if you wanted to stop here you could right you don't actually need to go any further if you're not going to use a gpu because we can actually go and run this code right now but this will not be picking up our gpu so if i run this so again shift enter allows us to run ourselves so this first line is importing tensorflow so import tensorflow as tf import os right so that's run successfully this line over here we'll probably go through that more detail when we do the image classification deep dive but it effectively allows or stops tensorflow from taking up all of the vram on your gpu now right now really really important so i've got to run this code and this actually lists all the physical devices that you've got and it filters it out based on what you pass through here so this is listing out all of the gpus that are available to tensorflow which you can see are none and this is because we haven't actually configured this to be able to leverage our gpu as of yet so if we go and run through this pipeline now let's go through this relatively quickly so again i'm just running shift enter and this is working through our pipeline so this is the bit that i want you to get to so over here let's take a look so you can see that by running tensorflow without a gpu it is taking 692 milliseconds per step let's just make a note of that so 692 per step so that's just a note that when we actually go and apply our gpu we'll actually be able to see how much faster it's actually training but right now it looks like it's training our accuracy is going up i'm going to delve into this in a little bit more detail towards the end but just note that this will run without a gpu perfectly fine you don't need your gpu if you want to get started with deep learning but i want to show you how to do that so what we're going to do is we're actually going to stop this cell running so we can go up to here and hit stop you just got to hit it a bunch of times and we'll get this keyboard interrupt but for now we know that this pipeline can actually run without our gpu but let's jump back on over to our client uh well let's actually take a look at our to-do list first that's done we can jump back on over to our client let's do it hmm nick training seems a little bit slow i've heard we can speed it up with a gpu is that right yep if you've got a gpu you're going to want to make use of that for deep learning right i had to sell my entire vaxdo nft portfolio to get one but i've got one at last cool well in order to get it set up we need to install two key libraries these are cuda and cu dnn are those free sure as long as you've got an nvidia gpu you're gonna be fine what about if i don't have a gpu can i still do deep learning yeah definitely it'll be a little bit slower particularly when it comes to computer vision and nlp tasks ah got it let's go alrighty and we're back so what we did last time is we have or what we've done successfully is we've installed anaconda we've installed git we've taken a look at our virtual environments we've also installed tensorflow now the good bit setting up your gpu for computational acceleration that sounds very fancy but really just enabling your gpu for deep learning cool alrighty so to do that we need two key things we need cuda and we need cu d n now these versions are going to vary depending on which version of tensorflow you've got installed now i want to show you this in great detail because it can cause an absolute nightmare if you don't know how to do this so specific versions of tensorflow map to specific versions of cuda and cu dnn if you don't have the right versions it may not work so even though you might have cuda installed it might not pick that up in tensorflow and you might not get that speed boost so let's actually take a look at the version of tensorflow that we've got in sword at the moment so exclamation mark pip list will give us that so what version do we have we have 2.8.0 now if we go to the tens flow site so tensorflow.org oh through it's getting a little dry tensorflow.org in store for pip and over to here if you go to windows because we're running on a windows machine scroll on down over here you can see it says tested build configurations if you go to gpu this master table gives you all of the different combinations that will work together so we are currently running tensorflow gpu 2.8 we have python between these versions so we're using python 3.9 we've got the visual c plus plus compiler oh so you do need 2019. really important thing to note dude 2019 don't do 2022 as of yet um the cuda and cuda cd and n versions that we need are 8.1 and 11.2 so we need to ensure that we have a matching version of cuda and cu dnn that matches with our tensorflow gpu version so let's go on ahead and go and find those so if we go to our to-do list crude is available through this link so https colon forward forward slash developer.nvidia.com forward slash cuda dash toolkit so if we copy this jump on over here this will allow us to download cuda so if you scroll on down you can see we can download it so i'm just going to hit download now and if we hit we want windows and we want the x86 what is that the 64-bit version and we can choose which version we want so we want it for windows 10 we want a local version and in this particular case it is going to be downloading cuda 11.6 that is going to be a little too far ahead of our windows version so let's actually go back so this might mean there's a newer version out if we go to cuda 11.2 you can see that we have now so again i've just plugged this into google so kudos toolkit 11.2.downloads we can actually go and download it from this particular link and because there will be continuously new versions of cuda coming out it's good to know how to go and find the version that you need so going to my default link which looks to have worked only a couple of days ago looks like there's a new version of cuda out so if you go to just go to google search for cuda 11.2 that will give you the right version or ideally give you the right version i'll show you how to look for it so if we select windows again we are going to for the 64-bit version for windows 10 we want the local version let's take a look all right this looks good so you can see it says cuda underscore 11.2.0 that means that we are picking up the appropriate cuda version this will be the build number the last bit will be which operating system it's going to run on which is windows 10 in my particular case now what we can go ahead and do is download that and that is going to go on ahead and download i've already downloaded this so we don't need to wait for that let me show you the next thing that we need so the next thing that we are going to need is cudn so again you need both of these to be able to run tensorflow with gpu acceleration so let's double check what version of cd and n is available so again if you go to this link so developer dot nvidia dot com forward slash cu dnn you will be able to download cu dnn key thing to note is that when you go to try to download this you need to have an nvidia developer account it's perfectly free you just need to go and sign up so if you go to download cu dnn you should be able to download it wow window of my internet is going hella slow you also need to agree to this ai statement don't build any bad ai guys again we're going to agree to that this is showing cuda 8.4 is that going to match cuda cu dnn 8.4 no good for our particular instance so how do we find it we just search cu dnn what do we need 8.1 8.1 into google and we should be able to find it inside of the archive so you can see that we've got an archive there let's open that and we need an 8.1 version so we've got this 8.1 version showing up over here which says that it's going to run with cuda 11.0 11.1 and 11.2 so let's download that version and we need to look for our particular environment so we are going to be running it on windows we want it for do we have a 64-bit version should be a this is for red hat let's look no there's this version here maybe there's no others let's download that one cool so that's going to download that so let's take a look all right so in my particular case so well that's how to go and find them so again if you can't find the appropriate version jump into google more often than not you'll have to go to the archive if it is not the latest one all right so we've got cuda 11.2 is that the version that we needed 1102 and cdn 8.1 so again i've gone and downloaded these previously so that we can speed this up so uh what do we have so we've got cuda 11.2 and i have you can see that right there let me zoom in so i've got cu dnn 11.2 windows dash x86 64 version 8.1.1.33 that's the one that we were just downloading let's double check that um let's see what we're downloading yeah exactly the same as what we're downloading there so again let me zoom in on that so cuda 11.2 windows x86 version 8.1.33 so again might just need to go to the cud and then archive to be able to find the appropriate version because look at how many have come up from after that so that was released in feb 26 there's a ton of new ones okay but that is how to find the appropriate versions whatever you do just make sure you download the versions that match the tensorflow gpu version otherwise you're gonna have a bad time okay so we've gone and downloaded those now what we need to do is install them so for the crude installation pretty straightforward you just need to double click it there's an installer i've just gone and double clicked it just install it wherever so this is just the setup package it's going to unpack it and then we should be able to install it five minutes later okay that is successfully unpacked it's gonna do some system compatibility checks and then we should be able to use this or set it up install it all right so we need to accept the software agreements we're just going to hit agree and continue we can just do the express install let me zoom in on this so you can see it we're going to hit next and again this might change in terms of the look and feel but again for now tensorflow you need cuda and cdn for windows and for any gpu installation you need it for linux as well so it's going to prepare the installation and then it should just kick it off let's give it a sec all right so this is installing so we'll just let that run and install and then we'll be right back and i'll show you how to set up cu dnn a little longer than a few minutes later okay that is cuda now installed so we can hit next we don't need to launch any of these so we can deselect them and hit close okay so now that cuda's installed what we need to do is go and install ku cu dnn so this one's relatively straightforward so you need to go back to where you've gone and installed cuda so in my particular case it's my c drive so i'm going to open that up in a new window and what i need to do is go and find the cuda installation so mine is in program files and then it should be nvidia gpu computing toolkit so let me zoom in on that so you can see that there and then you can see it says cuda pretty big and we've got this version 11.2 which is what our tensorflow version needs now the cu dnn installation normally just comes zipped up so i've gone and unzipped it already inside of here you're going to have a folder called cuda and inside of that you've got a folder called bin include and lib let me zoom in on that in include lib what you need to do is copy the stuff from those folders into the matching folders inside of your cuda installation so you can see here inside of kudo we've got a bin folder we've got an include folder and we've got a lib folder so what we first need to do is grab all the stuff from the cuda or from the cdn folder open up the bin folder grab all of that paste it into the bin folder inside of our cuda installation so paste those there you can see it's going to copy over it'll probably ask for admin privileges maybe notice we'll see you can see it's got privileges we can hit continue all right so you can see that i've copied it from here over to here so we've copied it from the cd and then zipped folder or wherever we've gone and downloaded a folder so that particular repository we're throwing it into where we've got cuda installed and we need to do this for all of the different folders so inside of cdn we also need to go into include copy all of this and we are going to put it inside of our include folder from where we've got cuda installed so open it up include we're going to paste it in there hit continue right so you can see i've copied it from my video here to here then the last one that we need to do is the lib folder so inside a lib you've got a sub folder so x86 or x64 my bad we're going to copy these over we're going to go into lib x64 paste those in there hit continue oh yeah that's pretty much kuda and cu dnn now installed so we can actually mark this as done actually wait no i lie we actually have to do one more bit we have to update our path variable so let's go and do that lucky lucky save nick okay so let's go ahead and do that so we've gone and done all of our copies so that we can close that we can close that we also need to add let's mark these as done so that's done that's done grab a drink water gotta hydrate we now need to add our gpu or our cuda insulation to our path variable so these three lines need to be added to the path so c program files or wherever you've got cuda installed so this is the cuda installation that i've got so see program files nvidia gpu computing toolkit backslash cuda backslash 11.2 so if your version changes so let's say for example goes to 11.3 more often than not you're going to be putting in 11.3 here in our particular case it's 11.2 so we need to include the bin folder the libvp folder and the lib64 from cupti so we need to include those three inside of our environment variables so for windows you just need to go environment edit the system environment variables and then go to environment variables here and what we need to do is add these to our path so if you select path open that up looks like i've already got them in there let's actually delete those delete delete so all you need to do is hit new and then paste each one of those in so i'm going to copy that i'm going to paste it in there i'm going to copy that paste that in there delete the spaces and i'm going to copy that and paste it in there just make sure there's no spaces at the start hit okay okay that is cuda successfully installed but what we want to do is we want to go and validate this so let's just hit that as done let's go and validate that this is actually working now now right now if we went and opened this up inside of our jupyter notebook it wouldn't necessarily pick up because we don't necessarily know if it's picked up the new environment variables but you can see here that we've actually got errors it's saying cannot open uh what is that cudn 6 64 underscore 8 that's because it we haven't actually installed that or we hadn't installed that when we went and ran tensorflow so what we can actually do is we can stop all of this and let's start up our jupyter notebook again how do we do that pop quiz guys give you two minutes think oh two seconds thinking time never mind again jupiter lab cool leo so all right open this over here all right cross your fingers guys so again this is our same jupiter notebook we don't need to go and rerun the installs what we can do is now import tensorflow and fingers cross if we go and run this next line you can see our gpu is showing up there key thing to note that you do need an nvidia gpu that is the core thing so there it they are working on gpu acceleration support for tensorflow for amd gpus but it's really just not there yet um at least at this stage so in 2022 right now at the start of 2022 it's really not there yet it might be getting there towards the later this year or towards next year but for now just know it's not there as of yet but this tells us that our gpu is now successfully working so we can now mark this line as done let's jump back on over to our client and see what's last so it looks like the gpu is registered right right let's actually walk through this deep learning project it's something that i've pre-written that allows you to build an image classifier using convolutional neural network layers and any image data nice so it can tell me what any images well kind of it'll be able to classify an image as belonging to a specific class or not we'll take a bird's-eye view of it and maybe in a future tutorial we'll do a deep dive okay cool let's roll alrighty and we're back so we have one last thing to do so we need to train an image classifier for any image but for now let's take a look at what we've done so we've gone and installed python and jupiter with anaconda so that's done i've gone in or i've gone and showed you how to create a custom environment and attach it to jupiter taking a look at how to install tensorflow for deep learning and remember that it took 692 milliseconds per step without gpu acceleration we then went in and saw cuda and cu dnn and i showed you how to find the correct versions keep that in mind guys you need those correct versions last thing is we are going to go and train our image classifier now again this isn't going to be a full deep learning tutorial the core crux of this tutorial is to get you up and running we're going to go through the full image classification tutorial in a couple of days time or when i finally released that video but it is coming so the beauty of the pipeline that i'm about to show you is that you can literally download a bunch of images from the web and build an image classifier from it and that's exactly what i've done so let's actually take a look at our notebook so remember at the first lines that we ran in our notebook were the installation so we ran pip install tensorflow tensorflow.gpu opencv python and matplotlib we then also ran pip lists so we could see what versions of stuff we've got running we also went and ran some imports so import tense flows tf so this allows us to use tensorflow and import os so that allows us to navigate through our operating system this is some pretty standard code so by default tensorflow is going to expand to use all of your virtual ram so if i actually show you this so inside the task manager if i go to performance and go to my gpu so right now it isn't fully utilized as soon as we go and create a tensorflow model it's going to take up virtually all of that and it will try to take up more if we didn't have this set so this is going to help you avoid out of memory errors this is just a test so it's telling us whether or not we've got a gpu available so you can see that before we had crude installed that wasn't popping up once we installed cuda that is now available now when i was downloading images from the web i noticed that there were some dodgy file types that weren't necessarily working so these or these three blocks cl four blocks allow us to get rid of those so i can actually run through these and it's going to check whether or not the image is a valid jpeg dot jpg.bmp or dot png file and that is going to allow us to load that in to our tens flow data set now this is exactly what we're doing here but again we're going to go into this in way more detail once we go through the full-blown image classification tutorial which is going to be coming up and that will be for beginners right okay so what we can then do is load up our data so this line here so tf.carous.utils.imagedataset from directory allows us to pull in our image data from our data folder so if we go and take a look at our data folder today uh where were we image classification data so we've got two folders there happy and these are just a bunch of happy images that are pulled from the web and we all where are we going and we've also got a folder called sad again bunch of sad people from the web coolio so we can go and run that line and that is going to load up our data set what we're actually doing here is we're actually working with the tensorflow data loader so if you take a look at tens flow dot uh what is it data sets no that's not what i'm looking at um i want tf data data set oh another really really important tip guys is if you want to look at documentation for a particular line of code write the line of code and then type in question mark question mark it's going to open up the documentation for that how sick is that so what we're actually using in this is the tensorflow data set api so this just makes it a whole lot more efficient when you're training deep learning models but again i'm going to go into this into way more detail so we are using the helper which actually creates an image data set so it creates the or loads up the images or creates an image pipeline and it also creates a set of classes so here we've got two different classes we've got happy people and sad people so happy people are assigned class zero so you can see that there sad people are assigned class one we can then run it through our data pipeline so this pipeline scales our data so we actually divided by 255 the reason that we do this is neural networks perform well with data which is between zero and one or minus one and one so the smaller the data the faster your model is going to be able to train so that's why we scale so this is effectively performing that scaling there we can then split it into a training validation and testing partition boom and then we can build our deep learning model so here we are using the tensorflow sequential api there's two key tensorflow apis or keras apis the sequential api and the functional api so credential is really really good if you've just got a quick model that you need a prototype and you've got a single input single output if you've got a whole bunch of custom stuff or you've got multi inputs and multi outputs then typically you're going to be using the functional api the functional api is available through this so from tensorflow.keras.models import model that is the functional one this is the sequential one so again we can run that so we're going to be using the sequential one for this model so we can create an instance and then this is adding all of our layers to our deep neural network so you can see here that we have some cnn layers or convolutional neural network layers and then we follow that by a bunch of max pooling layers so this is affectionately called a block so we've got two blocks and we're repeating them so one block two blocks three blocks we then flatten it down and we are going to be outputting a single value and we are going to be activating that with a sigmoid function again you don't need to worry about what this actually means just know that we're taking in our images as an input and what we're going to get out of it is whether or not that particular image is a zero or a one that's what this neural network does for us so if we run this we can then compile this model and this allows us to assign an optimizer and a target loss function to our model so here our optimizer is an atom optimizer there's a bunch of them again we'll go into that into more detail later on and we are going to be using binary cross entropy which is the appropriate loss function for a binary classification model so we can run that and this gives us a summary of what our neural network looks like and tells us that our neural network has 3.7 million parameters so pretty big but again it could get way bigger i was using one that was 97 million parameters just yesterday then we can go ahead and train our model so again we can run these three lines and again shift enter allows you to run a couple of lines you can also run ctrl shift i think it's ctrl enter which stays on that cell shift enter goes to the next cell now remember that our neural network prior to actually having a gpu took what was it 692 milliseconds per step with a gpu it's running at 257 milliseconds per step so less than half the time so this means that having a gpu is going to save you a ton of time particularly when you've got massive models this is only a small model so you're only seeing a partial improvement even though it's more than 50 faster so again way way faster but pretty cool right and over here you can track how well our model is performing so we have it started out at 54.91 accuracy and it is getting up to 99 almost 100 so again performing way better and it's actually telling us our accuracy on our training partition as well as our validation partition we do that to help ensure that our model is not overfitting all right so that is our model finish training so again i went really really fast with the gpu and we can actually take a look at how it's performed so if we run this line you can see that over time so the green line is on our training data the yellow line is on our validation data so if you start to see these diverging it might be an indication that you have what is it a variance problem so again you might need to use regularization techniques to ensure that your model does not overfit so that's our loss and our loss is our binary cross entropy and then this is our accuracy so again i know i'm glossing over a lot of these components but we're going to dive into this in way more detail when we actually do the image classification tutorial so that's what our accuracy looks like and again they're sort of following together so we're looking pretty good we can then go and evaluate on our testing partition so here we're going to calculate precision recall and binary accuracy if we go and run this looks like we've got 100 for what is that precision 100 for recall and 100 for binary accuracy so again performing really really well we can then go and test it using opencv so use opencv to read in our data and we can then go and resize it and go and make a prediction so over here you can see we're running model.predict so there's two key things to your model so model.fit which trains your model and model.predict which actually allows you to make a prediction so if we go and run these we're on that line already yep we have if we go and run that line and we haven't run that key thing to note is that when you go and run your jupyter notebook for the first time if you haven't run it before these values are going to be zero over here but if you've run it previously saved it and then reopen it it will still show these values so we can go to here and run uh what is it let's not run it i'll actually go through it more in the uh object or the image classification tutorial but just know that if you see a value over here means it's been run at some time previously if you go and clear that output run it again you can see that that is now available if i clear it again go to edit go to clear output there's no number in there if i go and run this we now have a value so if we go and run the predict function it is predicting a 95 which is closer to what are we getting up here so closer to our sad class so ideally we've got a sound image there do we have a sound image we don't have a sad image is that predicting sad it's predicting sad so that doesn't actually perform that well let's go and test it out with another image so data we'll go and grab this one over here so this one is a sad image let's go and run this so that is predicting sad so this might be an indication that it is overfitting let's actually test it out on another image so if we go into our data folder happy let's go and grab i don't know this dude and if we paste it over here and grab the name of that file so it's 0 5-12-21 happy people paste that over here so that's our happy person happy person that is predicting happy so you can see it's closer to zero right happy that is one of the problems that we might need to fix up in our image classification tutorial so how to evaluate whether or not your model is actually performing well but in that particular case you can see we are generating predictions from our model using dpaddy neural network what we can then do is save down our model using the model.save function over here so now we have a file called image classifier.h5 let's actually call it um new version live so if we go and save that now my bottle's blocking my uh so if we go to image classification my bottle is blocking me what is that the taskbar so if we go into models you can see that we've now gone and saved down that new version so image classifier new version live and if we want to go and reload that so if you're going and building up a i don't know like an api or something you'd want to reload that into memory so to do that we can use the load model function go and paste that in there boom we've reloaded it making new predictions so i know i went through that really really quick but i wanted to show you how to set up your pipeline how to get things up and running and at least test this out but we are going to go through the image classification tutorial in way more detail in a tutorial coming up so you'll actually see how to do this properly how to grab new data how to add new classes so on and so forth but in a nutshell know that you need to install your dependencies clean it up load your data do any pre-processing and then build your deep learning model and take a look evaluate it and then actually test it out but that in a nutshell is how to get up and running with deep learning again stay tuned we've got some more stuff coming thanks again for tuning in guys peace thanks so much for tuning in guys hopefully you enjoyed this video if you did be sure to give it a big thumbs up hit subscribe and tick that bell and let me know what you thought of this we are getting very much back into deep learning tutorials and really doing stuff from scratch like how do you stack layers how do you build really specific use cases let me know if there's any specific ones that you'd like to see or any specific deep learning use cases that you've seen floating around the web that you find interesting thanks again for tuning in guys peace
Info
Channel: Nicholas Renotte
Views: 156,863
Rating: undefined out of 5
Keywords: python, deep learning
Id: 19LQRx78QVU
Channel Id: undefined
Length: 70min 43sec (4243 seconds)
Published: Fri Apr 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.