当前位置:   article > 正文

TX2刷机和软件安装过程记录_deprecationwarning: pkg_resources is deprecated as

deprecationwarning: pkg_resources is deprecated as an api

准备

  1. 数据线、键盘、鼠标、显示器少不掉(显示器要支持HDMI接口,我看网上说HDMI转VGA的会黑屏,没有试过)
  2. Ubuntu16或Ubuntu18的虚拟机,或电脑作为主机(Ubuntu20.04不行,因为我电脑就是,第一次装了没法用)
  3. 有网的环境,而且网速一定要好,我在实验室里网速一般,经常下载失败

使用SDKmanager刷机

  1. 打开准备的Ubuntu系统作为主机
    注意 如果使用虚拟机需要分配较大的硬盘空间,起码得40GB,最好能有100G这个样子,否则空间不足也会失败
  2. 注册英伟达开发者账号https://developer.nvidia.com/
  3. 下载英伟达的SDKmanager(地址百度一下吧),安装,打开,登录
  4. TX2板子的第三根引脚和GND相连(进入恢复模式),上电,连主机
  5. Host Machine有的博客里面也点了,实际上不需要的,这个是给你电脑主机安装cuda之类的,如果没有这个需要,就不用勾上
    可以输入lsusb 看看有没有英伟达的设备,确保板子连上
    确保板子是脸上7. 底下的第一个I accept…要勾上,第二个Downloader now and install later第一次也建议勾上,意思是先下载,不安装。待会下载完了可以一起安装。如果是边下载变安装,网速不好很容易出问题在这里插入图片描述
  6. 先会烧写jetson os(就是魔改过的Ubuntu18),烧写到要结束的时候,显示屏会自己亮起来,过一段时间会出现这样的提示
    在这里插入图片描述
    不慌,这个是镜像已经烧写好了,可以进入系统了,后面是安装SDK软件的部分。我们先登录系统,设置用户和密码
    之后在TX2上设置开启SSH服务
ps -e | grep ssh  # 查看有没有SSH服务
sudo apt-get install openssh-server
sudo apt-get install openssh-client
service ssh start # 开启服务
  • 1
  • 2
  • 3
  • 4

如果ps -e | grep ssh当中有sshd则表示正常
可以通过ifconfig或者 ip addr查看ip地址
在主机上输入账号和密码一般就可以连接了
在这里插入图片描述
确保主机和TX2在同一个局域网络下
我的虚拟机配置如下,建议使用桥接模式而不是NAT模式
在这里插入图片描述
然后耐心等待他自己安装,有可能不能成功,多试几次
在这里插入图片描述
我在最后一步的Deepstream出错了,查看日志,认为是内存不够的问题,这个SDK暂时不是很重要,后面自己装一下
在使用SDKmanager中有问题可以参考官方的说明
我遇到的问题:
1、Default ip is not avaliable. Please make sure the default ip is shown in ip addr, or use a customer ip instead.
ip默认是192.168.55.1,我第一次刷机是直接可以连上的,第二次就报了这个错误,我换了一个ip192.168.3.141就可以了
2、flash 1%的时候就会error, 提示板子状态不对,不在恢复模式之类的话(我确定是在恢复模式),多试几次,可能试一次就好了,也有可能试很多很多次(啥也没动,不知道为什么,玄学)

手动安装SDK

虽然英伟达提供的工具傻瓜式操作,十分好用(也不好用,十分容易出错),但实际难免会遇到正常刷机不了的。英伟达提供了其他的安装方法https://docs.nvidia.com/jetson/jetpack/install-jetpack/index.html
刷完机是裸系统的话,可以让板子在线安装(我没试过)
在这里插入图片描述
我第一次也没有安装成功,自己手动安装了cuda,cudnn,pytorch,tersonRT等。后面可能会介绍一些安装的方法。

SSD启动

