Jetson环境安装(一):Ubuntu18.04安装pytorch、opencv、onnx、tensorflow、setuptools、pycuda....

简介: 本文提供了在Ubuntu 18.04操作系统的NVIDIA Jetson平台上安装深度学习和计算机视觉相关库的详细步骤,包括PyTorch、OpenCV、ONNX、TensorFlow等。

1.安装pytorch

  • 对于安装pytorch你要结合你的cuda的版本,以及你的python版本,由于我是jetson nano的平台,所以安装的时候要注意有aarch64的后缀,pytorch就是蛮难下下来的,需要你翻墙才能下载,下面我会给出相应的pytorch的腾讯微云分享版本

这是全部的下载链接,直接找对应下载:
https://elinux.org/Jetson_Zoo#PyTorch_.28Caffe2.29

首先给出下载pytorch的代码,如果运行不起就直接https://nvidia.box.com/shared/static/j2dn48btaxosqp0zremqqm8pjelriyvs.whl

wget https://nvidia.box.com/shared/static/j2dn48btaxosqp0zremqqm8pjelriyvs.whl -O torch-1.6.0-cp36-cp36m-linux_aarch64.whl

sudo pip3 install torch-1.6.0-cp36-cp36m-linux_aarch64.whl
  • ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
  • solve: sudo apt-get install libopenblas-dev
  • OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory
  • solve:
    在这里插入图片描述

安装完了之后就可以通过下面的这个验证

import torch
print(torch.__version__)
print('CUDA available: ' + str(torch.cuda.is_available()))
a = torch.cuda.FloatTensor(2).zero_()
print('Tensor a = ' + str(a))
b = torch.randn(2).cuda()
print('Tensor b = ' + str(b))
c = a + b
print('Tensor c = ' + str(c))

2.安装torchvision

在这里插入图片描述

# 安装一些必要的依赖包
sudo apt-get install libjpeg-dev zlib1g-dev

# 下载torchvision
git clone --branch v0.7.0 https://gitee.com/zero-one-game/vision torchvision   

# 安装torchvision
cd torchvision
sudo python3 setup.py install
# OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory  ->>>>sudo apt-get install libopenmpi2
cd ../
pip3 install 'pillow<7'
  • error: command ‘aarch64-linux-gnu-gcc‘ failed with exit status 1
  • way1: sudo apt-get install python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
  • way2: if has ffmpeg 改为if False即可

用以下代码测试是否成功

import torchvision

print(torchvision.__version__)

在Jetson Xavier NX上安装torchvision编译报错:fatal error: libavcodec/avcodec.h: No such file or directory
look at the authou csdn

3.安装opencv-python(自带有)

一条命令直接搞定

sudo apt-get install python3-opencv

通过终端验证直接通过

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>

若要删除用sudo apt-get remove python3-opencv

4.安装onnx/onnxruntime

  • 先安装onnx的环境依赖
    sudo apt-get install protobuf-compiler libprotoc-dev
  • 再安装onnx为1.9.0的版本
    pip install onnx1.9.0
    pip3 install onnxruntime1.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
  Created wheel for onnx: filename=onnx-1.4.1-cp36-cp36m-linux_aarch64.whl size=3646291 sha256=3632a794d71e5c744920b2abf7626a4fd3ca39b7ea47a85e7cb9f3a7c325dbf7
  Stored in directory: /home/lqs/.cache/pip/wheels/45/d1/9f/9508c4176d79c0373629eff6cf2645e2dcbfb291bbe9dc2f8a
Successfully built onnx
Installing collected packages: onnx
Successfully installed onnx-1.4.1

5.安装tensorflow-gpu

if your platform is jetson xavier nx,I think you should see the offcial word,the website is :https://forums.developer.nvidia.com/t/official-tensorflow-for-jetson-agx-xavier/65523

jetson nano look at here

1.sudo apt install python3-pip python3-dev
2.python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
#使用下述指令可以更改python镜像源为清华pypi镜像源
3.pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4.#安装机器学习常用包 
sudo apt install python3-scipy -y
sudo apt install python3-pandas -y
sudo apt install python3-sklearn -y
sudo apt install python3-seaborn -y
sudo pip install cython
上述指令会自动安装numpy和matplotlib等依赖包
5.
sudo apt-get update
sudo apt install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
6.#安装Python依赖包
sudo pip3 install -U numpy==1.16.1 future==0.18.2 mock==3.0.5 h5py==2.10.0 keras_preprocessing==1.1.1 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11 astor
7.#download tensorflow https://developer.download.nvidia.com/compute/redist/jp/v45 
pip3 install tensorflow-1.15.5+nv21.4-cp36-cp36m-linux_aarch64.whl --user
8.test
import tensorflow as tf
# 输出提示:
# 2020-10-11 15:25:36.253267: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2

a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
# 输出结果:
# tf.Tensor(3.0, shape=(), dtype=float32)

