NVIDIA-AI-IOT / jetbot

An educational AI robot based on NVIDIA Jetson Nano.
MIT License
3k stars 1.02k forks source link

Camera freezes on Jetson Nano 2GB in collision avoidance demo #529

Closed thelateperseus closed 2 years ago

thelateperseus commented 2 years ago

I am using the SparkFun JetBot AI Kit v3.0 (Without Jetson Nano) with a Jetson Nano 2GB I bought separately. I downloaded the sparkfun_2GB_jetbot_v00-02_linux.zip image and wrote this to the provided SD card. I followed the SparkFun assembly and setup guide and got the basic motion and teleoperation examples working without issue.

However, the camera freezes when inference starts in the collision avoidance "live_demo.ipynb" example. I found a related thread on the Nvidia forum Rpi v2 CSI camera freezes with Jetson Nano 2GB, and it seems that this is a common problem with the 2GB Nano. I fixed the issue by adding 6GB swap space, reducing other memory usage, then allocating 8G swap space to the jetbot_jupyter container:

# Disable ZRAM:
sudo systemctl disable nvzramconfig

# Prevent X-Server from starting:
sudo systemctl set-default multi-user.target

# Create additional 6GB swap file
sudo fallocate -l 6G /mnt/6GB.swap
sudo chmod 600 /mnt/6GB.swap
sudo mkswap /mnt/6GB.swap

# Append the following line to /etc/fstab
sudo su
echo "/mnt/6GB.swap swap swap defaults 0 0" >> /etc/fstab
exit

# REBOOT

# Check swap space
free -h

cd jetbot/docker
./disable.sh

# Edit configure.sh to change export JETBOT_JUPYTER_MEMORY_SWAP from 3G to 8G
# Edit enable.sh to comment out ./display/enable.sh since the display takes up extra memory for little benefit

./enable.sh

Given that this is a common issue with 2GB Nanos with CSI cameras, I think that the default Jetbot configuration should set 8G of swap space on the jetbot_jupyter container instead of 3G.

@santaimpersonator fyi in case you want to update the SparkFun image.

santaimpersonator commented 2 years ago

@thelateperseus Thanks for tagging me on this. I'll have to take a look and test it out.

Increasing the size of the swap space makes sense. We usually recommend that users disable the GUI to free up enough memory to get that example working. My only hesitation with this method, is that it increases the number of read/write cycles to the SD card and therefore, it also increases the chances of corrupting the SD card.

If possible, maybe an alternative would be to modify the swap file size only while the example is running. Though, I'd have to read up more on Docker containers.