Skip to content

Robotics-CSE-571/dt-machine-learning-base-environment

 
 

Repository files navigation

⚠️ We found out that running pytorch on Jetson 2GB is very memroy intensive and the Jetson hangs with all of its memory consumed. But still you can use this repo to run the pytorch node on laptop or workstation that communicates with the roscore on the robot. Read more about it below.

Template for DNN with duckiebot and a template ROS Node

This is based on this repo from the duckiebot.

I recommend to run this image on your laptop/workstation with GPU since building it on Jetson is really time consuming.

nvidia requirements to run the image on laptop or workstation

If you want to use GPU on your laptop/workstation, you need to first install nvidia docker runtime as described on this page on your laptop/workstation.

Of course you need to have the nvidia driver for linux first. I do not recommend anything on how to get it or download it. Since it is kind of difficult for ubuntu 16.04 but they made it super easy for ubuntu 20.04 which they can be installed from apt.

If you want to run the image on your laptop/workstaion follow these, Otherwise you can skip it.

sudo apt-get install nvidia-container-runtime

and then run the following

sudo tee /etc/docker/daemon.json <<EOF
{
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}
EOF
sudo pkill -SIGHUP dockerd

Now you have the nvidia runtime available. You can test it with

docker run --rm --runtime=nvidia  nvidia/cuda:11.0-base nvidia-smi

Which should list your GPU devices which is available within the docker image. Otherwise there is some issue in your setup.

Build and run the image on Laptop

It is going to be relatively time consuming

dts devel build  -f

To run the image on laptop or workstaion, change the robot name and ip according to yours.

ROBOT_NAME="yousofsduckie"
ROBOT_IP="${ROBOT_NAME}.local"
dts devel run -f --net host -- -e ROS_MASTER_URI=http://${ROBOT_IP}:11311 -e VEHICLE_NAME=${ROBOT_NAME} --runtime nvidia

Build and run the image for Jetson

Note building the image for Jetson is taking very long time but the nvidia runtime stuff should be already available on jetson and no extra requirements are need.

To build the image for Jetson

ROBOT_NAME="yousofsduckie"
dts devel build -f -H ${ROBOT_NAME}.local --ncpus 4

To run the image on Jetson

dts devel run -H ${ROBOT_NAME}.local

Test

The current version should print somewhere in the terminal as the following

torch is imported successfully
cuda available? True

Troubleshooting

"Not enough space" on Jetson during building the image

run the following to delete the dangling images.

docker -H ${ROBOT_NAME}.local image prune

Run docker -H ${ROBOT_NAME}.local image ls and see all the images. You can remove the previous images that you built and you do not need for example for previous project

to remove an image:

docker -H ${ROBOT_NAME}.local image rm <image-name>:<image-tag>

# for example
docker -H ${ROBOT_NAME}.local image rm duckietown/cse571-sp21-project-1:main-arm64v8

Template ROS Node

You can find the template ROS node that imports pytorch in packages/my_dnn/src/my_dnn_node.py.

About

Docker image for a base image containing machine learning tools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 79.0%
  • Dockerfile 10.0%
  • Shell 9.2%
  • CMake 1.3%
  • Makefile 0.5%