UNeedCryDear / yolov8-opencv-onnxruntime-cpp

yolov8 hub,cpp with onnxruntime and opencv
Apache License 2.0
277 stars 51 forks source link

源码编译make遇到的问题 #57

Open xufabs opened 1 week ago

xufabs commented 1 week ago

请问make的时候出现以下错误是什么问题呢?我想用它进行ONNXRUNTIME C++(CPU) 推理视频和图片

系统是Ubuntu24

onnxruntime是1.17的 opencv是4.5.3 在conda虚拟环境下编译的 g++是13.2.0

图片

/usr/bin/ld: CMakeFiles/YOLOv8.dir/main.cpp.o: in function int yolov8_onnx<Yolov8PoseOnnx>(Yolov8PoseOnnx&, cv::Mat&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': main.cpp:(.text._Z11yolov8_onnxI14Yolov8PoseOnnxEiRT_RN2cv3MatERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_Z11yolov8_onnxI14Yolov8PoseOnnxEiRT_RN2cv3MatERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x56): undefined reference toYolov8PoseOnnx::ReadModel(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, bool, int, bool)' /usr/bin/ld: main.cpp:(.text._Z11yolov8_onnxI14Yolov8PoseOnnxEiRT_RN2cv3MatERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_Z11yolov8_onnxI14Yolov8PoseOnnxEiRT_RN2cv3MatERKNSt7cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x1f1): undefined reference to Yolov8PoseOnnx::OnnxDetect(cv::Mat&, std::vector<OutputParams, std::allocator<OutputParams> >&)' /usr/bin/ld: CMakeFiles/YOLOv8.dir/main.cpp.o: in functionint video_demo(Yolov8PoseOnnx&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&)': main.cpp:(.text._Z10video_demoI14Yolov8PoseOnnxEiRT_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_Z10video_demoI14Yolov8PoseOnnxEiRT_RNSt7cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x204): undefined reference to Yolov8PoseOnnx::ReadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int, bool)' /usr/bin/ld: main.cpp:(.text._Z10video_demoI14Yolov8PoseOnnxEiRT_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_Z10video_demoI14Yolov8PoseOnnxEiRT_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x31d): undefined reference toYolov8PoseOnnx::OnnxDetect(cv::Mat&, std::vector<OutputParams, std::allocator >&)' /usr/bin/ld: CMakeFiles/YOLOv8.dir/yolov8.cpp.o: in function Yolov8::ReadModel(cv::dnn::dnn4_v20210608::Net&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)': yolov8.cpp:(.text+0x4a): undefined reference toCheckModelPath(std::cxx11::basic_string<char, std::char_traits, std::allocator >)' /usr/bin/ld: CMakeFiles/YOLOv8.dir/yolov8_onnx.cpp.o: in function Yolov8Onnx::ReadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int, bool)': yolov8_onnx.cpp:(.text+0x88): undefined reference toCheckModelPath(std::cxx11::basic_string<char, std::char_traits, std::allocator >)' /usr/bin/ld: yolov8_onnx.cpp:(.text+0x22e): undefined reference to OrtSessionOptionsAppendExecutionProvider_CUDA' /usr/bin/ld: CMakeFiles/YOLOv8.dir/yolov8_seg.cpp.o: in functionYolov8Seg::ReadModel(cv::dnn::dnn4_v20210608::Net&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >&, bool)': yolov8_seg.cpp:(.text+0x4a): undefined reference to CheckModelPath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' /usr/bin/ld: CMakeFiles/YOLOv8.dir/yolov8_seg_onnx.cpp.o: in functionYolov8SegOnnx::ReadModel(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, bool, int, bool)': yolov8_seg_onnx.cpp:(.text+0x88): undefined reference to `CheckModelPath(std::cxx11::basic_string<char, std::char_traits, std::allocator >)' /usr/bin/ld: yolov8_seg_onnx.cpp:(.text+0x230): undefined reference to `OrtSessionOptionsAppendExecutionProvider_CUDA' collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/YOLOv8.dir/build.make:234:YOLOv8] 错误 1 make[1]: [CMakeFiles/Makefile2:83:CMakeFiles/YOLOv8.dir/all] 错误 2 make: *** [Makefile:91:all] 错误 2

cmakelist如下

图片

UNeedCryDear commented 1 week ago

CheckModelPath() https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/blob/813aa9a2d970ea3f93d7db02d55f49b1058a5620/yolov8_utils.cpp#L13 这里面用到部分windows的函数(__access),linux下面没有,这个主要是检测模型路径对不对的,linux下面你可以换掉或者保证下模型路径正确的话可以不要

xufabs commented 1 week ago

图片 这段我已经注释掉了,还是有上面的问题,是不是其他地方引用了这段函数,需要一并注释掉?

xufabs commented 1 week ago

前面的编译我把函数里引用的都注释掉,编译通过了, 但是我把这段解开注释编译又有问题了orz

图片 图片

UNeedCryDear commented 1 week ago

如果你不要pose的话,把pose相关的头文件什么的都去掉,包括头文件include之类的,仅仅保留你需要的东西即可(cmake文件也把相关的去掉)

xufabs commented 1 week ago

好的,谢谢作者,我在cmakelist里增加上onnxpose.cpp文件就生成了YOLOV8文件了

xufabs commented 1 week ago

还有一个问题,如果要推理一段视频,需要将视频文件放在哪里呢?我看video demo 里没有传入视频路径?

xufabs commented 1 week ago

我发现那些类里onnx—detect的类是yolov8Poseonnx,无法识别我yolov8n.onnx的文件 图片

所以改用yolov8Onnx这个类,但是推理的效果不太理想,请问是有什么问题? 图片 图片

xufabs commented 1 week ago

图片

图片 补充一下,这是我用YOLOV8n POSE.onnx推理的效果 ONNX 1.14 onnxruntime C++ 1.15/1.17我都试过了,没有改善

xufabs commented 1 week ago

图片

图片 补充一下,这是我用YOLOV8n POSE.onnx推理的效果 ONNX 1.14 onnxruntime C++ 1.15/1.17我都试过了,没有改善

破案了,我重装了一下yolov8本体的环境就OK了,多谢作者! 之前图方便就conda克隆了yolov10的环境,然后转了onnx模型就出问题了

zhibin-hong commented 3 days ago

好的,谢谢作者,我在cmakelist里增加上onnxpose.cpp文件就生成了YOLOV8文件了

你好,请问在哪添加呢,我没有看到这个文件呀

xufabs commented 3 days ago

好的,谢谢作者,我在cmakelist里增加上onnxpose.cpp文件就生成了YOLOV8文件了

你好,请问在哪添加呢,我没有看到这个文件呀

在cmakelist文件里,那里有一行写了各种cpp和.h文件的,你把漏编译的cpp和.h 文件放进去就好了