hi there in this video i'm going to show you how
you can install tensorflow 2.5 CUDA 11.2 CuDnn 8.1
with the full support for an nvidia rtx 30 series gpu and since cuda is
backwards compatible whatever i'm doing here should also work
in any nvidia gpu including the rtx 20 series
but before i install cuda i will do some benchmarking of tensorflow
without a gpu i'll be training an image classification model that i have
developed in a previous episode with my amd ryzen 5900x
cpu the amd ryzen 5900x cpu has 12 cores and 24 threads and it's a
great cpu all around perfect for someone who wants
to dip their toes into deep learning once i complete the code setup i will
try to complete the training of the same model
with my nvidia rtx 3070 gpu which has 5888 cuda cores and i'm expecting of
course to beat my amd ryzen 5900x cpu by a big margin because gpus are just
faster than cpus when handling lots of matrix
calculations but i'm going to be open-minded you
never know one of the reasons i'm a bit open-minded is that
i saw on github an open issue regarding the rtx 3090 being slower than
the nvidia gtx 1080i for predictions in this case with rest
that this might be because of tensorflow itself which is still
implementing cooper 11.2 and not yet taking full
advantage of the ampere architecture but of course this is just a result
between gpus uh in general a gpu is going to always
be a lot faster than a cpu if not there must be something wrong
what are we waiting for let's get started
before we try to install tensorflow let's first install anaconda and conde
is a toolkit that includes python
and libraries that are the favorite for most data
science machine learning web scraping projects on the web
and it already includes jupyter app which is um my favorite
web-based id and it's very useful for general development of notebooks for
tensorflow and anything to do with python with anaconda
we also can run different versions of python in isolated environments
which only contain the python libraries and versions that we need
while still having access to pip we also have access to the
conda package manager which allows us to install
pre-compiled libraries for python contrast that
to pip which if you use pip instead of of using the compiled binary of a
library it needs to compile it from source
during installation which takes a lot longer and it can fail
especially if you don't have other dependencies in it
before starting it's a good idea to update
to the most recent version of the nvidia game ready driver
in this case i already have one of the most recent
versions and so i'm not going to update it i had to update my drivers recently
because i enabled the resizable bar support and as you can see
here i have this switched on which is quite cool at least
for games not for not for deep learning but it's there so
now let's start anaconda let's create a new environment two point
five so tensorflow two five so in this
environment i'll be able to install the libraries i need for
tensorflow and for anything else it's good to have an environment because
then we can reduce the chances of having dependencies
issues with dependencies between libraries with different persons
and with tensorflow normally you have a little bit of
that issue because there's a lot of libraries that it requires
so let's now open a command prompt in administrator mode
and we can do conda activate tensorflow 25 and i'm going to install
a tensorflow 2.5 but for now at the time of writing yoni can use the
release candidate that's it still hasn't been released for
general availability but you can already use the release
candidate which works with cuda 11.2.1 you can see the latest available version
is 2.4.1 but if you go into the release history
you can see that there is 2.5.0 release candidate one
so i'm going to use this version if you are more adventurous
you can even use tensorflow 2.6 from the nightly build but that's probably not a
very wise thing to do okay so let's install tensorflow 2.5
okay it's now installed i will install some extra libraries
um because i know that i need them i'll install by the way
normally you will install packages using the conda package manager but in this
case because tensorflow 2.5 is not yet available
in conda itself then that's why i had to use pip
so now that uh i need to install matpolip i'm going to actually use
conda for that because it's much easier the advantage of using
conda instead of pip is mainly to do with compilation so
all the packages that you get in anaconda they are already
pre-compiled and you don't have to worry about
having issues compiling code now i'm going to install
pandas as well okay so it's all done now that i've
installed the libraries that we need let's start
jupyter lab i need to install it first it's quite
handy to do it like this so you just have to click install and it will do it
for you that's why many people like anaconda gets you up
and running very quickly rather than having to install everything
with pip by hand okay so let's click launch so i have a
notebook here which i created in a previous episode and this notebook
actually trains an image classification model to basically to check if
a painting is of the nativity uh or not so you can check it out the videos i'll
put that into the description if you're curious how i got to this
model so i'm just going to make sure i clear all the outputs first
so we're going to run this notebook using the cpu only right so i haven't
installed cuda yet so i'm going to be only relying
on the cpu itself so i'm just going to start it now and here
there is some code that tells me if that what tensorflow version i have whether a
gpu is available or not so i can see here version 2.5.0
the release candidate one by the time you watch this video
tensorflow might already have the actual official 2.5.0 version
but until then you'll need to use the risk candidate if you want to use
kuda 11.2.1 and okay you can see gpu is now available so
let's run keep running the notebook so this notebook
actually downloads files from a dataset i've gathered about art
containing nativity scenes but because i've already done all the files
beforehand i'm going to skip the steps here i don't
need resizing images because i already have
everything in place don't run this as well so
we start basically here so at this stage we can see how many images we have in
our data set 452 for the nativity
i think it's total action some pictures from the nativity
just to check everything looks good and then
another data set we have which is not nativity
i know it looks very similar but it's this is
not a nativity uh painting although it looks like it
now we're just going to run the notebook and do the training with the cpu
and see how the amd ryzen 5900 does with training without a gpu it's
probably going to scream a bit not yet because i haven't
started the training yet so we'll be creating a model and then
this is the first place where we're going to do some training for 10 epics
and see how fast this goes
okay case finished the first training
so accuracy on the test data set is 67 0.67 it's not too bad
okay now 25 epics and see see how long it takes
so the training completed it's not too bad now we're going to do
transfer running okay so 25 epochs with transfer learning
this is a much bigger model and it's going to take a bit longer
it has completed the training and uh let's just check so the training looks
good actually so the the loss goes down which is what
we want to see on the validation on the training that
said it always happens it goes down because a neural network is
very it's very good for for fitting against
the data in which it's trained so let me just see
if i can gather some more information we can see that for transfer learning it
took like between 11 and 13 seconds per ad book
to train each step in the previous models
without using transfer learning and this is training a model from scratch
it takes 161 milliseconds per step which is quite good
and this one takes about 157 milliseconds
so you can see that because we are using a bigger model it takes a lot longer
in this case we're using the exception architecture which is trained on
imagenet okay we can see how long it takes to do
uh fine tuning
okay so it took two seconds per step fine tuning and then 47 seconds per
epoch compared to 11 seconds per epoch here
okay this is just to check how good the predictions are
predicted this p run troop is gt in this case it's not even activity it
seems too much much is good good no this one is bad so in total has
a 72 percent accuracy okay it's finished
i'm done the testing train the this custom image classification model
without a gpu and now let's uh go through the setup of
cuda and see how much improvements we can get
after we get kuda working which should be a bit of an
effort to be honest let's do that first thing i'm going to do i'm going to
download cuda make sure you download the version 11.2 dot don't download the
version 11.3 or any earlier version because
it will not work so i'm i'm installing this on windows 10
and 2.8 gigabytes so it'll take a bit of time
all right so it finished downloading kuta so i'm going to
install it now all right so cuda is now installed next is to
we should install qdn so i'm going to download
qdnm 8.1 so for that we need to log in uh you need to have a developer account
i already have one so this is the version i need to
download the first one for cuda 11.2 windows version in my case
now we have to unzip this uh directory so now we need to
copy certain files and this is where it gets a bit tricky we have to do this by
hand so i'm going to open the cuda
the cuda folder which is going to be inside program files and
nvidia corporation no not this one sorry
it's going to be inside nvidia gpu computing toolkit
cuda 11.2 okay so we have now to copy so i'm following these
instructions here so first unzip
which i've already done i already have two folders
one for with cuda and the other with qdn now this one is
dnn so i need to copy from this folder to the cuda folder
so first one i need to copy is all the files inside
pin with this name qdn dll so let's do that so all of them are qdn
dll and we're going to copy that to cue the
version number pin here so these files here
because i didn't do for all of them so now i have the files in the right place
so the second step is to copy the header files for inside include
directory qdn.h
so all the files in here actually and then i should copy that to to the
include folder so i shouldn't copy the files here
it says it has to replace files well i'll see me has it okay i'll
replace the files it needs administrator permission
okay and now the last step is to copy the qdn lib
so i need to go inside the lib directory x864
then i need to copy all these files into the equal font folder inside cuda
and i'll replace all the files okay so then so the next step is we need to
set up some environment variables so the
instructions tell me to start this process the system properties
so i can go to advanced advanced environment variables there are already
some variables set up here so we need to add code path
oops mistake so i need to make sure it's a valid path
so 11.2 so it's all good so i have set up all
the environment variables now let's go back to tensorflow and see
if we i don't think i need to run this step
here i'm going to just leave it out for now
i think that might be if you're trying to do some development with this library
itself and if you want to compile tensorflow or something like that
but that's not the case for me so let's go back to tensorflow
okay let's see if it can detect my gpu now
remember before it it said there's no gpu available
let's see what it says now i need to restart the kernel just in case
you can see now it's able to detect the gpu which is good
okay so that's very good now i'm going to run
again this notebook and see how how much faster the training is compared to
before i need to start from the right step so i
should start from here so here i'm compiling the module now i'm
going to run the model see before it took 1567 milliseconds
i'm using the gpu at the moment for recording this so i might have to switch
it off i'm just going to try and see what happens
if i don't do that okay it still works as you can see it's a lot faster before
it was doing in milliseconds now it's doing
almost like in zero seconds so 11 milliseconds per step okay
but this is not a lot of data so it doesn't take very long and the model is
very small but it's considerably faster than
my amd ryzen 5900 okay now it's just a second
attempted training it's very fast okay let's do the transfer running this
is the one where it's supposed to take a bit longer so it's
taking one second per step and sorry one second
per epoch and before it was taking 11 seconds
and notice there is a the first epoch takes a bit longer because this is a
startup time for tensorflow this is actually a known issue
takes a bit of time so very quick much quicker than my cpu as you would
expect look at this this is like sweet spot of
this is what you want to see in terms of validation loss going down
a conjunction with the training loss so here
we are running again the training with fine tuning
i am using uh the gpu as well for recording my voice
because i'm using rtx broadcast so i think this is actually going to be
quicker if i don't run this application at the same
time as i i run the training but you know you can
see it's actually reasonably fast no so before it was taking 44 seconds
per epic now it's taking nine seconds for the
first one and then five seconds for the the next one so it's much faster as you
would expect and that's about it so i've installed tensorflow
2.5 which supports cuda 11.2 i've installed cuda and at the same time
i even showed you why you want to have a gpu rather than
just relying on a cpu even though i have a very good cpu it's
a ryzen 5900 you know i tried to train the same model
in google cloud without the gpu and it took forever this
cpu is already uh doing a lot you know for a first cpu
is actually not bad for what it's it's trying yeah compared to google
cloud at least the cpu is really good as you would expect all right and that's
about it i hope you enjoyed this video i'm going to have
an article all the steps that i've gone through in this video uh
also uh written down so you can follow it easily
i hope you enjoyed this video and hope see you again soon don't forget to click
the like button by the way and happy coding bye