首先转换pytorch->onnx->param模型,这个过程可以查资料步骤有点多,参考blog.51cto.com/u_15660370/6408303,这里重点讲解转换后部署。
测试环境:
ubuntu18.04
opencv3.4.4(编译过程省略,参考我其他博客)
安装vulkan:
方式一(测试用的这个方法)
sudo apt-get install cmake git gcc g++ mesa-* libwayland-dev libxrandr-dev
sudo apt-get install libvulkan1 mesa-vulkan-drivers vulkan-utils libvulkan-dev
vulkaninfo
2.2 方式二
sudo apt-get install cmake git gcc g++ mesa-* libwayland-dev libxrandr-dev
sudo apt-get install libvulkan1 mesa-vulkan-drivers vulkan-utils libxcb-keysyms1-dev
sudo apt-get install libxcb1-dev libx11-dev
wget https://sdk.lunarg.com/sdk/download/1.2.162.1/linux/vulkansdk-linux-x86_64-1.2.162.1.tar.gz
mkdir vulkan
mv vulkansdk-linux-x86_64-1.2.162.1.tar.gz vulkan
cd vulkan
tar xf vulkansdk-linux-x86_64-1.2.162.1.tar.gz
# 下载github
cd 1.2.162.1/source/shaderc
python update_shaderc_sources.py
# 编译
cd 1.2.162.1
bash vulkansdk # 编译vulkan
source setup-env.sh # vulkan -> 系统环境变量
./x86_64/bin/vulkaninfo
2.3 方式三
git clone https://github.com/SaschaWillems/Vulkan.git
git submodule sync
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make
下载ncnn库:
https://github.com/Tencent/ncnn/releases/download/20230223/ncnn-20230223-ubuntu-1804-shared.zip 解压后,编写CMakeLists.txt
cmake_minimum_required(VERSION 2.8.0)
project(YOLOX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# 1.找ncnn的动态库,修改到自己下载的ncnn路径
set(ncnn_DIR /home/darknet/CM/10_device/ncnn-20230223-ubuntu-1804-shared/lib/cmake/ncnn)
find_package(ncnn REQUIRED)
# 2. opencv动态库
find_package(OpenCV REQUIRED)
add_executable(yolox yolox.cpp)
target_link_libraries(yolox ncnn ${OpenCV_LIBS})
注意这个CMakeLists.txt和yolox.cpp一起,yolox.cpp代码就在yolox官方源码demo/ncnn/cpp里面,然后编译
mkdir build && cd build
cmake ..
make -j
结果: