L-5 YOLOv5 on Jetson Nano | PyTorch & TorchVision Installation on Jetson Nano

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is arohi and welcome to my channel so guys in this video I'll show you how to install pytorch and torch Vision on Jetson Nano after that we will learn how to set up and run YOLO v51 Jetson Nano and we will cover how to use uh the pre-trained weights which are trained on Coco data set I'll show you how to use that pre-trained weights and test on various input sources we will see how to work with CSI camera USB cameras and then how to work on images videos rtsp streams all these things I'm going to show you today and guys I'm assuming that you already have python installed on your Jetson Nano and pip is installed and after that opencv is also installed on your device so if you don't have these things with you right now before watching this video I would recommend to install all these things first and you can check this video this is the third lecture on Jetson Nano and in this video I have explained how to um set up your python environment how to upgrade the PIP and how to install the opencv um with Cuda compatibility okay so check this video for that so now I'm assuming that you have all these things in your um Jetson Nano and let's start with the today's class so first thing is we are installing the pi torch so now guys uh one thing to note over here is that we can't install pytors using pip because on this Jetson Nano okay so we have to manually install this pre-built by Dodge pip wheel okay and then from The Source only so let's see how to do that so let me open the link from where you will install it okay this one so I will share this link in my description section okay so from this link you will pick the pie torch version as per your jetpack SDK version okay so jetpack SDK version is the jetpack uh which is installed on your uh Jetson Nano remember at the time of initial boot you downloaded the image of a jetpack SDK then you flash your SD card with that um as a jetpack SDK and you installed that boot your Jetson Nano right so that version that jetpack SDK version you should know the version and on the basis of that version you will install the pytorch version so in my case the jetpack SDK which I am using is 4.6.1 so I am showing you today's class on the basis of that jetpack SD okay okay so you can see here the different pie torch paper wheels okay let's click on the first wheel first so you can see here that jetpack SDK 5 is supported and then 5.1 and 5.2 so that means if you are working on Jetpack SDK 4 this pie torch pytosh 1.12 version is not for you okay now let's check this pie torch version 1.10.0 here you can see that jetpack SDK 4.4 4.4.1 and then 4.5 and for 4.6 so my Jetpack version is 4.6 so that means I can install this pytorch version 1.10 but I have installed this one there is no specific reason guys so what I have done is I have checked this partosh 1.8.0 and it was compatible with 4.6 so I have directly installed it I didn't check the above versions okay soon but in your case you can go with the spider 1.10 also if you're using jetpack SDK uh 4.6 all right and okay so this is the version which I am installing right now once you know the pytorch version which is compatible with your jetpack SDK okay then scroll down and under this instructions click on this installation here you can see the installation these are the steps these four commands will install the pi torch on your Jetson Nano okay so what you need to take care over here is that in first line in this line just move it like this over here you have to write the real file name which is compatible with you for example in my uh let's suppose if somebody is installing this 10 version then this is what you need to copy from here and replace this with that wheel file okay this is what you need to do all right once you've done that then you just copy the commands from here one by one okay these are few modules second line these are few modules you need just copy this command from here and put it on the terminal and execute it and then again install the python and then install this okay these four lines these four commands will give you the pi torch okay now you have the pytorch version you need a torch vision for that okay so for every pytorch version there is a different torch Vision version okay so in my case my torch version is 1.8.0 I have to download and install the torch Vision which is compatible with it so let's scroll down and under this torch Vision you can see we have set of commands you have to execute all these commands one by one the only thing to take care is that over here version okay so over here you need to write the torch Vision version which is compatible with your pytorch version so in my case the pytorch version is 1.8.0 now how would we know that which is the compatible torch Vision version with that so scroll down for that over here you will see a list of versions this torch Vision version is compatible with this Pi torch so in my case my pytorch version is 1.8 so that means the compatible torch Vision version is 0.9.0 so I will install this version so copy this version from here and then while installing the torch Vision these are the four five commands first here here you need to replace this with your version so in my case 0.9.0 so you will write V 0.9.0 okay and over here after that when you are here to execute this command over here you also need to mention the torch Vision version 0.9.0 and then install setup and then CD to this and then install this command these few commands will install the torch Vision okay so that's it guys this is how you install python torch Vision now we have to see uh let's verify the installation if this installation is correct or not so for that what you can do open the terminal let's open Terminal and open python shell so the python version I'm using is 3.6.9 and guys you get this python version by default and Nvidia I recommend to use the default python version so if you are planning to work on a python version higher than this so let's say you want to work on python 3.8 then you can install the jetpack SDK uh five or in that you will get a python 3.8 okay so but if you're working on this Pi jetpack SDK 4.6 so as per Nvidia they say that work on the default python versions only otherwise there will be a problem in um you can face problems okay so this is my python version let's import torch so once it imported and after that what we can do is we can copy this command from here and paste it here so you will get your torch wall pie torch version so my pytos version is this that means I've successfully installed the pythons in the same way let's import torch vision import torch Vision after that let's check the torch Vision version so you can see here that my pytorch version is this and torch Vision version is this so we have successfully installed these two things now the next task is to run YOLO V5 on uh Jetson Nano YOLO V5 works on pie torch framework so we have the pie torch with us now we can directly work with um this yellow V5 let's see how to do that okay guys so for that I have this Jupiter notebook first step is steps are similar the way we work on our uh Windows machine or Ubuntu machines the same way we are going to work on uh this also right so the first step is to clone the GitHub repo of YOLO V5 so this is the official GitHub YOLO V5 repo so we are cloning that once you clone that you will get a YOLO V5 folder okay let me open my folder location and show you so here I'm working this is the YOLO V5 folder okay this you will get after cloning and now you need to get inside this folder from here CD YOLO V5 once you enter in that folder okay this is one command which you have to execute sudo apt install this command okay this is the a few requirements you have to install it so install this command after installing this command you have to install the requirements.txt but guys remember in this requirements.txt file they have mentioned the pi torch and torch version also but we have already installed it right manually so we will delete those versions okay so let me show you Soul see in this YOLO V5 repo you will get a requirements.exe let's open this file now when you open this file here you can see the torch and torch Vision version okay so but we don't want to install these things because we have already done these two steps so you can delete these two things from here and then you can after deleting this you can run this command pip 3 install hyphen R requirements.txt this file will install all the other requirements of YOLO V5 all right then after that uh what we need is we need the pre-trained YOLO V5 weights and that what we are doing here we are downloading the weight file this weight file we want to download right so we are downloading it from the official YOLO V5 repo and you can see okay let me show you all right you can see over here once you execute that this command okay you will get YOLO v5s dot PT file dot PT means Pi torch model okay so this is the pre-trained uh pytorch model and it is trained on Coco data set pre-trained Coco model is this okay now we are checking the opencv version so I'm using 4.1 5.1 and after that I am using the detect command so guys this python detect dot py this detect dot py you will get all the files and folders inside this YOLO V5 repo once you clone it you get over here right so this detect dot py file is responsible to perform the detections on various different sources like how to it will uh it it have a code it will accept the source input source uh USB camera rtsp streams images and videos okay this file don't have a code which supports the CSI camera all right so that code that part we will add ourselves don't worry I'll show you that part in some time first let's see if this python this detect.py is able to work on images videos USB camera and rtsp streams once we test all these four sources after that finally I'll show you what and how to add in what code to add and where exactly to add that code in detect.py in order to work on CSI camera okay so let's see so initially I'm starting with the source image so python detector py and we are providing the source we want to perform the detections on this image and which weights file we want to use the weight file we have downloaded just now the pre-trained weight file using this we want to perform the directions and once you execute it you will get your results stored in runs folder under runs folder you'll get a detect folder and inside that you will get a exp folder over there you will see the output so let's see the output and first see the image like let's see which image is this and then we'll see the image with the detections all right so let's go back here so this is our test image so you can see over I have written testimage.jpg and this is the image let's open it so this is the image on this I want to perform the testing now let's go inside this YOLO V5 folder and see runs inside run we have detect inside detect we have exp so I have renamed it so exp image is this folder okay so let's open it now let's see the output so you can see it is detecting it as a person okay so this is how you can work on image now let's see what's next source is python detect.py this time we are giving a video as a source now let's see this video first the we'll see the input video first and we'll see after that we'll see the video with the detections okay so let's go back here and you can see this is the cards dot MP4 let's open this video so this is the video now we will perform the testing this is a short video 10 seconds video okay so now let's see the video with detections runs detect exp underscore video okay let's see the output okay this one is uh sorry guys I have done the testing on a different video but you'll see you can see here also that we are getting the output right now let me open the another video to show you okay so let me open the the video exp to video yeah this one I'm talking about so you can see this is how it works okay so now it is working on video also next thing to test is Source One this uh see guys uh you can try Source zero and Source One for web camera because sometime it works with Source zero on Jetson Nano on our normal on a computers right on a Windows machine and on a Linux machine it works with Source zero okay for web camera but over here on Jetson Nano I am facing I was facing a issue with when I provide 0 as a source at the time I was getting error then I provided one as a source and my web camera is working so that's why I've used Source One you can try with Source zero first if Source zero is not working then you can try with Source One okay so when you execute this command this let me execute this command for you let's comment all the above codes okay and then let's execute the code so once you execute it it will take some time and it will open a web camera and then web camera will detect the objects so guys this is how you will see uh output of web camera okay so now let's move to the next Source our next source is rtsp stream here ESP Stream So sources this rtsp stream okay you can see this IP address and the password and then this whole URL this is our rtsp stream okay now see you can processes started and then we were able to connect with this rtsp stream and now uh it will open the camera and show you the output so guys you can see the output right so uh this is how it works and now let's close it so for that you just need to do Q so this is how rtsp stream work now the next thing is to work on uh CSI camera so let's see how to use that so for that what I have done is so guys I took help from this GitHub repo so what I have done is I have downloaded the elements folder from this GitHub repo and I took the code from some code from here okay so download the elements folder and place it in your YOLO V5 folder let me show you where I have placed this is the Euro V5 folder you can see the elements folder over here place it over here download it from this GitHub repo and place it over here so this folder have only one file this YOLO you don't need this file okay so this is the file we have and then we will use the code from this file okay this is the code all right so now let's see what we have done so basically I just created another copy of this detected detect.py and I have given a name detect underscore modified dot py this file detect underscore modified.py file this file will work with image video CSI camera USB camera rtsp streams okay this file was not working with CSI camera so we have added some code in it to make it work for CSI camera also so let's see this file so okay let's open this file so what we have done is so this is the file detect.py file so over here this is the code firstly I have added in the beginning so I am importing Nano camera because using this Nano camera module on this camera interface I'm using this Nano camera interface using this interface I will use the CSI camera okay and if you don't know about this camera interface then just install it by pip install Nano camera after that import it over here like this all right and then remember we have our elements folder which we have downloaded from the GitHub repo from this element folder we are using a YOLO file and in that YOLO file we have one class with the name of object detection we are using that okay so we will do the detections with this class object detection class and it is in yolo.py file which is in elements folder okay and object classes this is a list so guys Coco data set have 80 classes so these are the names of those 80 classes and then object colors have the different colors for all the bounding boxes and object detector variable object underscore detector in this variable we are calling we are calling this object detection class and we are providing the pre-trained model this pretrained model is trained or coco data set and these are the 80 classes of that data set object classes okay this so we have done pasted this over here so from where I got this this I got from this file okay this file this Jetson yolo.py you can copy the data from there and paste it here after art just scroll down in this run function scroll down so after this line Source equals to string Source after this line I have added this code this code will read the CSI camera and then will detect the objects so basically what I have done is I've written if source is 3 that means if you are providing source is equal to 3 in your detect dot py command the way we were working with other files over here okay just give me a minute so let's say if you are writing python detect Dot py and then we provide the source if you provide Source 3 okay and then provide the weights weights are YOLO v5s dot PT this is how we write the command right so this Source three few give Source three over here then what will happen what I have written is okay where is that code yeah so I've written that if source is 3 then with the help of Nano camera interface I want to open a CSI camera and this is the line this one line is responsible to open a CSI camera and after that if camera is ready CSI camera is ready then we will read all the frames one by one and after reading those frames we are storing those frames in frame variable and then object detector remember this is the variable in which we have called the object detection class okay above Dodge detect is a method to detect the object and we want to detect the object from the frames okay and then with this code we are plotting our bounding boxes on the objects which we have detected and we have written the class names on them okay so for that you can see object colors we have mentioned above okay and with the help of this put text we are putting the text on the bounding boxes okay and finally cv2.im show will show all the frames which we have one by one with the object detected on it and with the bounding boxes and with the names okay so this is the code so now let's check this code okay so let's run it let's come out from here and my code is in python examples and then I have another folder inside that I have a folder not this one sorry let me see the folder name uh it's CD oh it's sorry my bad guys three underscore in this let's see what we have then we have cd YOLO V5 on Jetson then again we have YOLO V5 okay so now I have entered in the folder this is the GitHub repo we have installed we have cloned in the beginning okay I've entered in that over here I'll execute the command python detect our file name is detect modified this is the copy of detect dot Pi only okay but this have a code of CSI file uh CSI camera also detect modified Dot py and then we are providing the source source should be 3 because if source is three then only CSA camera will open and after that let's provide the weights because this will uh perform the detections okay okay wait file name is Yolo b5s dot PT okay now let's run it and see what we get so you can see the camera is ready so CSI camera ready true that means the camera is ready so you can see we have executed the command and now CSI camera is ready now camera will open and it will start detecting the objects so you can see the CSI camera the output is at cup and then TV and this is how it is detecting the different devices okay so this is how uh we can use CSI camera and USB camera and then rtsp streams images and videos on Jetson Nano and I hope this video is helpful thank you for watching
Info
Channel: Code With Aarohi
Views: 29,469
Rating: undefined out of 5
Keywords: Jetson, pytorch, python, opencv
Id: ZXbOV83EXdQ
Channel Id: undefined
Length: 29min 14sec (1754 seconds)
Published: Fri Jan 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.