Β§2024-12-05
To prepare the NVIDIA Jetson Orin Nano development board for coding with PyTorch, you'll need to go through several steps to ensure that the necessary software and libraries are installed and configured correctly. Here's a step-by-step guide to get you started:
Prerequisites: Jetson Orin Nano development board with Ubuntu-based Jetson OS (like JetPack). A monitor, keyboard, and mouse connected to the Jetson Orin Nano. An internet connection for downloading required packages and dependencies. Step-by-Step Guide:
Download SDK Manager from NVIDIA's Developer Site. Follow the Setup Instructions to flash your Jetson Orin Nano. Once flashing is complete, boot up your device.
bash γ³γΌγγγ³γγΌγγ
cat /etc/nv_tegra_release
lsb_release -a 3. Update System Packages Itβs important to keep your system updated before proceeding with the installation of libraries.
bash γ³γΌγγγ³γγΌγγ sudo apt update sudo apt upgrade sudo apt dist-upgrade 4. Install Required Dependencies PyTorch on Jetson requires several dependencies, including Python, pip, CUDA, and cuDNN. Since Jetson devices come with CUDA and cuDNN as part of JetPack, you typically don't need to install them manually. However, there are a few additional packages you'll need.
First, make sure Python 3 and pip are installed (they should be by default):
bash γ³γΌγγγ³γγΌγγ sudo apt install python3 python3-pip python3-dev Additionally, install some necessary build tools:
bash γ³γΌγγγ³γγΌγγ sudo apt install build-essential cmake git 5. Install PyTorch for Jetson PyTorch needs to be installed with specific optimizations for the Jetson architecture. NVIDIA provides pre-built PyTorch wheels for the Jetson platform, so weβll use those instead of building from source (which can be time-consuming).
To install PyTorch on Jetson:
Install NVIDIA's PyTorch Wheel: Go to NVIDIA's PyTorch page for Jetson to find the correct wheel for your version of JetPack (make sure it matches your CUDA version).
Example Command for Installing PyTorch: For example, if you're using JetPack 5.x with CUDA 11.4, you might run:
bash γ³γΌγγγ³γγΌγγ sudo pip3 install torch-2.x.x-cp36-cp36m-linux_aarch64.whl You can download the correct wheel file from NVIDIAβs site. Make sure you download the wheel that corresponds to your exact version of JetPack.
Install torchvision (optional but recommended for computer vision tasks): To install the torchvision library, use the following command (assuming your PyTorch version is compatible):
bash γ³γΌγγγ³γγΌγγ sudo pip3 install torchvision Install other dependencies for PyTorch: If you want additional functionality, such as support for specific deep learning models or other machine learning libraries, you might want to install additional libraries like scipy, numpy, etc.
bash γ³γΌγγγ³γγΌγγ sudo pip3 install numpy scipy matplotlib 6. Verify PyTorch Installation After installation is complete, verify that PyTorch is installed correctly by opening a Python shell and testing PyTorch:
bash γ³γΌγγγ³γγΌγγ python3 Then, run the following commands inside the Python shell:
python γ³γΌγγγ³γγΌγγ import torch print(torch.version) print(torch.cuda.is_available()) torch.version will print the installed version of PyTorch. torch.cuda.is_available() should return True if PyTorch can detect the CUDA-enabled GPU on your Jetson device. 7. Test a Simple PyTorch Model (Optional) To confirm everything is working, try running a simple model:
python γ³γΌγγγ³γγΌγγ import torch import torch.nn as nn import torch.optim as optim
model = nn.Linear(10, 5).cuda()
input_data = torch.randn(1, 10).cuda() target = torch.randn(1, 5).cuda()
criterion = nn.MSELoss() optimizer = optim.SGD(model.parameters(), lr=0.01)
output = model(input_data) loss = criterion(output, target) print(f'Loss: {loss.item()}') If this runs without errors, you're all set to start working with PyTorch on your Jetson Orin Nano!
bash γ³γΌγγγ³γγΌγγ sudo apt install python3-notebook sudo pip3 install jupyter Start Jupyter with the following command:
bash γ³γΌγγγ³γγΌγγ jupyter notebook Access it via your browser at http://<Jetson_IP>:8888.