pjreddie / darknet

Convolutional Neural Networks
http://pjreddie.com/darknet/
Other
25.75k stars 21.33k forks source link

Python API #928

Open karanmartian opened 6 years ago

karanmartian commented 6 years ago

Hi,

Is there any way to write wrapper / API in python for yolo darknet? Basically I want to do things like object counting, updating a custom GUI with classes that are detected etc. by taking the output of YOLO. I don't want to use darkflow because its much slower than darknet on my setup.

sharowyeh commented 6 years ago

The python code which pjreddie provided works fine already, you can find them at python folder and detect file for prediction. Or using my fork if implemented functions meet your requirement.

karanmartian commented 6 years ago

Thanks @sharowyeh but I am getting this error while executing: I am running a miniconda python 3.6 with opencv 3.4.1

python detector-scipy-opencv.py Traceback (most recent call last): File "detector-scipy-opencv.py", line 4, in from darknet_libwrapper import * File "/home/karan/darknet/darknet_libwrapper.py", line 59, in lib = ctypes.CDLL(lib_path, ctypes.RTLD_LOCAL) File "/home/karan/miniconda3/envs/tf/lib/python3.6/ctypes/init.py", line 348, in init self._handle = _dlopen(self._name, mode) OSError: /usr/lib/libgdal.so.20: undefined symbol: sqlite3_column_table_name

sharowyeh commented 6 years ago

@karanmartian It only tested in Python2.7, and still working on fix issues from ctypes implementation in 3.6.

karanmartian commented 6 years ago

@sharowyeh fixed the error. Would you have any example for reading / performing detections on Video file?

karanmartian commented 6 years ago

I just wrote python code for video detections. but its kind of running slow. I was thinking of using this code instead in yolo_console_dll.cpp but getting this error. Have you encountered this before?

(tf) karan@karan-LinuxTP:~/al/darknet/src$ g++ yolo_console_dll.cpp /tmp/cc4RfFu5.o: In function main': yolo_console_dll.cpp:(.text+0x60b): undefined reference toDetector::Detector(std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, int)' yolo_console_dll.cpp:(.text+0x734): undefined reference to Detector::load_image(std::__cxx11::basic_string<char, std::char_traits, std::allocator >)' yolo_console_dll.cpp:(.text+0x77c): undefined reference toDetector::detect(image_t, float, bool)' yolo_console_dll.cpp:(.text+0x79b): undefined reference to Detector::free_image(image_t)' yolo_console_dll.cpp:(.text+0x85b): undefined reference toDetector::~Detector()' yolo_console_dll.cpp:(.text+0xad4): undefined reference to `Detector::~Detector()' collect2: error: ld returned 1 exit status

sharowyeh commented 6 years ago

It is recommended that using AlexeyAB's repository for this c++ file modification.

laksh-lp commented 6 years ago

@karanmartian Could you share python code for video detection ??

sharowyeh commented 6 years ago

Updated in my repo, quick represent video detection function with python code wrapped from libdarknet.so. Using python darknet.py detector demo <data> <cfg> <weight> <cam_index> <video_file_path>

deimsdeutsch commented 6 years ago

@sharowyeh Getting compilation errors on your build. I suggest you take a look at them as some files are missing.

Project: libdarknet.sln

sharowyeh commented 6 years ago

@deimsdeutsch Thank you for reminding me :)

And the issue feature of my project has been opened.

shuoyuanxu commented 5 years ago

Hi guys, I just tested the official python wrapper, I was wondering if it is normal for the python wrapper to be a little slower than the original code.

Mine GTX1050 gives me 0.08s for the dog demo on original code, and average 0.106 for python on the same resolution video.

vitosaver commented 5 years ago

@shuoyuanxu I have the same problem when I am running from terminal I get 60 FPS and when I am running from python I am getting 50 FPS which is a big difference if you scale it.

Can maybe someone explain why is this happening?

vinnadipo09 commented 5 years ago

Thanks @sharowyeh but I am getting this error while executing:

I am running a miniconda python 3.6 with opencv 3.4.1 python detector-scipy-opencv.py Traceback (most recent call last): File "detector-scipy-opencv.py", line 4, in from darknet_libwrapper import * File "/home/karan/darknet/darknet_libwrapper.py", line 59, in lib = ctypes.CDLL(lib_path, ctypes.RTLD_LOCAL) File "/home/karan/miniconda3/envs/tf/lib/python3.6/ctypes/init.py", line 348, in init self._handle = _dlopen(self._name, mode) OSError: /usr/lib/libgdal.so.20: undefined symbol: sqlite3_column_table_name

Has anyone found a solution to this? I have been battling with the issue for quite some time.

18310837090 commented 3 years ago

Thanks @sharowyeh but I am getting this error while executing:

I am running a miniconda python 3.6 with opencv 3.4.1 python detector-scipy-opencv.py Traceback (most recent call last): File "detector-scipy-opencv.py", line 4, in from darknet_libwrapper import * File "/home/karan/darknet/darknet_libwrapper.py", line 59, in lib = ctypes.CDLL(lib_path, ctypes.RTLD_LOCAL) File "/home/karan/miniconda3/envs/tf/lib/python3.6/ctypes/init.py", line 348, in init self._handle = _dlopen(self._name, mode) OSError: /usr/lib/libgdal.so.20: undefined symbol: sqlite3_column_table_name

Has anyone found a solution to this? I have been battling with the issue for quite some time.

I also have this problem