我们TX2的板子上装了一块128GB的固态硬盘,十分实用,下面介绍如何将SSD设为第一启动项

1. 格式化已安装的 SSD

打开DISK
在这里插入图片描述
点右上角的三条横线按钮
在这里插入图片描述
之后Fromat
点底下的加号
在这里插入图片描述
留16GB的交换空间
在这里插入图片描述
之后create,就成功创建卷

2. 从SD卡复制到SSD

git clone https://github.com/jetsonhacks/rootOnNVMe.git
cd rootOnNVMe
./copy-rootfs-ssd.sh
  • 1
  • 2
  • 3

如果执行了这个脚本却没有反映,一般是权限不够,给它权限就好了,就像这样

chmod  +x copy-rootfs-ssd.sh
  • 1

3. 启用从 SSD 启动

./setup-service.sh
  • 1

之后重新启动,就可以看到TX2的内存有100多G了

换源

TX2的软件源为国外服务器,网速会很慢,需要换国内的ARM源(记得是ARM的)

1. 备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak    #先备份原文件sources.list
sudo vim /etc/apt/sources.list  #sudo打开sources.list
  • 1
  • 2

2. 删除或注释sources.list中的所有内容,将下面的内容复制进去

清华源

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse  
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main universe restricted   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main universe restricted
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

科大源:

deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse
deb htp://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main universe restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main universe restricted
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3. 保存

sudo apt-get update
sudo apt-get upgrade
  • 1
  • 2

查看一些信息

1.查看cuda的版本

nvcc -V # 或者nvcc --version
  • 1

2.查看cudnn的版本

网上的那些一般输进去没有反应,仔细考虑过觉得这样才是正确的

cat /usr/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
  • 1

3.查看opencv的版本

pkg-config --modversion opencv
  • 1

一开始不能查看opencv版本,原因是由于没有找到opencv.pc,而jetpack4.4+刷机刷的opencv是opencv4
将/usr/lib/aarch64-linux-gnu/pkgconfig中的opencv4.pc,复制到/usr/lib/pkgconfig下,并改名为opencv.pc就可以了。

cd  /usr/lib/aarch64-linux-gnu/pkgconfig
sudo cp opencv4.pc /usr/lib/pkgconfig/opencv.pc
  • 1
  • 2

默认是4.1.1

4.查看TensorRT的版本

dpkg -l | grep TensorRT
  • 1

5.查看系统版本

cat /etc/lsb-release
  • 1

6.查看正在运行的进程

top
  • 1

一些软件的安装

1.安装todesk远程软件

sudo dpkg -i todesk_x.x.x_aarch64.deb
  • 1

2.装jtop查询系统工具

sudo -H python3 -m pip install jetson-stats
  • 1

修改默认python、pip版本

1. 修改python版本

默认板子刷机后是自带python为2.7和python3.6.9解析器的(使用python3 -V可以查到),但默认是python2.7 ,如果需要python3.6.9,需使用下面命令调用python3.6版本

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
sudo update-alternatives --config python
  • 1
  • 2
  • 3

2.修改pip版本

sudo apt-get install python3-pip
  • 1

一些软件的安装

1. torch & torchvision的安装

此处参考官方教程 里面内容十分详尽
本人是下载使用了官方提供的torch-1.8.0-cp36-cp36m-linux_aarch64.whl包

sudo apt-get install python3-pip libopenblas-base libopenmpi-dev 
pip3 install Cython
pip3 install numpy torch-1.8.0-cp36-cp36m-linux_aarch64.whl #注意路径下包含刚才下载的“torch-1.8.0”这个包
  • 1
  • 2
  • 3

pytorch应该就被安装好了,安装torchvision的话要注意对应pytorch的版本!

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch v0.9.0 https://github.com/pytorch/vision # 从github上下载对应版本的
python3 setup.py install --user # 在下载下来的文件夹下运行安装程序,编译过程会比较慢,耐心等一下
  • 1
  • 2
  • 3

