#3 Installing OpenCV, PyTorch & TorchVision on Jetson Nano | 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to this course on the nvidia jetson i am brandon on behalf of tayab and today we shall talk about some useful libraries that we will be using throughout this course and we will also see how we can install them on our jetson let's get started in this lecture we will discuss some popular libraries including opencv pi torch and torch vision we'll start with the installation of python along with some other supporting libraries luckily the image provided by nvidia already contains python 3.6 with most of the supporting libraries including numpy matplotlib etc it also has opencv installed inside it but the problem is that opencv is not built with cuda support so therefore we have to install the cuda enabled opencv library from scratch thereafter we will move on to the other two main libraries which are pi torch and torch vision before doing all that let's discuss a little bit about these libraries open source computer vision abbreviated as opencv is one of the largest libraries designed to implement the mathematics of computer vision it was initially released in 2000 and was upgraded over time with the latest functionalities the most recent version available at the time of this recording is 4.5.4 that contains around 2500 algorithms both traditional and state-of-the-art opencv comes with support for cuda making it capable of running machine learning algorithms on its gpu cool so that was a quick introduction of opencv let's now discuss another popular library that we are going to use throughout this course which is pytorch pytorch is another famous library provided by facebook that was released in 2016. pytorch was especially designed to efficiently perform machine learning or deep learning math pytorch uses tensors as the input output parameters tensors are similar to numpy's n-dimensional arrays except sensors execute directly on the gpu due to these capabilities and its ease of use pytorch became the most popular choice from the ai community during the last few years before pytorch tensorflow was the most commonly used library for the implementation of machine learning math however tensorflow was quite difficult to implement especially when it came to the customization of low-level functions but still it had quite a large community keras is another famous library which actually came with the back end support of tensorflow which made it easy to use because it worked as an api and helped provide the ai community with a flexible use of tensorflow however being an api it did not provide direct control to the low-level functions of tensorflow so pytorch solved all these problems by providing a user-friendly platform to machine learning users that can easily customize the low-level functions according to their needs from the given survey we can see how the people's preferences rapidly changed from keras or tensorflow to pytorch during the last two years another important library that comes with pytorch is torch vision it is specially designed for computer vision problems that are related to machine learning with the assistance of pytorch since it is part of pytorch it already has the support on the gpu it also contains several image data sets including mnist cifar coco and many other important data sets that can be used to train the machine learning models it also contains several pre-trained models including resnet inception googlenet etc which can be used to further train the built-in datasets or with their custom datasets as well so that was a quick overview of some of the important libraries that we are going to use in this course now let's move on to the jetson where we can see how to install these libraries and set up our jetson for the execution of machine learning models okay so we have started our jetson and now we will start with the installation process in which we will install the required libraries that we have discussed so far but before installing them i want to mention here that i have already created an image on which all the required libraries have already been installed so you don't need to waste a lot of time on the installation process you can simply flash this image directly on your jetson this image can be found in the description of this lecture so you can download it from there however you can also follow the instructions given in this lecture if you want to set up your jetson by yourself so if you're using the given image which i've provided just move on to this drive open it up and inside you will find a folder named nvidia jetson course inside you will find there are around 15 folders here which are the module folders containing all the materials related to the lectures in total we have 15 modules for this course so i've created 15 folders and each folder contains all the required material that we will be discussing in each module currently we are in module 3 so we will open module 3. here i have placed the document in which all of these transition commands that you will be using for the installation of libraries are all present ok so here you can see all of the commands we will go through all of them one by one starting with the system level packages which we will use to update and upgrade our advanced package tool so let's implement this one by opening up our terminal okay so we will start with the first command you can simply copy and paste this line enter the password and it will update all of the advanced package tools we will wait for it to complete there we go it's done let's move on to the next command which is the upgrade command first we need to clear it okay so most of these are already upgraded so we don't need to upgrade them and now we will move on to the next part in which we will install some system level dependencies so if you're using the latest version of the developer kit provided by nvidia we will find that most of the libraries will already be installed so let's try them one by one you do actually have to check all of them to make sure that you don't miss any so for example we try the first one and it says that it's already installed so let's move on to the next one okay so this one is also installed so we move to the next one okay this one is also installed the next one is also installed right let's try this one cool so it's also installed i think all of them are already present but we do have to just check to make sure great so this dependency is also installed let's check cython okay so on to the last one this process will have saved us a lot of our time right so it is also installed now we will download and update cmake in which you will later use for the installation of opencv so using the wget command you can download cmake from the given link you can either download it directly or you can use the wget command to download it but since i've actually already downloaded it and built it here i won't download it again but this is just to explain the process for you cool so if you were able to download it it would be a zip file which you would then have to extract creating a folder like this from inside the folder you have to run this command which will take a little while and then using the make command you have to create the cmake directory which will take around 20 to 25 minutes so once this has been completed we will update our path so we'll place this path in our bash so let's make sure that our path is present okay cool it's done and this one is fine it's also done let's move on to our next part which is actually the installation of opencv but before doing that we make sure to install the supporting libraries for opencv i do believe that all of them will be installed but we can't risk it so we need to double check all of them to make sure okay this one is installed let's check the next one yes this is also installed okay that's great these libraries are already present nice i believe this one is also already present this one is also present as well so let's try the last one and then we will move on to the opencv installation great so we are done with all of the supporting libraries for opencb let's move on to the next part so when we are ready to install opencv we will first download opencv version 4.1.2 this version contains most of the required features that we will be using in the future lectures however you can install the latest version as well but just keep in mind that if you use a package to install opencb you might not be able to install it with full cuda support so in order to install opencv with cuda support we have to install it from scratch which we will do so in the next lecture here i must also mention one more thing if you have downloaded the latest version of jdk from the nvidia website python and opencv are already installed and integrated however the opencv that comes with it is actually not built with cuda support that means you have to first uninstall that one and then install this one from scratch so again here you would use the wget command to download opencv from github which will be saved as opencv.zip so to save time i've already downloaded it here you can see opencv.zip as well as the opencv contribution items which i've also already downloaded so let's unzip it and then we will move on to the next part so we clear it first just note that it will take a bit of time great it's done so we clear it and then we check do we have any folders with names of opencv ok here we have opencv 4.1.2 so before installing it let's also unzip the opencv contribution folder so copy and paste cool so now we will change the names of our folders here we can see our folders open cb 4.1.2 and open cv contribution so just simply rename this one to opencv and similarly we will also change the name of this one to opencb contributions okay so these are our main folders now let's move on to the next part we will navigate into the opencv folder using cd command and we will create a directory with a name build because we are going to build all the data in this folder so we have our directory here with the name build and let's navigate into the bulb directory ok let's create it now in order to check whether you are in the correct folder or not we use the command pwd this will then show you which directory that you are currently in so we are right now inside the build folder this is your home directory and then it's my account and then it's opencv and that's correct great so the next part is actually the main part in which we will configure our opencv with different configurations for example here we have gstreamer and cuda so it will create a cmake with cuda support so let's try this one over here you have to copy and paste it directly here so just make sure that you have copied it directly so this is a configuration through which opencv will be installed so ensure that you have properly copied this and do not change anything if you want it to work with python 3. otherwise if you also wanted to work with python 2 then simply make sure that it states on over here instead of off i will only be using python 3 so i'm not going to integrate it with python 2. we will also be using gstreamer in the later lectures that is why i've also checked it on here so let's try this one great so now it's configurating once it is complete then we will move on to the next part so the next part is actually the make command here so we'll be running cmake on the configuration we have done so let's simply copy and paste it so this is the configuration through which opencv will be installed so you can check it out and make sure that you are not going in the wrong direction and that you have configured it properly so as you can see we have disabled the python 2 and the gui says yes it is available and also they are the same configuration for video parallel framework is also present p threads and our application on nvidia says yes so it will be configured with cuda now before we start we just need to clear our terminal first and now we can start it with the make minus j4 command cool so we have started building opencv from scratch using cmake and this may take some time so take this time to grab a cup of coffee or a beverage of your choice because it's going to take around two to three hours to complete so just pause the video here and we'll come back when the installation is done okay so finally opencv has been built using cmake now let's finalize the installation using this command so it took around 2.5 hours for me it might be more or less for you ok let's finalize the installation with this command it won't take too much time okay so we are finally done with the installation of opencv now let's test whether we have installed opencv correctly and that it has cuda support so let's clear our terminal and let's move to the parent directory and clear it again great so please start python 3 and we will see whether we can import our opencv or not nice so it has imported successfully which means that opencv is installed properly so now let's try to see whether it has been installed with the cuda support to do this we have a function available in opencv that allows us to check whether cuda is enabled or not type in cv2 cv2.cuda.get cuda enabled device count so this will return the number of gpu devices available on your machine so currently we only have one gpu here so let's see what it will return okay so it returned one that means we currently only have one gpu available in jetson which is correct so that means that opencv has been successfully installed with cuda support and it can now be used for different applications to execute any kind of computer vision models in which we would require cuda so that was all about the installation of opencv so let's stop here we are now done building opencv from scratch along with the cuda support see you in the next lecture now let's move on to our next important library for this course which is pytorch so we will start pytorch now but before installing this let's start with its supporting libraries so we'll start with the first library okay let's first clear our terminal great it has been installed already let's install this one as well okay it's also installed let's try this one okay it is showing that most of the libraries have already been installed here but it doesn't mean that the jdk you have already downloaded and deployed on your jetson will also have all these installed on your device this means you will have to check all of these commands including the libraries available on your jdk and test them just like how i'm doing so that you can make sure you are not leaving anything behind that may take a bit of your time but at least you will be sure that you have successfully installed everything properly okay so now that we know that everything is installed let's move on to the pi torch library so before installing it you have to download it from this link therefore you will need g download in order to download anything from the google drive so first we'll clear the terminal i have already installed it before so you can try to download it using this command g download and provide the link or you can download pytorch directly from here or from the download section of this course i have already downloaded it so you can see that it's present here therefore i won't need to run that command i will simply run this command so we can simply run it this way and then our pi torch will be installed so let's try this one okay let's clear it first so it has started processing the pi torch wheel which we have downloaded since it will take some time i'm going to pause the video here and continue once it is finished okay so our pi torch library is installed now let's move on to our next library which is the torch vision library once again we also have to install all the prerequisites for the torch vision library so let's do that first okay these are already installed this one is also installed let's try this one as well great it's also installed so now you have to download torch vision via this link using the same method you used for pytorch i've also installed torch vision as well to save our time so since i have already downloaded it let's run this command to install the torch vision library once again we clear our terminal nice clean slate paste the command here and let's run it okay this took much less time cool so now we are done with all of the important libraries that we require so let's give it a try and see whether all these libraries are working or not let's start with opencv and it is imported so let's go to pytorch pi torch is referred to as torch so let's see whether we can import it yes so torch is already imported finally let's try torch vision okay great so we have successfully installed all three of the libraries that we will require for this course so that's all about the installation of these libraries to conclude i just want to mention another thing which is that we cannot do all this coding on the terminal since it is not very user friendly so for that purpose we need to install jupyter notebook maybe most of you are already familiar with jupyter notebook which is actually a very good editor in which you can save all of your code in one place i have already installed jupyter notebook but if you have not yet installed it you can simply use this command run it and jupyter notebook will be installed once you are done installing it then you can open it using the command jupyter notebook right it will then open in the browser you can then create a new notebook using python3 and you can give it any suitable name we are doing testing so let me rename it as testing then we will try to load all three of the libraries in a single cell so let's try torch version and see if it works okay so there was no error that means that all three of the libraries have loaded properly which means that they have all been successfully installed so that was the goal of this course we have successfully installed all three of the libraries as well as tested that they are integrated with python so in the next module we will discuss these libraries in more detail we will try some basic functions of opencv and pytorch and we will also try one of the data sets provided by torch vision okay so that's it for this lecture we will meet again in the next module cool so if you're ready to get started what you need to do is scroll down and you see that link over there yeah yep that one click over there it'll take you to a page where you can sign up to get a free preview of the course type in your name and email and you can start learning for free otherwise if you're ready for the comprehensive course we are running a special pre-launch campaign where you'll be able to pre-order jetson pro now at early bird prices you'll also find the harvard requirements there on the entrance page don't waste time don't let your competition learn this before you do enroll now if you're ready to learn the jsonpro course links are all down below and we'll see you inside the course
Info
Channel: Augmented AI
Views: 10,821
Rating: undefined out of 5
Keywords: opencv, computer vision, opencv tutorials, computer vision tutorials, artificial intelligence, tensorflow, opencv python, jetson, JETSON Nano, jetson course, jetson tutorials, JETSON Nano tutorial, jetson lessons, introduction to Jetson, jetson sd card, jetson pytorch, jetson torchvision, jetson computer vision, jetson opencv install
Id: UiZaM-Wbc6A
Channel Id: undefined
Length: 24min 10sec (1450 seconds)
Published: Tue Apr 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.