LaneNet on NVIDIA Jetson
January 9, 2021
LaneNet is a real-time deep neural network model used for lane detection. An unofficial implementation for TensorFlow is available at this GitHub repo, which runs really well on a PC. However, I wanted to get this running on the NVIDIA Jetson platform, which is a suite of products made for low-power edge AI. I first targeted the Xavier NX, which offers more compute & power than the entry-level Nano, knowing that this is a pretty intensive task.
From TensorFlow to TensorRT
Unfortunately, running the TensorFlow model out of the box resulted in memory & performance issues on the Xavier NX. NVIDIA offers TensorRT to speed up inference on their platforms, so the next major step was to port the TensorFlow model to TensorRT. This forked repo contains additional files, as well as a
Dockerfile with all the necessary dependencies to run this on the Xavier NX.
Starting with TensorRT 7.0, the preferred method is to use the ONNX workflow, where a TensorFlow model is converted to the ONNX format, which is then used to build the TensorRT engine. Other frameworks are also supported, e.g. PyTorch, Keras, & Caffe.
Freezing the TensorFlow graph
The first step requires freezing the TensorFlow graph. The Python script to do this can be found at
To run it:
This creates a frozen graph called
model/lanenet.pb. The next step is to convert this to ONNX using the tf2onnx Python package:
This takes the
.pb file and converts it to an ONNX model, which is saved as
Running inference with TensorRT
Using the ONNX model, we can now run inference! The Python script can be found at
To run it with a sample video file:
This can also run with a live video stream if a webcam or camera is connected to the Xavier NX. Just update the
--video_src flag with the appropriate name for the connected video source.
You can check out this video to see it in action!
With a little bit of work to convert a TensorFlow model to TensorRT, we can now run real-time lane detection on the NVIDIA Jetson Xavier NX. Next steps are to try this on the entry-level Nano.