https://blog.csdn.net/Black__Jacket/article/details/127736938
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
https://blog.csdn.net/beautifulback/article/details/125717717
1. Reinstall jetpack first
2. Check if there is /usr/local/cuda-11.4
jetson nano Check CUDA version: nvcc -V Error: bash: nvcc: command not found
At this time, switch to the ~ directory: cd ~;
then open the .bashrc file: vim .bashrc;
then press the i key to enter the editing state;
then add the following three lines of code at the end of the file:
export PATH=/usr/local/cuda-11.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH
export CUDA_ROOT=/usr/local/cuda-11.4
Then, press the Esc key, enter a colon, and then press wq! (which means force writing and exit)!
The last step is also a step that is easy to forget. Be sure to source this file:
source .bashrc
After everything above is OK, enter nvcc again and you can see the CUDA version information in the system:
3. Install torch 1.13.0 GPU version and torchvision
Install pytorch
jetson orin pytorch version download address
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
pip3 install Cython
pip3 install numpy torch-1.13.0-cp38-cp38-linux_aarch64.whl
b. Install torchvison
torchvision download URL:
https://github.com/pytorch/vision
Select main–>Tags 1.14.0 to download and unzip.
cd torchvision
export BUILD_VERSION=0.14.0
python3 setup.py install --user
cd ../
pip install 'pillow<7'
View version
python
import torch
import torchvision
torch.__version__
torchvision.__version__
Possible errors
RuntimeError: Couldn’t load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible
The specific error information is as follows
jk@jk-desktop:~/Desktop/work/python_project/yolov8_tracking$ python examples/track.py --source /home/jk/Desktop/work/python_project/yolov8_tracking/test_1.mp4 --tracking-method deepocsort --yolo-model /home/jk/Desktop/work/python_project/yolov8_tracking/yolov8/ultralytics/weights/yolov8s.pt
/home/jk/.local/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")
track: yolo_model=/home/jk/Desktop/work/python_project/yolov8_tracking/yolov8/ultralytics/weights/yolov8s.pt, reid_model=/home/jk/Desktop/work/python_project/yolov8_tracking/examples/weights/lmbn_n_cuhk03_d.pt, tracking_method=deepocsort, source=/home/jk/Desktop/work/python_project/yolov8_tracking/test_1.mp4, imgsz=[640], conf=0.5, device=, show=False, save=False, classes=None, project=/home/jk/Desktop/work/python_project/yolov8_tracking/runs/track, name=exp, exist_ok=False, half=False, vid_stride=1, hide_label=False, hide_conf=False, save_txt=False
/home/jk/.local/lib/python3.8/site-packages/examples/weights
/home/jk/.local/lib/python3.8/site-packages/examples
add by xxx = osnet_x1_0_imagenet.pth
add by xxxx cached_file= /home/jk/.cache/torch/checkpoints/osnet_x1_0_imagenet.pth
Successfully loaded imagenet pretrained weights from "/home/jk/.cache/torch/checkpoints/osnet_x1_0_imagenet.pth"
Traceback (most recent call last):
File "examples/track.py", line 246, in <module>
main(opt)
File "examples/track.py", line 241, in main
run(vars(opt))
File "/home/jk/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "examples/track.py", line 114, in run
predictor.results = predictor.postprocess(preds, im, im0s)
File "/home/jk/.local/lib/python3.8/site-packages/ultralytics/yolo/v8/detect/predict.py", line 14, in postprocess
preds = ops.non_max_suppression(preds,
File "/home/jk/.local/lib/python3.8/site-packages/ultralytics/yolo/utils/ops.py", line 246, in non_max_suppression
i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS
File "/home/jk/.local/lib/python3.8/site-packages/torchvision/ops/boxes.py", line 40, in nms
_assert_has_ops()
File "/home/jk/.local/lib/python3.8/site-packages/torchvision/extension.py", line 48, in _assert_has_ops
raise RuntimeError(
RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
PyTorch and torchvision versions do not match,
but I printed it out and there is no problem with the version.
Finally uninstalled and reinstalled.
pip uninstall torch
pip uninstall torchvision
pip uninstall torchaudio
Uninstall several times
pip uninstall torch
pip uninstall torchvision
pip uninstall torchaudio
In fact, during the uninstallation process, I found that there are multiple versions of torchvision, which is probably caused by this reason.
Then follow step 3 and try again (reinstallation is quick)
Run successfully.