https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
一、先重新装 jetpack
【Jetson Agx Orin】执行sudo apt install nvidia-jetpack命令时报错:E: Unable to locate package nvidia-jetpack
二、查看是否有/usr/local/cuda-11.4
jetson nano 查看 CUDA 版本:nvcc -V 报错:bash: nvcc: 未找到命令
此时切换到 ~ 目录下: cd ~ ;
然后打开 .bashrc 文件:vim .bashrc ;
接着按 i 键,进入编辑状态;
再接着在文件的末尾添加下面三行代码:
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
紧接着,按 Esc 键,然后输入冒号 ,再按下 wq! (表示强制写入并退出)!
最后一步,也是容易忘记的一步,一定要 source 一下这个文件:
source .bashrc
上面的一切都操作OK后,再次输入 nvcc ,就可以看到系统中 CUDA 的版本信息了:
三、安装torch 1.13.0 GPU版本和torchvision
安装pytorch
jetson orin上的pytorch版本下载地址
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.安装torchvison
torchvision下载网址:
https://github.com/pytorch/vision
选择main–>Tags 1.14.0 下载并解压。
cd torchvision
export BUILD_VERSION=0.14.0
python3 setup.py install --user
cd ../
pip install 'pillow<7'
查看版本
python
import torch
import torchvision
torch.__version__
torchvision.__version__
可能遇到的错误
RuntimeError: Couldn’t load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible
报错具体信息如下
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 版本不匹配
但是我打印出来,版本没有问题
最终卸载重装了一下,
pip uninstall torch
pip uninstall torchvision
pip uninstall torchaudio
多卸载几次
pip uninstall torch
pip uninstall torchvision
pip uninstall torchaudio
其实卸载的过程中,我发现torchvision有多个版本,很可能是这个原因造成的。
然后按照步骤3重新来一次(重新安装很快)
运行成功。