print('GPU:', tf.test.is_gpu_available())
# 输出最后一句为:
# GPU: True
#this is NV
pip3 install tensorflow-1.15.5+nv21.3-cp36-cp36m-linux_aarch64.whl 
# jetson xavier nx  jetpack 4.5.2 cuda 10.2
  • 验证
    在这里插入图片描述

6.安装setuptools

pip install --no-cache-dir setuptools==20.7.0 -i https://pypi.doubanio.com/simple/
#下面是升级 
pip install --ignore-installed  setuptools

7.安装Pycuda

下载地址
https://files.pythonhosted.org/packages/5e/3f/5658c38579b41866ba21ee1b5020b8225cec86fe717e4b1c5c972de0a33c/pycuda-2019.1.2.tar.gz

tar zxvf pycuda-2019.1.2.tar.gz    
cd pycuda-2019.1.2/  
python3 configure.py --cuda-root=/usr/local/cuda-10.2
sudo python3 setup.py install
  • 若报错FileNotFoundError: [Errno 2] No such file or directory: ‘nvcc’
  • 打开Pycuda的compiler.py文件中的compile_plain()
    中,大约在第 73 行的位置中加入下面段代码!
    在这里插入图片描述

8. 安装Cmake

wget http://www.cmake.org/files/v3.13/cmake-3.13.0.tar.gz
tar xpvf cmake-3.13.0.tar.gz cmake-3.13.0/  
cd cmake-3.13.0/
./bootstrap --system-curl    
make -j4 
echo 'export PATH=/home/z/Downloads/cmake-3.13.0/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc

9. 安装matplotlib

sudo apt-get install python3-matplotlib

10. 安装pyqt5

sudo apt install pyqt5*
sudo apt-get install python3-pyqt5
相关实践学习
在云上部署ChatGLM2-6B大模型(GPU版)
ChatGLM2-6B是由智谱AI及清华KEG实验室于2023年6月发布的中英双语对话开源大模型。通过本实验,可以学习如何配置AIGC开发环境,如何部署ChatGLM2-6B大模型。
目录
相关文章
|
5月前
|
Ubuntu 安全 iOS开发
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
698 5
|
5月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 22.04上安装MongoDB 6.0的步骤
这些步骤应该可以在Ubuntu 22.04系统上安装MongoDB 6.0。安装过程中,如果遇到任何问题,可以查阅MongoDB的官方文档或者Ubuntu的相关帮助文档,这些资源通常提供了解决特定问题的详细指导。
601 18
|
6月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
409 18
|
6月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
478 15
|
6月前
|
存储 Ubuntu iOS开发
在Ubuntu 22.04系统上安装libimobiledevice的步骤
为了获取更多功能或者解决可能出现问题,请参考官方文档或者社区提供支持。
624 14
|
6月前
|
Ubuntu 安全 关系型数据库
安装与配置MySQL 8 on Ubuntu,包括权限授予、数据库备份及远程连接指南
以上步骤提供了在Ubuntu上从头开始设置、配置、授权、备份及恢复一个基础但完整的MySQL环境所需知识点。
720 7
|
6月前
|
消息中间件 人工智能 运维
Ubuntu环境下的 RabbitMQ 安装与配置详细教程
本文聚焦在Ubuntu下RabbitMQ安装与配置教程,旨在帮助读者快速构建稳定可用的消息队列服务。
1242 6
|
机器学习/深度学习 人工智能 算法
猫狗宠物识别系统Python+TensorFlow+人工智能+深度学习+卷积网络算法
宠物识别系统使用Python和TensorFlow搭建卷积神经网络,基于37种常见猫狗数据集训练高精度模型,并保存为h5格式。通过Django框架搭建Web平台,用户上传宠物图片即可识别其名称,提供便捷的宠物识别服务。
1263 55
|
机器学习/深度学习 人工智能 算法
鸟类识别系统Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+ResNet50算法模型+图像识别
鸟类识别系统。本系统采用Python作为主要开发语言,通过使用加利福利亚大学开源的200种鸟类图像作为数据集。使用TensorFlow搭建ResNet50卷积神经网络算法模型,然后进行模型的迭代训练,得到一个识别精度较高的模型,然后在保存为本地的H5格式文件。在使用Django开发Web网页端操作界面,实现用户上传一张鸟类图像,识别其名称。
735 12
鸟类识别系统Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+ResNet50算法模型+图像识别
|
机器学习/深度学习 数据采集 数据可视化
TensorFlow,一款由谷歌开发的开源深度学习框架,详细讲解了使用 TensorFlow 构建深度学习模型的步骤
本文介绍了 TensorFlow,一款由谷歌开发的开源深度学习框架,详细讲解了使用 TensorFlow 构建深度学习模型的步骤,包括数据准备、模型定义、损失函数与优化器选择、模型训练与评估、模型保存与部署,并展示了构建全连接神经网络的具体示例。此外,还探讨了 TensorFlow 的高级特性,如自动微分、模型可视化和分布式训练,以及其在未来的发展前景。
1110 5