我遇到的问题:
报这样的错误:

virtual AVCodec* findCodec(AVCodecParameters* params);
^~~~~~~~~~~~~~~~~
/home/paluhin/Downloads/torchvision/torchvision/csrc/io/video_reader/…/decoder/stream.h:52:20: error: expected ‘;’ at end of member declaration
virtual AVCodec* findCodec(AVCodecParameters* params);
^~~~~~~~~
/home/paluhin/Downloads/torchvision/torchvision/csrc/io/video_reader/…/decoder/stream.h:52:47: error: expected ‘)’ before ‘’ token
virtual AVCodec findCodec(AVCodecParameters* params);
^
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

网上找来找去也没有人提到,最后在论坛找到了方法,希望以后遇到这个问题的人不会像我一样煎熬

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
# 不行的话试一下
$ sudo mv /usr/bin/ffmpeg /usr/bin/ffmpeg_backup
  • 1
  • 2
  • 3

2.archiconda的安装

本人现在是不使用conda的,但之前装过,记录一下
TX2无法使用anaconda,有大佬编译了archiconda,这东西就是anaconda的aarch64的版本。我用这个进行虚拟环境的安装。
直接到https://github.com/Archiconda/build-tools/releases下载.sh文件
然后到你下载文件的地址
sh 你的sh文件

./Archiconda3-0.2.3-Linux-aarch64.sh
  • 1

之后点yes,安装完毕。安装中间有叫你选择目录,如果不喜欢它默认的可以换。
archiconda的使用和普通的anaconda没有什么区别
如果你在虚拟环境里面使用pytorch,请务必建立python3.6的环境

conda create -n pytorch python=3.6
conda activate pytorch
  • 1
  • 2

3.TensorRT的安装

刷机过后会自带TensorRT,下面记录自己之前自行安装的方法。仅记录自己用tar安装tensorRT的流程,对于DEV版本等的安装,请移步其他博客。
参看cuda,cudnn的版本后挑选TensorRT版本(千万不要不符合,不然很麻烦,可能我当时第一次选的不对报了一些奇怪的错误,换了版本就好了)
下面的指令是copy其他博主的

# 在home下将下载的压缩文件进行解压
tar xzvf TensorRT-6.0.1.5.Ubuntu-16.04.x86_64-gnu.cuda-10.1.cudnn7.6.tar.gz
 
# 解压得到TensorRT-6.0.1.5的文件夹,将里边的lib绝对路径添加到环境变量中
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/xxxxx/TensorRT-6.0.1.5/lib
# 如果手动添加到.bashrc文件中,需要执行source .bashrc命令,配好的环境才能生效

# 安装TensorRT
cd TensorRT-6.0.1.5/python
pip install tensorrt-6.0.1.5-cp37-none-linux_x86_64.whl
# 博主亲测,这里你的python环境并没有限制,py35,py36,py37都可
 
# 安装UFF,支持tensorflow模型转化
cd TensorRT-6.0.1.5/uff
pip install uff-0.6.5-py2.py3-none-any.whl
 
# 安装graphsurgeon,支持自定义结构
cd TensorRT-6.0.1.5/graphsurgeon
pip install graphsurgeon-0.4.1-py2.py3-none-any.whl
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

4.安装中文输入法

sudo apt install fcitx fcitx-googlepinyin fcitx-table-wbpy fcitx-pinyin fcitx-sunpinyin 
  • 1

在语言设置选项里(langugae support)选择fcitx。
重启电脑,在Fcitx configuration里配置下就好了。

5.安装ROS

1.更换源

我用的是自带的源

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  • 1

如果需要换源的话可以参考这一篇

2.设置最新的密钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
  • 1
3、安装:
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
  • 1
  • 2
  • 3
4、初始化ROS
sudo apt install python-rosdep
sudo rosdep init
rosdep update
  • 1
  • 2
  • 3

