1 问题出现原因
场景:
需要把tensorflow的pb模型,先转为onnx模型,再转换成tensorrt的trt模型,使用的是:
- tensorflow2onnx:https://github.com/onnx/tensorflow-onnx
- onnx2tensorrt:https://github.com/onnx/onnx-tensorrt
在安装onnx2tensorrt的过程中,需要使用cmake
,由于我的版本比较低,因此需要升级cmake的版本
编译:
cmake .. -DTENSORRT_ROOT=../tensorrt_root && make -j
(yolov4) shl@zhihui-mint:~/shl_res/1_project/yolov4-deepsort/checkpoints/onnx-tensorrt/build$ cmake .. -DTENSORRT_ROOT=../tensorrt_root && make -j
CMake Error at CMakeLists.txt:21 (cmake_minimum_required):
CMake 3.13 or higher is required. You are running version 3.10.2
-- Configuring incomplete, errors occurred!
(yolov4) shl@zhihui-mint:~/shl_res/1_project/yolov4-deepsort/checkpoints/onnx-tensorrt/build$
2 升级cmake的版本
1、各种cmake版本安装包下载
Cmake Files Download:
https://cmake.org/files/
2、安装教程参考
我使用sudo apt-get install cmake
默认安装的是3.10.2
,我们这里编译要求cmake的版本至少是3.13以上
卸载旧版本的cmake
apt-get autoremove cmake
最好不要用上面的命令,直接把旧版本cmake所在的目录删除或移动到桌面备份也可以
上面的傻逼命令,会把之前安装的ros很多库包都删除了
,以后如果要卸载什么包,最好用命令:sudo apt remove package_name
,atutoremove
命令不要轻易用
sudo rm -rf /usr/bin/cmake
注意:
旧版本的cmake可以不用卸载的,所以上面的命令
也可以不用使用
,因为我在卸载旧版本的cmake的时候
,它自动把好多依赖都卸载了,把我的ROS系统也卸载了
,哎,只想说FK!
3、下载cmake的安装包,这里我下载的是3.16.8
wget https://cmake.org/files/v3.16/cmake-3.16.8-Linux-x86_64.tar.gz
注意:
cmake-3.16.8-Linux-x86_64.tar.gz压缩包里的文件是已经编译过的,解压就可以用!
4、解压
tar zxvf cmake-3.16.8-Linux-x86_64.tar.gz
5、建立软链接
sudo ln -s /home/shl/tools/cmake-3.16.8-Linux-x86_64/bin/cmake /usr/bin/cmake
软链接建立成功,就可以使用cmake了
(base) shl@zhihui-mint:~/tools$ sudo ln -s /home/shl/tools/cmake-3.16.8-Linux-x86_64/bin/cmake /usr/bin/cmake
(base) shl@zhihui-mint:~/tools$ cmake --version
cmake version 3.16.8
CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) shl@zhihui-mint:~/tools$
3 最简单的升级cmake命令的方法,直接使用pip
3.1 使用pip安装cmake的过程
1、可以用如下的方式,随便指定一个cmake的版本,查看cmake有哪些版本:
pip install cmake==23232
(base) shl@zhihui-mint:/opt/flameshot/build$ pip install cmake==323
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
ERROR: Could not find a version that satisfies the requirement cmake==323 (from versions: 0.1.0, 0.2.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.9.0, 3.6.3, 3.6.3.post1, 3.7.2, 3.8.2, 3.9.6, 3.10.3, 3.11.0, 3.11.4, 3.11.4.post1, 3.12.0, 3.13.0, 3.13.1, 3.13.2, 3.13.2.post1, 3.14.3, 3.14.3.post1, 3.14.4, 3.14.4.post1, 3.15.3, 3.15.3.post1, 3.16.3, 3.16.3.post1, 3.16.5, 3.16.6, 3.16.7, 3.16.8, 3.17.0, 3.17.1, 3.17.2, 3.17.3, 3.18.0, 3.18.2, 3.18.2.post1, 3.18.4, 3.18.4.post1, 3.20.2, 3.20.3)
ERROR: No matching distribution found for cmake==323
(base) shl@zhihui-mint:/opt/flameshot/build$
2、安装我们自己需要的cmake版本
pip install -U cmake==3.17.3
(base) shl@zhihui-mint:/opt/flameshot/build$ pip install -U cmake==3.17.3
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting cmake==3.17.3
Downloading cmake-3.17.3-py3-none-manylinux1_x86_64.whl (17.6 MB)
|████████████████████████████████| 17.6 MB 331 kB/s
Installing collected packages: cmake
Successfully installed cmake-3.17.3
(base) shl@zhihui-mint:/opt/flameshot/build$
3、查看安装好的cmake版本
cmake --version
如下,已经成功安装了指定的cmake的版本3.17.3
(base) shl@zhihui-mint:/opt/flameshot/build$ cmake --version
cmake version 3.17.3
3.2 编译的时候没有使用pip安装的cmake进行编译
当用cmake编译的时候用的还是系统中旧的cmake版本,我们需要把这个cmake指定为我们新安装的版本
(base) shl@zhihui-mint:/opt/flameshot/build$ sudo cmake ..
[sudo] password for shl:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.13 or higher is required. You are running version 3.10.2
-- Configuring incomplete, errors occurred!
(base) shl@zhihui-mint:/opt/flameshot/build$ cmake --version
cmake version 3.17.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) shl@zhihui-mint:/opt/flameshot/build$
1、删除之前旧的cmake版本
sudo rm -rf /usr/bin/cmake
(base) shl@zhihui-mint:/opt/flameshot/build$ ll /usr/bin/cmake
-rwxr-xr-x 1 root root 5325648 4月 4 22:10 /usr/bin/cmake*
(base) shl@zhihui-mint:/opt/flameshot/build$ sudo rm -rf /usr/bin/cmake
2、查看我们新安装cmake可执行文件路径
which cmake
(base) shl@zhihui-mint:/opt/flameshot/build$ which cmake
/home/shl/anaconda3/bin/cmake
(base) shl@zhihui-mint:/opt/flameshot/build$
3、把新安装的cmake建立系统cmake路径的软链接
sudo ln -s /home/shl/anaconda3/bin/cmake /usr/bin/cmake
(base) shl@zhihui-mint:/opt/flameshot/build$ sudo ln -s /home/shl/anaconda3/bin/cmake /usr/bin/cmake
之后就可以正确使用新的cmake版本进行编译了!