To use Dlib with the power of the GPU on the Jetson Nano, you need to ensure that Dlib is compiled with CUDA support. Here are the detailed steps to install and use Dlib with CUDA on the Jetson Nano:
- Install Necessary Packages
First, you need to install the required software packages:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake
sudo apt-get install libopenblas-dev liblapack-dev
sudo apt-get install libx11-dev libgtk-3-dev
sudo apt-get install libboost-python-dev
- Install CUDA and cuDNN
The Jetson Nano typically comes with CUDA and cuDNN pre-installed. You can check the current CUDA version with the following command:
nvcc --version
This command will display the version of CUDA installed on your Jetson Nano. If CUDA and cuDNN are not installed, follow NVIDIA's official JetPack installation guide to install them. JetPack includes both CUDA and cuDNN.
- Download and compile Dlib with CUDA
Download Dlib from GitHub:
git clone https://github.com/davisking/dlib.git
cd dlib
# Create build directory and configure CMake with CUDA support:
mkdir build
cd build
cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
# Compile Dlib
cmake --build . --config Release
sudo make install
sudo ldconfig
- Install Dlib Python API
cd ..
python3 setup.py install
- Test Dlib installation with CUDA
Run the following Python code to check if Dlib supports CUDA:
import dlib
# Check if Dlib is compiled with CUDA or not
print("DLIB_USE_CUDA:", dlib.DLIB_USE_CUDA)
# Check the number of CUDA devices
print("Number of CUDA devices:", dlib.cuda.get_num_devices())
# Check if CUDA is active or not
if dlib.DLIB_USE_CUDA and dlib.cuda.get_num_devices() > 0:
print("CUDA is enabled and available")
else:
print("CUDA is not enabled or no CUDA devices found")