【从零开始部署SAM(Segment Anything Model )大模型 3 Ubuntu20 离线部署 C++】-运行

cmakelist

cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 17)

project(SamCPP)

find_package(OpenCV CONFIG REQUIRED)
find_package(gflags CONFIG REQUIRED)

set(ONNXRUNTIME_ROOT_DIR /home/ubuntu/onnxruntime-linux-x64-gpu-1.14.1)

add_library(sam_cpp_lib SHARED sam.h sam.cpp click_sample.cpp)
set(onnxruntime_lib ${ONNXRUNTIME_ROOT_DIR}/lib/libonnxruntime.so)
target_include_directories(sam_cpp_lib PRIVATE ${ONNXRUNTIME_ROOT_DIR}/include)
target_link_libraries(sam_cpp_lib PRIVATE
  ${onnxruntime_lib}
  ${OpenCV_LIBS}
)

add_executable(sam_cpp_test test.cpp)
target_link_libraries(sam_cpp_test PRIVATE
  sam_cpp_lib
  ${OpenCV_LIBS}
  gflags
)

缺啥按啥

更改test.cpp中的路径:

DEFINE_string(pre_model, "models/mobile_sam_preprocess.onnx", "Path to the preprocessing model");
DEFINE_string(sam_model, "models/mobile_sam.onnx", "Path to the sam model");
DEFINE_string(image, "images/input.jpg", "Path to the image to segment");
DEFINE_string(pre_device, "cpu", "cpu or cuda:0(1,2,3...)");
DEFINE_string(sam_device, "cpu", "cpu or cuda:0(1,2,3...)");

确保以上路径都正确且可以访问到文件
在项目主文件夹内打开终端

编译

mkdir build
cd build
cmake ..
make -j2
cd ..
./build/sam_cpp_test
上一篇:【K8s】专题四(2):Kubernetes 控制器之 Deployment


下一篇:1. tomcat