解决MMdetection3d运行demo报错:attributeError: ‘NoneType‘ object has no attribute ‘convert_to_pinhole_camer

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

1. 现象描述

运行以下代码报错

python projects/BEVFusion/demo/multi_modality_demo.py demo/data/nuscenes/n015-2018-07-24-11-22-45+0800__LIDAR_TOP__1532402927647951.pcd.bin demo/data/nuscenes/ demo/data/nuscenes/n015-2018-07-24-11-22-45+0800.pkl projects/BEVFusion/configs/bevfusion_lidar-cam_voxel0075_second_secfpn_8xb4-cyclic-20e_nus-3d.py /home/zc/Downloads/bevfusion_converted.pth  --cam-type all --score-thr 0.2 --show

或者运行官方的pcd_demo.py报错
报错详细如下

libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
[Open3D WARNING] GLFW Error: GLX: Failed to create context: GLXBadFBConfig
[Open3D WARNING] Failed to create window
/home/zc/APP/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/visualization/visualizer.py:831: UserWarning: Warning: The polygon is out of bounds, the drawn polygon may not be in the image
warnings.warn(
Traceback (most recent call last):
File "projects/BEVFusion/demo/multi_modality_demo.py", line 78, in <module>
main(args)
File "projects/BEVFusion/demo/multi_modality_demo.py", line 64, in main
visualizer.add_datasample(
File "/home/zc/APP/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/dist/utils.py", line 427, in wrapper
return func(*args, **kwargs)
File "/home/zc/work/code/python/mmdetection3d/mmdet3d/visualization/local_visualizer.py", line 1082, in add_datasample
self.show(
File "/home/zc/APP/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/dist/utils.py", line 427, in wrapper
return func(*args, **kwargs)
File "/home/zc/work/code/python/mmdetection3d/mmdet3d/visualization/local_visualizer.py", line 868, in show
self.view_control.convert_to_pinhole_camera_parameters() # noqa: E501
AttributeError: 'NoneType' object has no attribute 'convert_to_pinhole_camera_parameters'

如果不加–show有结果输出,但没有界面显示,或闪一下就消失,那么使用我的方法
报错原因:
opengl没有使用显卡驱动输出
现象如下:

glxinfo | grep "OpenGL renderer"
OpenGL renderer string: llvmpipe (LLVM 15.0.7, 256 bits)

glxinfo | grep "OpenGL vendor"
OpenGL vendor string: Mesa

2.解决办法

(1)检查nvidia驱动是否有问题,nvidia-smi是否有输出
(2)切换到nvidia渲染

sudo prime-select nvidia

如果报错说明显卡驱动安装有问题,
手动安装显卡驱动时很多人加了,-no-x-check -no-nouveau-check -no-opengl-files,这样安装有问题
如果没有报错重启就可以解决了,然后跳到步骤(5)
(3)安装opengl

sudo apt-get update
sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dri libglu1-mesa freeglut3 nvidia-driver nvidia-settings nvidia-prime

(4)重装显卡驱动

sudo bash NVIDIA-Linux-x86_64-575.57.08.run --uninstall
或
sudo apt-get purge nvidia-*  # 只有包管理器安装的才有效
sudo bash NVIDIA-Linux-x86_64-575.57.08.run 

然后重启

(5) 检查opengl
然后就可以看到opengl正常

glxinfo | grep "OpenGL vendor"

OpenGL vendor string: NVIDIA Corporation

glxinfo | grep "OpenGL renderer"
OpenGL renderer string: NVIDIA GeForce RTX 4070 Ti SUPER/PCIe/SSE2

再运行pcd_demo就有显示

3. 附加新版nvidia驱动安装失败解决办法

安装报错可以查看/var/log/nvidia-installer.log
大致内容是需要gcc12这个版本,但系统自带gcc11

1.安装gcc12

sudo apt update
sudo apt install gcc-12 g++-12

2.查看所有版本

ls /usr/bin/gcc*  # 查看所有 gcc 版本
ls /usr/bin/g++*  # 查看所有 g++ 版本

3.切换11->12

删除所有 gcc 和 g++ 的备选项(重置配置)
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

注册 gcc-11 和 gcc-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 90

注册 g++-11 和 g++-12
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 90
sudo update-alternatives --config gcc #会有选项0-2,选择你需要的版本

如下:

There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-12   90        auto mode
  1            /usr/bin/gcc-11   100       manual mode
  2            /usr/bin/gcc-12   90        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1  # 输入 1 选择 gcc-11
sudo update-alternatives --config g++

g++同理

❯ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值