tx2_nx安装的是3261的bsp,jetpack4.6,python版本3.6.9
默认安装的是 如下版本安装教程看我之前的博客就行点击跳转
torch_version: 1.10.0
cuda_version: 10.2
cudnn_version: 8201
----------------------------------
True
device_count: 1
cuda:0
device_name: NVIDIA Tegra X2
tensor([[0.2731, 0.3814, 0.9734],
[0.3926, 0.0862, 0.3923],
[0.2319, 0.3595, 0.6996]], device='cuda:0')
CUDA available: True
cuDNN version: 8201
Tensor a = tensor([0., 0.], device='cuda:0')
Tensor b = tensor([-0.8535, -0.3004], device='cuda:0')
Tensor c = tensor([-0.8535, -0.3004], device='cuda:0')
0.11.0a0
安装过程饶了一大堆圈子,刚开始以为是QT的问题,opencv-python版本也没在意,以为是大于4.1.2就可以了。各种尝试开始了
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Aborted
资料贡献博主一估计也是没找到根源可以借鉴一下 这个方法,不显示界面,保存到文件夹下去打开
测试代码报错如上:以为是qt的问题
qt下程序运行问题贡献博主
nvidia论坛贡献Getting Error in Jetson Xavier -> qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "" - Jetson & Embedded Systems / Jetson Xavier NX - NVIDIA Developer Forums
按照nvidia的论坛我还安装了QT 也算获得了一个新技能
In the end what worked for me (Jetson Nano 4GB) was:
(Source: PySide2 (Qt for python) installation on Jetson Xavier 34)
Download Qt source:
if you need the whole Qt5 (~900MB):
wget http://master.qt.io/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz 19
or
qtbase (basic module such as QtCore, QtGui and QtWidget)(~90MB):
wget http://master.qt.io/archive/qt/5.15/5.15.2/submodules/qtbase-everywhere-src-5.15.2.tar.xz 8
configure and install Qt5 (here I used qtbase):
tar -xpf qtbase-everywhere-src-5.15.2.tar.xz
cd qtbase-everywhere-src-5.15.2/
./configure -xcb
(must enable xcb here manually)
Choose “o” to install Qt open source version.
make -j4
sudo make install
Also
#If you don't configure the installation path, you need to create a link.
sudo ln -sf /usr/local/Qt-5.15.2/bin/qmake /usr/lib/aarch64-linux-gnu/qt5/bin/qmake
安装过程参考了贡献博主
贡献博主
意思是找不到xcb这个插件 ,然后去QT的安装路径下面找,我的是/usr/local/Qt-5.15.3/plugins/platforms,下面只有这几个lib,找到了libqxcb.so
pip3 list
Package Version
----------------------------- -------------------
apt-clone 0.2.1
apturl 0.5.2
asn1crypto 0.24.0
beautifulsoup4 4.6.0
blinker 1.4
Brlapi 0.6.6
certifi 2022.9.24
chardet 3.0.4
charset-normalizer 2.0.12
cppy 1.2.0
cryptography 2.1.4
cupshelpers 1.0
cycler 0.11.0
Cython 0.29.32
dataclasses 0.8
decorator 4.1.2
defer 1.0.6
distro 1.8.0
distro-info 0.18ubuntu0.18.04.1
feedparser 5.2.1
graphsurgeon 0.4.5
html5lib 0.999999999
httplib2 0.9.2
idna 3.4
importlib-resources 5.4.0
Jetson.GPIO 2.0.17
jetson-stats 3.1.4
keyring 10.6.0
keyrings.alt 3.0
kiwisolver 1.3.1
language-selector 0.1
launchpadlib 1.10.6
lazr.restfulclient 0.13.5
lazr.uri 1.0.3
louis 3.5.0
lxml 4.2.1
macaroonbakery 1.1.3
Mako 1.0.7
MarkupSafe 1.0
matplotlib 3.3.4
numpy 1.19.5
oauth 1.0.1
oauthlib 2.0.6
onboard 1.4.1
opencv-python 4.5.5.64
packaging 21.3
PAM 0.4.2
pandas 1.1.5
Pillow 8.4.0
pip 21.3.1
protobuf 3.0.0
pybind11 2.10.1
pycairo 1.16.2
pycrypto 2.6.1
pycups 1.9.73
PyGObject 3.26.1
PyICU 1.9.8
PyJWT 1.5.3
pymacaroons 0.13.0
PyNaCl 1.1.2
pyparsing 3.0.9
pyRFC3339 1.0
python-apt 1.6.5+ubuntu0.6
python-dateutil 2.8.2
python-debian 0.1.32
pytz 2018.3
pyxattr 0.6.0
pyxdg 0.25
PyYAML 6.0
requests 2.27.1
requests-unixsocket 0.1.5
scikit-build 0.16.2
scipy 1.5.4
seaborn 0.11.2
SecretStorage 2.3.1
setuptools 59.6.0
simplejson 3.13.2
sip 6.5.1
six 1.16.0
ssh-import-id 5.7
system-service 0.3
systemd-python 234
tensorrt 8.0.1.6
toml 0.10.2
torch 1.10.0
torchvision 0.11.0a0
tqdm 4.64.1
typing_extensions 4.1.1
ubuntu-drivers-common 0.0.0
uff 0.6.9
unity-scope-calculator 0.1
unity-scope-chromiumbookmarks 0.1
unity-scope-colourlovers 0.1
unity-scope-devhelp 0.1
unity-scope-firefoxbookmarks 0.1
unity-scope-manpages 0.1
unity-scope-openclipart 0.1
unity-scope-texdoc 0.1
unity-scope-tomboy 0.1
unity-scope-virtualbox 0.1
unity-scope-yelp 0.1
unity-scope-zotero 0.1
urllib3 1.26.12
urwid 2.0.1
wadllib 1.3.2
webencodings 0.5
wheel 0.37.1
xkit 0.0.0
youtube_dl 2018.3.14
zipp 3.6.0
zope.interface 4.3.2
nvidia@nvidia-desktop:~/yolov5-6.1$ pip in
翻阅资料以后找到如下方法,无奈又回到了起点,版本还是不对 ,pip3 install opencv-python4.3到4.5都安装了一遍,安装都失败了,4.5.5将就安装上也是下面的问题,给大家伙踩个雷,不要再跳坑了。
sudo pip3 --default-timeout=1000 install opencv-python-headless==4.5.5.64 -i https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
WARNING: The directory '/home/nvidia/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python-headless/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python-headless/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python-headless/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python-headless/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python-headless/
Collecting opencv-python-headless==4.5.5.64
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/43/03/13447b012f11ed59948a1f09fc791bd2fbc32afca11a49eea75a4e683d1d/opencv_python_headless-4.5.5.64-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.7 MB)
|████████████████████████████████| 26.7 MB 830 kB/s
Requirement already satisfied: numpy>=1.19.3 in /home/nvidia/.local/lib/python3.6/site-packages (from opencv-python-headless==4.5.5.64) (1.19.5)
Installing collected packages: opencv-python-headless
Successfully installed opencv-python-headless-4.5.5.64
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
nvidia@nvidia-desktop:~/yolov5-6.1$ sudo python3 detect.py --weights yolov5s.pt --source data/images/zidane.jpg --view-img
detect: weights=['yolov5s.pt'], source=data/images/zidane.jpg, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=True, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 2022-2-22 torch 1.10.0 CUDA:0 (NVIDIA Tegra X2, 3832MiB)Fusing layers...
Model Summary: 224 layers, 7266973 parameters, 0 gradients
Traceback (most recent call last):
File "detect.py", line 257, in
main(opt)
File "detect.py", line 252, in main
run(**vars(opt))
File "/home/nvidia/.local/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 181, in run
cv2.imshow(str(p), im0)
cv2.error: OpenCV(4.5.5) /io/opencv/modules/highgui/src/window.cpp:1268: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
直接使用pip3 install opencv-python和 pip3 install opencv-python--headless安装最新的4.6直接报错AttributeError: partially initialized module ‘cv2‘ has no attribute ‘_registerMatType‘ ,就应该知道
最新的opencv-python安装完不使用 --view-img:是否展示预测之后的图片/视频,默认False,也可以在本地下runs看到,应该是 opencv-python--headless的问题了
参数介绍
weights:训练的权重
source:测试数据,可以是图片/视频路径,也可以是'0'(电脑自带摄像头),也可以是rtsp等视频流
output:网络预测之后的图片/视频的保存路径
img-size:网络输入图片大小
conf-thres:置信度阈值(检测精度,作者是设置的0.25)
iou-thres:做nms的iou阈值()
device:设置设备
view-img:是否展示预测之后的图片/视频,默认False
save-txt:是否将预测的框坐标以txt文件形式保存,默认False
classes:设置只保留某一部分类别,形如0或者0 2 3
agnostic-nms:进行nms是否也去除不同类别之间的框,默认False
augment:推理的时候进行多尺度,翻转等操作(TTA)推理
update:如果为True,则对所有模型进行strip_optimizer操作,去除pt文件中的优化器等信息,默认为False
导入错误:无法从“cv2.cv2”导入名称“_registerMatType” ·问题 #591 ·OpenCV/OpenCV-Python (github.com)(13条消息) AttributeError: partially initialized module ‘cv2‘ has no attribute ‘_registerMatType‘_noirblack的博客-CSDN博客
原因就是opencv-python的版本和opencv-python-headless的版本兼容问题,安装好yolo5就不会报错了,差不多花费了我一周的时间,搭建开发环境真消耗时间,最后如下一条安装命令解决了尴尬
pip3--default-timeout=1000 install opencv-python install "opencv-python-headless<4.3" -i https://pypi.tuna.tsinghua.edu.cn/simple
-bash: pip3--default-timeout=1000: command not found
nvidia@nvidia-desktop:~$ pip3 --default-timeout=1000 install opencv-python install "opencv-python-headless<4.3" -i https://pypi.tuna.tsinghua.edu.cn/simple
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-python
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/12/5d/1527327b9f7ea13bef31377f8bf399f03dc5f4f1c9f1fb69bc56b6e24cd4/opencv_python-4.6.0.66-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (39.5 MB)
Collecting install
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4d/c8/8cbca135f9e167810756ea2bc34b028501936675fcbd7dadccf752fa4622/install-1.3.5-py3-none-any.whl (3.2 kB)
Collecting opencv-python-headless<4.3
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e7/a1/bd4535ce45ef5853b8e25d2753fe3c89dad419be55d89779ea60a3f52c10/opencv_python_headless-3.4.18.65-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (25.0 MB)
|████████████████████████████████| 25.0 MB 27 kB/s
Requirement already satisfied: numpy>=1.13.3 in ./.local/lib/python3.6/site-packages (from opencv-python) (1.19.5)
Installing collected packages: opencv-python-headless, opencv-python, install
Successfully installed install-1.3.5 opencv-python-4.6.0.66 opencv-python-headless-3.4.18.65
我的环境安装了以后就好了,欢迎大家测试!
test_yolo5部署到jetsons设备视频
播放地址