UNeedCryDear / yolov8-opencv-onnxruntime-cpp

yolov8 hub,cpp with onnxruntime and opencv
Apache License 2.0
282 stars 53 forks source link

Error while compiling "fatal error: onnxruntime_cxx_api.h: No such file or directory" #8

Closed madinwei closed 1 year ago

madinwei commented 1 year ago

Hello 你好@UNeedCryDear ,

thank you for this amazing repository. While I was compiling I encountered the following ERROR:

$ make
[ 14%] Building CXX object CMakeFiles/YOLOv8.dir/main.cpp.o
In file included from /home/mad/yolov8-opencv-onnxruntime-cpp/main.cpp:6:0:
/home/mad/yolov8-opencv-onnxruntime-cpp/yolov8_onnx.h:6:32: fatal error: onnxruntime_cxx_api.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/YOLOv8.dir/build.make:76: CMakeFiles/YOLOv8.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/YOLOv8.dir/all] Error 2

To my knowledge, the error means that the Onnx lib is not installed, however, I have already installed it by downloading onnxruntime-linux-x64-gpu-1.9.0.tgz and unzip it in the /usr/local folder.

I am still novice, so any help or advice will be valuable for me. looking forward to your response

UNeedCryDear commented 1 year ago

cmakelists Set onnxruntime ROOT_PATH and try again. I am not good at deploying it on Linux. If this doesn't work, add the onnxruntime link library to the system environment variable like configuring the cuda.

madinwei commented 1 year ago

太感谢了 @UNeedCryDear , I just set my path and compile and it worked fine. with that, I will close this issue. However, I have a couple of questions about this issue.

  1. after compiling only yolov8 is produced only, and I need yolov8-seg is there a way to compile it too?
  2. is there any way to use the C++ code without the need to compile it? since you are not good at it ^_^
UNeedCryDear commented 1 year ago
  1. 编译后只生产 yolov8,我需要 yolov8-seg 有没有办法编译它?
  2. 有没有办法在不需要编译的情况下使用C++代码?因为你不擅长 ^_^
  1. https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/blob/4b90bf0c3d86d67faf1a3683ccace79163b7c16d/CMakeLists.txt#L10

项目名字叫yolov8,实际上包括了yolov8和yolov8-seg,这两者又分别包括了opencv和onnxruntime两个版本。你可以通过修改这里的链接只编译其中一种组合(例如yolov8+onnxruntime),然后修改mian.cpp中的调用为yolov8+onnxruntime的调用,最后重新编译。

  1. 不编译情况无法使用,c++本身就是编译型语言,不像python为解释型语言可以不编译使用。
madinwei commented 1 year ago

@UNeedCryDear , thank you for your help and response.

I hope I didn't bother you, but I have another problem. even though my build is successful the yolov8 is not implementing:

~/yolov8-opencv-onnxruntime-cpp/build$ ./YOLOv8 
************* Infer model on CPU! *************
read net ok!
Segmentation fault (core dumped)

as you see after I call YOLOv8 no detection happened, I checked my compiling but there was no error :

~/yolov8-opencv-onnxruntime-cpp/build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mad/yolov8-opencv-onnxruntime-cpp/build
~/yolov8-opencv-onnxruntime-cpp/build$ make
Consolidate compiler generated dependencies of target YOLOv8
[ 14%] Building CXX object CMakeFiles/YOLOv8.dir/main.cpp.o
[ 28%] Linking CXX executable YOLOv8
[100%] Built target YOLOv8

I also make sure my path to my models and test image is right, so I have no clue what's going on , if you have any helpful tips I will appreciate it

madinwei commented 1 year ago

I have solved it by modifying _className to my number of class

@UNeedCryDear , thank you for your help and response.

I hope I didn't bother you, but I have another problem. even though my build is successful the yolov8 is not implementing:

~/yolov8-opencv-onnxruntime-cpp/build$ ./YOLOv8 
************* Infer model on CPU! *************
read net ok!
Segmentation fault (core dumped)

as you see after I call YOLOv8 no detection happened, I checked my compiling but there was no error :

~/yolov8-opencv-onnxruntime-cpp/build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mad/yolov8-opencv-onnxruntime-cpp/build
~/yolov8-opencv-onnxruntime-cpp/build$ make
Consolidate compiler generated dependencies of target YOLOv8
[ 14%] Building CXX object CMakeFiles/YOLOv8.dir/main.cpp.o
[ 28%] Linking CXX executable YOLOv8
[100%] Built target YOLOv8

I also make sure my path to my models and test image is right, so I have no clue what's going on , if you have any helpful tips I will appreciate it