AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.65k stars 7.96k forks source link

How to use darknet.so as library in c++ project on ubuntu? #2534

Open SarchWu opened 5 years ago

SarchWu commented 5 years ago

Hello,AlexeyAB: I have accomplished my own c++ project which could detect object by including yolov2class.hpp and dll on Windows.Now i want to transfer my code from windows to ubuntu.But im not familiar with linux.I have compiled darknet with cuda and cudnn,also,I have generated darknet.so.When the project tried include darknet.so,it could be included,but when the program init the constructor,ie :detector. It occurs cuda error. ./src/cuda.c:36: check_error: Assertion `0' failed. i'm not sure why could this error occur?Maybe the cmakelist.txt of my project is not correct. so,would you tell me how to write the cmakelist.txt of part about including darknet.so in ? or,it might be the cuda include error in cmakelist.txt? thanks for your help

AlexeyAB commented 5 years ago

@SarchWu Hi,

Did you compile Darknet with GPU=1 CUDNN=1 LIBSO=1 in the Makefile by using make ?

You can find the simplest Cmake example here to use libdarknet.so library: https://github.com/stereolabs/zed-yolo/blob/master/zed_cpp_sample/CMakeLists.txt#L28


I have generated darknet.so.

Currently it is libdarknet.so instead of darknet.so

https://github.com/AlexeyAB/darknet/blob/master/Makefile#L50

SarchWu commented 5 years ago

yes,i compiled with gpu1,cudnn1,libso1 in the makefile.I forked your project almost in July last year.so might generate darknet.so .I will tried the libdarknet tomorrow.thank you

rniebecker commented 5 years ago

Hi, just rename darknet.so to libdarknet .so and link with -ldarknet, that works for me.

Make sure libdarknet.so is in a standard libs folder (like /usr/lib on Ubuntu) and call ldconfig so the system can find the lib dynamically.

Cheers, Ralf

SarchWu commented 5 years ago

Hi, just rename darknet.so to libdarknet .so and link with -ldarknet, that works for me.

Make sure libdarknet.so is in a standard libs folder (like /usr/lib on Ubuntu) and call ldconfig so the system can find the lib dynamically.

Cheers, Ralf

HI,miebecker i tried your method.Now the system could find the lib.But it still not worked for me.The error ./src/cuda.c:36: check_error: Assertion `0' failed still exists.

ivder commented 5 years ago

Is it possible to use libdarknet.so using gcc?

SarchWu commented 5 years ago

Is it possible to use libdarknet.so using gcc?

I compiled with g++. I copied the libdarknet.so to the directory exe ,and run the program with sudo. So the problem had been solved.

ivder commented 5 years ago

@SarchWu really? Can you show me your project tree structure? I keep failing to compile using g++

SarchWu commented 5 years ago

@SarchWu really? Can you show me your project tree structure? I keep failing to compile using g++

you mean compiling what? my project or darknet?I compiling darknet using the makefile in the darknet_master.As to my project,i write my cmakelist and link the libdarknet.so. And then copy libdarknet.so in the darknet_master to the exe directory of my project

ivder commented 5 years ago

@SarchWu I mean compiling your project that using libdarknet.so . Can you show me your CMakeLists.txt ? I also having problem building using cmake

SarchWu commented 5 years ago

@SarchWu I mean compiling your project that using libdarknet.so . Can you show me your CMakeLists.txt ? I also having problem building using cmake

set(darknet_root " root_path_of_libdarknet") add_library(darknet SHARED IMPORTED) set_target_properties(darknet PROPERTIES IMPORTED_LOCATION "${darknet_root}/libdarknet.so") aux_source_directory(. srcs) add_executable(main ${srcs}) target_link_libraries(main darknet)

ivder commented 5 years ago

@SarchWu Thank you! Do you also use the C++ API (https://github.com/AlexeyAB/darknet/blob/master/include/yolo_v2_class.hpp)? Do we also need to copy that header file to our project include directory? Or can we link it directly using cmake? Sorry I'm kinda new in linux

SarchWu commented 5 years ago

@SarchWu Thank you! Do you also use the C++ API (https://github.com/AlexeyAB/darknet/blob/master/include/yolo_v2_class.hpp)? Do we also need to copy that header file to our project include directory? Or can we link it directly using cmake? Sorry I'm kinda new in linux

just copy the file to your project include directory

ivder commented 5 years ago

@SarchWu Thanks a lot for your help!