如果出现下面情况,基本是网络问题,换个网络尝试下

ubuntu@ubuntu-d:~$ sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
  • 1
  • 2
  • 3
  • 4

或修改hosts Ubuntu直接在终端输入

sudo gedit /etc/hosts
  • 1

添加以下内容保存即可

151.101.84.133 raw.githubusercontent.com
  • 1

这个解决方法来自这里
如果不行试试这个
或者这个
其实我后来依旧出问题

rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
	<urlopen error timed out> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
	<urlopen error [Errno 104] Connection reset by peer> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
	<urlopen error [Errno 104] Connection reset by peer> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
^CTraceback (most recent call last):
  File "/usr/bin/rosdep", line 11, in <module>
    load_entry_point('rosdep==0.21.0', 'console_scripts', 'rosdep')()
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 146, in rosdep_main
    exit_code = _rosdep_main(args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 441, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 450, in _no_args_handler
    return command_handlers[command](options)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 662, in command_update
    ros_distro=options.ros_distro)
  File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 480, in update_sources_list
    rosdep_data = download_rosdep_data(source.url)
  File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 315, in download_rosdep_data
    f = urlopen(url_request, timeout=DOWNLOAD_TIMEOUT)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1248, in https_open
    context=self._context)
  File "/usr/lib/python2.7/urllib2.py", line 1202, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/usr/lib/python2.7/httplib.py", line 1099, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1139, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1095, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 898, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 860, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 1312, in connect
    HTTPConnection.connect(self)
  File "/usr/lib/python2.7/httplib.py", line 837, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 566, in create_connection
    sock.connect(sa)
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
KeyboardInterrupt

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

没办法,买代理吧
如果出现下面情况,是python版本问题,换到python2就可以了
home/rm/.local/lib/python3.6/site-packages/pkg_resources/init.py:119:

PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
  PkgResourcesDeprecationWarning,
Traceback (most recent call last):
  File "/usr/bin/rosdep", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3266, in <module>
    @_call_aside
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3241, in _call_aside
    f(*args, **kwargs)
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3279, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 573, in _build_master
    ws.require(__requires__)
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 891, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/rm/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 777, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'rosdep==0.21.0' distribution was not found and is required by the application
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

解决:

sudo update-alternatives --config python
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。

  选择       路径            优先级  状态
------------------------------------------------------------
* 0            /usr/bin/python3   150       自动模式
  1            /usr/bin/python2   100       手动模式
  2            /usr/bin/python3   150       手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:1
update-alternatives: 使用 /usr/bin/python2 来在手动模式中提供 /usr/bin/python (python)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

重新进行初始化等步骤又可以了

sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

	rosdep update
  • 1
  • 2
  • 3
  • 4
  • 5
5、安装rosinstall
sudo apt-get install python-rosinstall
  • 1
6、添加ros环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
  • 1
  • 2

完成了

7、测试

可以尝试分别在三个终端下执行这三条命令

roscore  
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key 
  • 1
  • 2
  • 3

成功的话,可以方向键操作小海龟,则ROS成功安装。

6. 安装pycharm

1. 下载Pycharm

(1)下载pycharm社区版,下载地址
(2)解压下载文件到任意位置待用。可以使用tar -xf来进行解压。
(3)cd到bin文件夹,运行./pycharm.sh,出现以下报错。问题是缺少JDK环境。

Gtk-Message: 18:05:39.195: GtkDialog mapped without a transient parent. This is discouraged.
  • 1
2.解决这个问题的方法:

(1)输入以下指令:(jetpack为4.5.1版本)

apt-cache search openjdk
sudo apt-get install openjdk-11-jdk
  • 1
  • 2

(2)等待完成后用下面指令检查版本情况

java -version // 查看安装结果
  • 1
penjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.18.04, mixed mode)
  • 1
  • 2
  • 3

(3)没问题后进行环境变量配置
首先切换用户到root

