当前位置:网站首页>Jetson TX2配置Tensorflow、Pytorch等常用库
Jetson TX2配置Tensorflow、Pytorch等常用库
2022-07-04 12:33:00 【竹叶青lvye】
之前在PC Ubuntu或者树莓派上都配置过,方法不变,所以此篇博客会简单记录下过程,详细的一些方法思路可以去参考博主之前的系列博客(虽然硬件平台不一样,但方法大体一致的。硬件平台主流的有树莓派,NVIDIA Jetson,Google的Coral Dev Board等。授人以鱼不如授人以渔,我们重点的是学方法,以不变应万变。前面系列博客里从常用库的配置,深度学习的推断,如何交叉编译都做了一些详细的实验和阐述,这些思路和习惯都可以沿用到新的嵌入式平台上)
https://blog.csdn.net/jiugeshao/category_11391557.html?spm=1001.2014.3001.5482
https://blog.csdn.net/jiugeshao/category_11447160.html?spm=1001.2014.3001.5482
对于Jetson TX2的初始环境配置可见此前三篇博客
NVIDIA Jetson TX2简介_竹叶青lvye的博客-CSDN博客_nvidiatx2
NVIDIA Jetson官网资料整理_竹叶青lvye的博客-CSDN博客
NVIDIA Jetson TX2安装JetPack_竹叶青lvye的博客-CSDN博客
一.配置指定的python版本
这里选择python3.7,方法参考博主之前博客
树莓派4B上多版本python切换(一)_竹叶青lvye的博客-CSDN博客_树莓派python版本更换
注:
(1)软链接的删除可参考Ubuntu下的基本知识点(一)_竹叶青lvye的博客-CSDN博客_ubuntu基础知识
(2)这里pip3的链接目标要切换为如下(结合自己的路径)
完毕后,终端输入python3和pip3 -V
可以看到已经切换到python3.7了,而不是系统自带的python3.6。
注:
若发现在桌面点击终端没有反应,terminal打不开,可以打开任意文件夹,空白处右击打开终端。编辑如下路径下的文件
最顶部改为当前系统默认的python3.6,原先的是python3。(因为前面建立软链接时,python3已经链接到python3.7版本了,所以这边捅破窗户,直接告诉系统,你要用的就是python3.6)。完毕后,桌面上点击终端就能打开了。
二.配置CUDNN
博主前面重新安装过JetPack
NVIDIA Jetson TX2重装系统_竹叶青lvye的博客-CSDN博客
这里要看默认的cuda和cudnn系统可以如下命令语句查看
cd到如下目录
/usr/src/cudnn_samples_v8/mnistCUDNN
执行sudo make,完毕后再执行./mnistCUDNN,显示测试通过。
类似博主之前博客,我们需要将cudnn的一些头文件和lib库拷贝到cuda下面去
TensorRT安装及验证_竹叶青lvye的博客-CSDN博客_验证tensorrt
对于当前TX2的配置,执行如下的命令语句
sudo cp /usr/lib/aarch64-linux-gnu/libcudnn* /usr/local/cuda-10.2/lib64
三.安装Tensorflow
主要参考博主之前博客里的方法
树莓派4B安装Tensorflow2.4.0_竹叶青lvye的博客-CSDN博客_树莓派安装tensorflow
这里选择如下版本
下载下来后使用如下命令进行安装
pip install tensorflow-2.4.0-cp37-none-linux_aarch64.whl --user
安装过程中若出现如下错误信息:
可以手动去源码编译下hdf5, 可从网址Download HDF5下载,博主这里选用的是hdf5-1.10.6
完毕后,在hdf5-1.10.6文件夹中新建一个install文件夹,然后执行如下命令行语句进行编译
./configure --prefix=/home/sxhlvye/Downloads/hdf5-1.10.6/install
sudo make -j4
sudo make install
完毕后,在install文件夹中就能看到安装好的库
注:别忘了在~/.bashrc中配置下环境变量哦,如下:
完毕后,可以继续执行如下两条安装语句:
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libhdf5-dev
完毕后再重新执行如下命令语句
pip install tensorflow-2.4.0-cp37-none-linux_aarch64.whl --user
这次安装成功,如下图:
测试:如下import库没有报错
四.安装pycharm
参考博客下载和安装(这里选择的是社区版,无需激活)Ubuntu20.04 C++程序的简单编译及QT和Pycharm的配置_竹叶青lvye的博客-CSDN博客
在执行./pycharm.sh的时候,出现报错:No JRE found.Please make sure $PYCHARM_JDK,$JDK_HOME,or $JAVA_HHOME point to valid JRE installation
需要配置下jdk。
1.使用apt-cache search openjdk来看当前TX2环境下所支持的jdk版本
这边配置jdk11
2.如下命令行语句即可安装
sudu apt-get install openjdk-11-jdk
安装完毕后,可执行语句查看openjdk的安装路径
dpkg -L openjdk-11-jdk
如下命令可以查看jdk的版本
java -version
3.再次执行./pycharm.sh, pycharm能正常加载
但看到报错信息:Failed to load moudle "canberra-gtk-moudle"
等会下面来解决它。
五.更新源
可以参考博主之前博客更新源
VMware Ubuntu20.04下挂载磁盘、更新源等常用配置_竹叶青lvye的博客-CSDN博客_ubuntu vmware 挂载硬盘
这里选择如上的源,但记得要将里面的ubuntu改为ubuntu-ports
完毕后,别忘了执行语句sudo apt-get update
更新完毕,尝试安装下如下语句
sudo apt-get install libcanberra-gtk-module
以解决上面第三部分中提到的报错。此时再打开pycharm,后台就不会出现报错信息了。在pycharm中来测试下前面配置的tensorflow的信息
pycharm的使用可以参考博主之前的博客,从上图中可以看出,第二部分所装的tensorflow版本不是GPU版本的,所以接下来通过虚拟环境,在python3.7版本的虚拟环境下配置下tensorflow-gpu
六. 配置Tensorflow-GPU
python3下虚拟环境的配置可以参考博主之前的博客
树莓派4B上多版本python切换(二)_竹叶青lvye的博客-CSDN博客_树莓派切换python2
安装过程,主要参考官网DOCS这一栏
NVIDIA Documentation Center | NVIDIA Developer
点进去后,便可以看到安装说明
Installing TensorFlow for Jetson Platform :: NVIDIA Deep Learning Frameworks Documentation
博主这边就不复述了,按照文档操纵即可,还是很详细的。博主所用的TX2的配置可见之前博客
NVIDIA Jetson TX2重装系统_竹叶青lvye的博客-CSDN博客
链接里也例句了官方tensorflow的一些信息
TensorFlow for Jetson Platform Release Notes :: NVIDIA Deep Learning Frameworks Documentation
博主这边安装Tensorflow 2.7版本(博主所使用的python3环境还是安装Jetpack后系统默认的python3.6环境,并没有在前面所配置的python3.7环境下安装tensorflow2.7)。
博主这边是先下载下来,再进行的安装,下载地址如下
Index of /compute/redist/jp/v461/tensorflow
下载下来后,再pip安装下,即可
验证:
在pycharm测试如下代码:
import tensorflow as tf
print(tf.test.is_gpu_available())
print(tf.config.list_physical_devices('GPU'))
print(tf.test.is_built_with_cuda())
执行结果如下:
/usr/bin/python3 /home/sxhlvye/PycharmProjects/pythonProject/test1.py
WARNING:tensorflow:From /home/sxhlvye/PycharmProjects/pythonProject/test1.py:2: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2022-06-25 07:03:13.240374: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:13.465336: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:13.465659: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.279189: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.279540: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.279799: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.280005: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 638 MB memory: -> device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2
True
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
True
2022-06-25 07:03:17.291743: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.293825: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
2022-06-25 07:03:17.295500: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1019] ARM64 does not support NUMA - returning NUMA node zero
Process finished with exit code 0
上面可看到已经成功安装,能够跑在GPU上。
这边也跑下之前博客(在树莓派上运行)中的代码
树莓派4B安装Tensorflow2.4.0_竹叶青lvye的博客-CSDN博客_树莓派安装tensorflow
运行结果如下,ct需要19s:
七. 配置Pytorch
参考官方文档
Installing PyTorch for Jetson Platform :: NVIDIA Deep Learning Frameworks Documentation
博主这边还是先下载好安装包,再pip install安装 (安装之前先按照官网配置下预配置环境)
Index of /compute/redist/jp/v461/pytorch
安装完毕后,如下测试,没有报错,torch成功安装
再继续安装下torchvision库,如下命令行语句即可,torch、torchvision、torchaudio的对应关系可从官网去查看
https://pytorch.org/get-started/locally/
pip install torchvision==0.10.0 --default-timeout=100000
pip install torchaudio
完毕后,在pycharm中进行如下的代码测试:
import torch
import torchvision
from torchvision import transforms
import torchvision.models as models
print("over")
print(torch.cuda.is_available())
print(torch.__version__)
print(torch.backends.cudnn.version())
运行结果如下:
可看到pytorch已经配置成功。跑下博主之前博客(在树莓派上)中的测试代码
树莓派4B安装pytorch_竹叶青lvye的博客-CSDN博客_树莓派4b安装pytorch
可看到在TX2上跑的时间,需要28s。
八.配置TensorRT
前面重装系统后,默认的python3.6环境下已经有了tensorrt的库,这边直接贴上加速效果图,具体方法参考博主之前博客。
TensorRT加速方法介绍(python pytorch模型)_竹叶青lvye的博客-CSDN博客_tensorrt加速
需要pip3 install pycuda,安装过程中若出现如下错误
In file included from src/cpp/cuda.cpp:4:0:
src/cpp/cuda.hpp:14:10: fatal error: cuda.h: No such file or directory
#include <cuda.h>
^~~~~~~~
compilation terminated.
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
可以在环境变量中添加相关变量
export CPATH=$CPATH:/usr/local/cuda/include
在执行import torch时,若报:OSError: libomp.so找不到问题,可添加如下环境变量
在TX2上的运行信息如下,ct时间大大加快:
精力有限,只记录上面几个常用库的配置,可以到其过程和在其它硬件平台上的ubuntu系统环境下差距不大。
边栏推荐
- The most robust financial products in 2022
- Games101 Lesson 8 shading 2 Notes
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
- [notes] streamingassets
- Pat 1059 prime factors (25 points) prime table
- [directory] search
- First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
- 13、 C window form technology and basic controls (3)
- 昨天的事情想说一下
- C language memory layout
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
[the way of programmer training] - 2 Perfect number calculation
Practical dry goods: deploy mini version message queue based on redis6.0
Clion configuration of opencv
Communication tutorial | overview of the first, second and third generation can bus
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
How to judge the advantages and disadvantages of low code products in the market?
Wechat video Number launches "creator traffic package"
Games101 Lesson 8 shading 2 Notes
随机推荐
【数据聚类】第四章第一节3:DBSCAN性能分析、优缺点和参数选择方法
OSI seven layer model & unit
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
Detailed explanation of NPM installation and caching mechanism
French Data Protection Agency: using Google Analytics or violating gdpr
Global and Chinese market of piston rod 2022-2028: Research Report on technology, participants, trends, market size and share
Workplace liquor bureau must pay attention to
Source code analysis of the implementation mechanism of multisets in guava class library
R语言--readr包读写数据
Practice of retro SOAP Protocol
Global and Chinese market of dental elevators 2022-2028: Research Report on technology, participants, trends, market size and share
Games101 Lesson 8 shading 2 Notes
C language: find the length of string
[directory] search
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
[notes] in depth explanation of assets, resources and assetbundles
MySQL performance optimization index
MySQL advanced review
Awk getting started to proficient series - awk quick start
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6