UCS671 Embedded Vision
UCS671 Embedded Vision
Jhilik Bhattacharya
February 12, 2024
Abstract
In this course you will learn to work on the Jetson Nano kit and the Jetbot. You will learn
about Nvidia NGC docker images,how to use them and deploy different CV applications on the
kit.
1 Prerequisites
• Mandatory: Dual boot with Ubuntu
• Mandatory: Your system should have atleast 1 USB-A to attach data cable, else get a converter
(USB-C to USB-A)
• Preferred: Carry an ethernet cable
• Preferred: Carry a USB-C to USB-A cable (to be attached to your USB-A laptop port, alternative
for power plug)
1
xxxx denotes the name of the image, for example nvcr.io/nvidia/l4t − ml : r36.2.0 − py3. In the
x : y format, x represents the repository and y gives the tag name. The tag name denotes the jetpack
version number as well as the software version. The jetpack version and associated tag numbers are
shown below:
Your jetpack version is 4.6. Recall this while downloading any docker image. At this point if a question
pops in your mind- ”Whats the advantage of using docker images over conda environments? ”. Doesnt
a conda environment do a similar thing? You can create an environment, activate it and have a
list of packages(softwares) installed there. This does not clash with software versions in any other
environment. If a docker image also offers us an environment with all softwares installed, whats the
advantage of dockers over conda environment. Well the simplest answer is that docker image allows
you a OS level virtualization. You can run a linux container from windows OS if you are using dockers.
You can view the list of docker images installed on your jetson by executing
sudo docker images
For checking the list of active containers you can use
sudo docker ps
For saving any container as an image you can commit the container using
sudo docker commit container id repository:tagname
You run a docker image using
sudo docker run xxxx
where xxxx is the repository:tag for a docker image. Take a note of different options like it, rm,
network, runtime, volume, device you can use
Now that you know how to run a container, you should be able to answer the following questions
• You have connected a device to your jetson nano but cannot access it from inside a container.
Why?
• How to prevent loosing all your data saved while running the container?
2
3 Lab 1: Getting Acquainted with dockers
In this session you will try the following
• Run the docker image nvcr.io/nvidia/l4t-ml:r36.2.0-py3 and check which version of pytorch,
tensorflow, opencv, numpy are installed here
• Run the docker with rm option, install a software (say matplotlib or pillow) and exit. Run it
again and check if you are able to access the softwares
• Check whether the container you saved is still available and save an image again
• This time delete the container you are using and check if you can run the image you have saved.
Once you open this file , use the insert mode (by pressing i) to edit the file. Once you finish editing,
escape the insert mode (using escape key) and save the file using (using :wq). You can build the docker
file as an image using the docker build command
sudo docker build -t jetpose:v1 .
The name jetpose:v1 is the image repository:tag you give to the image you have created. The ”.” in
the end signifies that your docker file is in this directory. You can check that your image is built by
using the sudo docker images command.
The docker file uses the following main keywords
• FROM keyword is used to include an already existing docker image.
• RUN keyword is used to execute any shell command like pip install matplotlib
FROM nvcr.io/nvidia/l4t-pytorch:r32.6.1-pth1.9-py3
RUN pip install matplotlib
WORKDIR /home
RUN git clone https://github.com/NVIDIA-AI-IOT/torch2trt
WORKDIR /home/torch2trt
RUN python3 setup.py install –plugins
RUN pip3 install tqdm cython pycocotools
WORKDIR /home
RUN git clone https://github.com/NVIDIA-AI-IOT/trt pose
WORKDIR /home/trt pose
3
RUN python3 setup.py install
WORKDIR /home
• Replace the workdir command with run cd and build another docker image jetpose:v2. What
are the differences?
• Pull the github repos in you jetson and use the COPY command inside the docker file to copy
the folders from the jetson to the container. Do this instead of cloning inside the docker file.
Build this image as jetpose:v3.
At the end of the session you should be able to answer the following questions
• In how many ways can you create a docker image?
• What are the pros and con of using jetpose:v1 vs jetpose:v3
• Suppose you have to edit a setup file you pulled from a github repo. In how many ways can you
do it?
4
• COCO
• PascalVOC
• Cityscapes
• Bereley Driving Dataset
• CALTECH
• Openpose
• NYUDepth
While you check each dataset make sure you understand what are the labels in each cases. For example
for classification task where the entire image is labeled as a class, its just a name. For detection tasks,
annotation files in xml or txt files will be available. For segmentation or depth datasets, the label is
another image like a mask image or a depth image. For enhancement tasks, the output is also another
image known as the groundtruth. For example for a hazy dataset, the labels are clear hazefree images.
Once you have a clear understanding of different datasets and formats, its time to try the jetson in-
ference module. You can follow the steps given below:
#If you find the below entry search jetson-inference folder on your jetson device
#dustynv/jetson-inference r32.6.1 5363eb4a3327 18 months ago 2.71GB
cd jetson-inference
docker/run.sh
You will recall we discussed that the run.sh file inside the docker folder has the sudo docker run
command with all options. Instead of typing it on the terminal you can always write the command in
a sh file and just run it.
#Once inside the container for running an image classification/segmentation example
cd jetson-inference/build/aarch64/bin
./imagenet.py images/orange 0.jpg images/test/output 0.jpg #classification
./segnet.py –network=fcn-resnet18-cityscapes images/city 0.jpg images/test /output.jpg #segmenta-
tion
The test .py files are available for you in the bin directory. You can check the files to see the default
parameters. You can add options like –network if you want to work with a different network. The list
of networks can be checked from jetson-inference/data/networks folder. You can provide the input
5
image path and the path to save the output. You can view them even after exiting the container inside
the jetson-inference/data/images folder on your jetson as you had mounted them inside the container.
Inorder to view the images either open jupyter-notebook on your jetson (not container). Alternatively
you can use the following from your jetson terminal (not container)
Use the username of your laptop (not jetson) instead of my name. The image is copied from the
jetson device to your laptop desktop. Assuming that ssh works on your laptop, you are in the correct
folder in your jetson terminal (here we assume you are inside jetson-inference folder and can see images
subfolder), it will work.
For taking continuous feed from the camera (/dev/video0) and saving the output in a video file(out.mp4),
you can run any of the detection/classification/segmentation codes with
c=0
while True:
.
.
.
c+ =1
if c>1000:
break
Also, you can use the detection object to extract particular information.
This will print a message when the ClassID is 1. You can similarly extract bounding box locations
using detection.T op, detection.Bottom etc. The members of the object (i.e. ClassID, Top, Left etc)
will be visible when you print the object using print(detection). Use the saveImageRGBA function
of jetson.utils to save parts of Images extracted using the bounding box information.
6
directly used to take different decisions. If you need to maintain a repository, you may save the results
as video files. Here are a few examples of what you should be able to do:
• Can your device save images of all the people it sees. Remember only the person, not the whole
image or video.
• Can you keep a note of all the people and animals seen in a live feed
• Assume that a feed is viewing a constant scene. Can you provide a total accuracy of all the
objects viewed. For example say in 30 frames, an object was detected as cat in 20, and as a
dog in the remaining frames. So you can say that the detected object may be a cat with 66%
confidence and dog with 33% chance.
9 Lab 4:
This is a good time to have a deeper understanding of label files and format. Take a look at the
following
• object annotation in KITTI format
• object annotation in COCO format
• object annotation in PASCALVOC format
• xml and txt files for annotation
• Find 3 pose datasets and 3 depth datasets other than the one mentioned above.
10 Lecture 9,10:
In this session you will run your first code for capturing a dataset, training it and running it for infer-
ence . Upon completion, you’ll be able to create your own deep learning classification and regression
models with the Jetson Nano. These are the steps
• Set up your Jetson Nano and camera. You have already done this.
• Collect image data for classification models
• Annotate image data for regression models
• Train a neural network on your data to create your own models
• Run inference on the Jetson Nano with the models you create
• Complete the certification
Some common issues are listed here
• While running the docker-run.sh file ensure that you are using the correct image version which
is already there in your jetson device. You can check the version with sudo docker images
command
• Make sure to check that you have used the appropriate code for your 2GB device and camera
usb/csi.
• If your camera isnt working check with attached display device
• If jupyter notebook isnt working: You can open the a browser from the jetson device (not inside
container) using the command chromium-browser. Use another new terminal in your laptop
to connect to the jetson again via ssh as chromium is running from the previous one. Once
connected run the container and open jupyter inside the container using jupyter notebook
–allow-root –no-browser. Once jupyter starts running, copy the ip (you will find that on the
second last line) and paste on the chromium browser you opened. Type the password and login.
7
11 Lab 5
In this session you will get familiar with theTransfer Learning Toolkit. Go through the CV Model
Zoo already available in details taking into consideration the training algorithm and use cases. Almost
all models mention Pruning aware training mechanisms. Its time that we step into model optimization
techniques using pruning aware, quantization aware tools paving way for TensorRT optimization tool.
A summary of popular pruning criterias and tools are provided here.