sudo -i 
  • 1
gedit ~/.bashrc
  • 1

在末尾加入

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
  • 1
  • 2
  • 3
  • 4
source ~/.bashrc
  • 1

(4)运行Pycharm
进入刚刚解压的pycharm/bin文件夹运行./pycharm.sh

7.安装DeepStream

Deepstream的安装可以参考官方教程
https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_Quickstart.html#jetson-setup
先安装依赖

sudo apt install \
libssl1.0.0 \
libgstreamer1.0-0 \
gstreamer1.0-tools \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
libgstrtspserver-1.0-0 \
libjansson4=2.11-1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在官网Install the DeepStream SDK一栏
我选择了Method 2的方法,原文如下:

Method 2: Using the DeepStream tar package: https://developer.nvidia.com/deepstream_sdk_v6.0.0_jetsontbz2
Download the DeepStream 6.0 Jetson tar package deepstream_sdk_v6.0.0_jetson.tbz2 to the Jetson device.
Enter the following commands to extract and install the DeepStream SDK:

$  sudo tar -xvf deepstream_sdk_v6.0.0_jetson.tbz2 -C /
$ cd /opt/nvidia/deepstream/deepstream-6.0
$ sudo ./install.sh
$ sudo ldconfig
  • 1
  • 2
  • 3
  • 4

我其实用的是v5.1.0 版本,下的是deepstream_sdk_v5.1.0_jetson.tbz2,操作是一样的
安装完成进入官方例程文件夹

cd /opt/nvidia/deepstream/deepstream-5.1/samples/configs/deepstream-app/
deepstream-app -c source12_1080p_dec_infer-resnet_tracker_tiled_display_fp16_tx2.txt 
  • 1
  • 2

部署yolov5(使用TensorRT)

到github上去下载源码

git clone https://github.com/ultralytics/yolov5.git
  • 1

在yolov5项目下,右键打开终端,安装依赖
我们已经安装好了pytorch,torchvision,建议把这两个注释掉,以防命令行自动更新了

pip3 install -r requirements -i https://mirror.baidu.com/pypi/sample 
  • 1

下载yolov5的权重,我用的是之前我自己训练好的,需要改名为yolov5s.pt(不改名字就改代码)

TensorRT加速

git clone https://github.com/wang-xinyu/tensorrtx.git
  • 1

具体编译方法原作者有很详细的说明

cd tensorrtx
cp yolov5/gen_wts.py ~/yolov5
cd ~/yolov5
python gen_wts.py -w yolov5s.pt -o yolov5s.wts
  • 1
  • 2
  • 3
  • 4

就得到了wts格式的文件

# 需要改一下CLASS NUM的值
cd ~/tensorrtx/yolov5
mkdir build && cd build
mv ~/yolov5/yolov5s.wts ./
cmake .. 
make -j
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

等出现这个就好了

[ 60%] Building CXX object CMakeFiles/yolov5.dir/calibrator.cpp.o
[ 80%] Building CXX object CMakeFiles/yolov5.dir/yolov5.cpp.o
[100%] Linking CXX executable yolov5
[100%] Built target yolov5
  • 1
  • 2
  • 3
  • 4

表示编译成功

./yolov5 -s yolov5s.wts yolov5s.engine s #生成engine文件需要一段时间
  • 1

等出现这个就好了

Loading weights: yolov5s.wts
Building engine, please wait for a while...
Build engine successfully!
  • 1
  • 2
  • 3

有了engine就可以调用了
测试一下

./yolov5 -d yolov5s.engine ../samples
  • 1

samples下面放需要测试的图片

6ms
6ms
  • 1
  • 2

会出现推理所用的时间,在build下面会出现推理后的结果
我遇到的问题
1、

