Getting started in AI and computer vision with Nvidia Jetson Nano. Hands-on approach to the JetBot project | by David Retana | Towards Data Science

With the rise of AI and IoT, Nvidia offers us a simple, cheap and powerful solution for the development of embedded artificial intelligence applications. Jetson Nano opens up opportunities to create homemade robots, intelligent systems...
Jetson Nano is a raspberry like board but much more powerful which runs a custom Ubuntu image with preloaded Nvidia software. It has a Quad-core ARM® Cortex®-A57 MPCore processor, NVIDIA MaxwellTM architecture GPU with 128 NVIDIA CUDA® cores and 4 GB 64-bit LPDDR4 1600MHz memory. This hardware makes the Jetson Nano suitable for training and inference phases in deep learning problems. It supports most common deep learning frameworks like TensorFlow, Caffe or PyTorch.
With this board, you can make an educational AI robot called JetBot. Building and using JetBot gives the hands on experience needed to create entirely new AI projects, including hardware and software phases. Building JetBot is not the goal of this article. In the official GitHub page you can find all the information and requirements. https://github.com/NVIDIA-AI-IOT/jetbot
With Jetson Nano board you can easily run majority of deep learning frameworks like TensorFlow, Caffe or PyTorch in a efficient way.
All the necessary code to run this project is available on JetBot GitHub page mentioned above. However, you can take advantage of my modified notebook with improvements like taking pictures dynamically whereas moving your JetBot remotely with a Xbox controller (easy extensible to other controllers).
Step 1.- Collect data to feed your model
https://github.com/davidRetana/jetbot/blob/davidretana/notebooks/collision_avoidance/data_collection_teleoperation.ipynb
In order to train our neural network, we need to collect images from the camera. We need two kind of images: blocked and free. Take care of collect images from the 2 classes in a balanced way (50–50 %) and try different positions of the same blocking object or clear path. A good dataset is the key to the robot’s proper functioning.
If the path is blocked, the JetBot will turn left and on the contrary if the path is clear, the JetBot will continue straight.
Step 2: Train the network
https://github.com/davidRetana/jetbot/blob/davidretana/notebooks/collision_avoidance/train_model.ipynb
The network architecture chosen from this job is AlexNet but with a slightly modification to accomplish our requirements.
This architecture was designed to ImageNet LSVRC-2010 contest with 1000 different classes. However, our network only need to distinguish if a image is free or blocked to move the JetBot through so the final layer will only have 2 outputs. Moreover, PyTorch allows us to download a pretrained AlexNet network which is a huge advantage to solve our problem because in the training phase, we don’t need to start the network weights randomly. The layers have the knowledge learned with the 1000 different classes in ImageNet LSVRC-2010 contest. A model developed for a task is reused as the starting point for a model to accomplish a different task. This technique is called Transfer Learning.
import torchimport torchvision.models as modelsmodel = models.alexnet(pretrained=True)model.classifier[6] = torch.nn.Linear(model.classifier[6].in_features, 2)print(model)
You can train the network in the JetBot itself or in a external system. The notebook in prepared to export your model’s weights in a file that you can import in the JetBot later.
Step 3: Run your model
https://github.com/davidRetana/jetbot/blob/davidretana/notebooks/collision_avoidance/live_demo.ipynb
Now, it’s time to run your model and see how it works.