首页 > 其他分享 >orin上安装cuda pytorch gpu运行环境

orin上安装cuda pytorch gpu运行环境

时间:2023-06-08 18:35:28浏览次数:51  
标签:torch torchvision py pytorch cuda orin jk home local



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

orin上安装cuda pytorch gpu运行环境_pytorch

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__

orin上安装cuda pytorch gpu运行环境_YOLO_02

可能遇到的错误

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 版本不匹配

orin上安装cuda pytorch gpu运行环境_v8_03


但是我打印出来,版本没有问题

orin上安装cuda pytorch gpu运行环境_YOLO_02

最终卸载重装了一下,

pip uninstall torch 
pip uninstall torchvision
pip uninstall torchaudio

多卸载几次

pip uninstall torch 
pip uninstall torchvision
pip uninstall torchaudio

其实卸载的过程中,我发现torchvision有多个版本,很可能是这个原因造成的。

然后按照步骤3重新来一次(重新安装很快)

运行成功。


标签:torch,torchvision,py,pytorch,cuda,orin,jk,home,local
From: https://blog.51cto.com/u_15316847/6442177

相关文章

  • 显卡,CPU,GPU和CUDA的关系与区别
    (1)显卡:显卡全称显示接口卡,又称显示适配器,是计算机最基本配置、最重要的配件之一。就像电脑联网需要网卡,主机里的数据要显示在屏幕上就需要显卡。因此,显卡是电脑进行数模信号转换的设备,承担输出显示图形的任务。具体来说,显卡接在电脑主板上,它将电脑的数字信号转换成模拟信号让显示器......
  • Pytorch
    Pytorch张量直接张量创建依据数值创建依据概率创建拼接切分索引变换四则运算自动求导数据如何读取你自己的数据集?如何图像数据预处理及数据增强?模型如何构建神经网络?如何初始化参数?损失函数如何选择损失函数?如何设置损失函数?优化器如何管理参数?如何调整学习率?迭代过程:如何观察训练......
  • 从0开始学pytorch【4】--维度变换、拼接与拆分
    从0开始学pytorch【4】--维度变换、拼接与拆分学习内容:维度变换:张量拆分与拼接:小结学习内容:维度变换、张量拆分与拼接维度变换:1、viewimporttorcha=torch.rand(4,1,28,28)print(a.shape)print(a.view(4,28*28))print(a.shape)b=a.view(4,28,-1)b.view(4,28,28,-1......
  • 从0开始学pytorch【3】--张量数据类型
    从0开始学pytorch【3】--张量数据类型前言学习目标基本数据类型创建tensor索引、切片小结前言  在前两篇博文中,从0开始学pytorch【1】–线性函数的梯度下降、从0开始学pytorch【2】——手写数字集案例中介绍了人工智能入门最为基础的梯度下降算法实现,以及机器学习、深度网络编......
  • cuda+cudann+tensorflow安装日记
    1、确定自己电脑有GPU:设置---系统---系统信息---设备管理器---显示适配器,例如:我有,型号是"NVIDIAGeForceRTX3060LaptopGPU"2、(超级重要)确定自己CUDA、CUDANN、tensorflow的安装版本:先确定自己电脑最高能装的最高CUDA版本,然后上官网找其他两个对应的版本CUDA:win+r---cmd---指......
  • 使用Optuna进行PyTorch模型的超参数调优
    前言 Optuna是一个开源的超参数优化框架,Optuna与框架无关,可以在任何机器学习或深度学习框架中使用它。本文将以表格数据为例,使用Optuna对PyTorch模型进行超参数调优。本文转载自DeepHubIMBA仅用于学术分享,若侵权请联系删除欢迎关注公众号CV技术指南,专注于计算机视觉的技术总......
  • yolov5项目cuda错误解决
    CUDA报错解决#报错详情AssertionError:CUDAunavailable,invaliddevice0requested查看cuda版本先看一下电脑是否支持GPU,打开任务管理器就能查看(ctrl+shift+esc)#cmd命令nvcc--version#如果上面命令不是内部或外部命令,也不是可运行的程序,就输入下面的命令NVIDIA-......
  • AssertionError CUDA unavailable, invalid device 0 requested
    报错信息UserWarning:Userprovideddevice_typeof'cuda',butCUDAisnotavailable.Disablingwarnings.warn('Userprovideddevice_typeof\'cuda\',butCUDAisnotavailable.Disabling')AssertionError:CUDAunavailable,inv......
  • pytorch 的 torchvision.datasets.ImageFolder 来自定义数据集
    importtorchvisionclassClassificationDataset(torchvision.datasets.ImageFolder): """ YOLOv5ClassificationDataset. Arguments root:Datasetpath """ def__init__(self,root): super().__init__(root=root)#调用了父类的......
  • Pytorch中张量的连续性:contiguous
    根据PyTorch文档¹,t.contiguous()返回一个包含与t张量相同数据的连续张量。如果t张量已经是连续的,这个函数返回t张量本身。一个张量是连续的,如果张量中的相邻元素在内存中实际上是相邻的³。有些对张量的操作,例如transpose(),permute(),view()和narrow(),不改变张量的内容,但改变数......