[12/24/2021-11:36:38] [E] [TRT] Parameter check failed at: ../builder/Network.cpp::addScale::482, condition: shift.count > 0 ? (shift.values != nullptr) : (shift.values == nullptr)
yolov5: /home/rm/tensorrtx/yolov5/common.hpp:155: nvinfer1::IScaleLayer* addBatchNorm2d(nvinfer1::INetworkDefinition*, std::map<std::__cxx11::basic_string<char>, nvinfer1::Weights>&, nvinfer1::ITensor&, std::__cxx11::string, float): Assertion `scale_1' failed.
Aborted (core dumped)
  • 1
  • 2
  • 3

不知道为什么,重新下载编译了一遍工程就好了,可能文件缺失了吧,又是玄学
2、
编译核心时出现问题

Loading weights: yolov5s.wts
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: kernel weights has count 3840 but 32640 was expected
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: count of 3840 weights in kernel, but kernel dimensions (1,1) with 128 input channels, 255 output channels and 1 groups were specified. Expected Weights count is 128 * 1*1 * 255 / 1 = 32640
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: kernel weights has count 3840 but 32640 was expected
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: count of 3840 weights in kernel, but kernel dimensions (1,1) with 128 input channels, 255 output channels and 1 groups were specified. Expected Weights count is 128 * 1*1 * 255 / 1 = 32640
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: kernel weights has count 3840 but 32640 was expected
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: count of 3840 weights in kernel, but kernel dimensions (1,1) with 128 input channels, 255 output channels and 1 groups were specified. Expected Weights count is 128 * 1*1 * 255 / 1 = 32640
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: kernel weights has count 3840 but 32640 was expected
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: count of 3840 weights in kernel, but kernel dimensions (1,1) with 128 input channels, 255 output channels and 1 groups were specified. Expected Weights count is 128 * 1*1 * 255 / 1 = 32640
Building engine, please wait for a while...
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: kernel weights has count 3840 but 32640 was expected
[01/20/2022-18:08:29] [E] [TRT] (Unnamed Layer* 214) [Convolution]: count of 3840 weights in kernel, but kernel dimensions (1,1) with 128 input channels, 255 output channels and 1 groups were specified. Expected Weights count is 128 * 1*1 * 255 / 1 = 32640
[01/20/2022-18:08:29] [E] [TRT] Could not compute dimensions for (Unnamed Layer* 214) [Convolution]_output, because the network is not valid.
[01/20/2022-18:08:29] [E] [TRT] Network validation failed.
Build engine successfully!
yolov5: /home/ubuntu/tensorrtx-yolov5-RM/yolov5/yolov5.cpp:245: void APIToModel(unsigned int, nvinfer1::IHostMemory**, bool&, float&, float&, std::string&): Assertion `engine != nullptr' failed.
已放弃 (核心已转储)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

CALSS_NUM没有改
未完待续。。

安装pycharm

1. 下载Pycharm

(1)下载pycharm社区版,下载地址
(2)解压下载文件到任意位置待用。可以使用tar -xf来进行解压。
(3)cd到bin文件夹,运行./pycharm.sh,出现以下报错。问题是缺少JDK环境。

Gtk-Message: 18:05:39.195: GtkDialog mapped without a transient parent. This is discouraged.
  • 1

2.解决这个问题的方法:

(1)输入以下指令:(jetpack为4.5.1版本)

apt-cache search openjdk
sudo apt-get install openjdk-11-jdk
  • 1
  • 2

(2)等待完成后用下面指令检查版本情况

java -version // 查看安装结果
  • 1
penjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.18.04, mixed mode)
  • 1
  • 2
  • 3

(3)没问题后进行环境变量配置
首先切换用户到root

sudo -i 
  • 1
gedit ~/.bashrc
  • 1

在末尾加入

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
  • 1
  • 2
  • 3
  • 4
source ~/.bashrc
  • 1

(4)运行Pycharm
进入刚刚解压的pycharm/bin文件夹运行./pycharm.sh

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/144506
推荐阅读
  

闽ICP备14008679号