darknet-nnpack icon indicating copy to clipboard operation
darknet-nnpack copied to clipboard

issue with darknet-nnpack python library

Open ligc opened this issue 6 years ago • 19 comments

HI,

I am trying to run detection on multiple images (currently static images, will be image snapshots from a video in the future) on my Raspberry PI 3, the CLI works great and I get the same result 1.3s/image as claimed, but because the CLI needs to load the network and metadata every time, it slows down the detection, so I wrote the following python script to automate the images detection without needing to load the network and metadata every time:

#!/usr/bin/python

import sys
import os.path

sys.path.append("python")

import darknet

yolo_net = darknet.load_net("cfg/tiny-yolo-voc.cfg",
                    "tiny-yolo-voc.weights",0)
yolo_meta = darknet.load_meta("cfg/voc.data")

list = os.listdir("data")
for i in range(0,len(list)):
    imagename = os.path.join("data",list[i])
    if os.path.isfile(imagename):
        if os.path.splitext(imagename)[1] == ".jpg":
            print "Detecting image %s" % imagename
            res = darknet.detect(yolo_net, yolo_meta, imagename)
            print res

I put the python script under darknet-nnpack directory, and update the darknet-nnpack/python/darknet.py with the following line:

lib = CDLL("/root/darknet-nnpack/libdarknet.so", RTLD_GLOBAL)

The python script runs correctly with the upstream darknet(https://github.com/pjreddie/darknet), but as expected, it runs terribly slow(40s+/image) and does not work for my scenario.

The python script could not be run with the darknet-nnpack, with the following error:

root@rpi-3:~/darknet-nnpack# ./test.py
Traceback (most recent call last):
  File "./test.py", line 8, in <module>
    import darknet
  File "python/darknet.py", line 37, in <module>
    lib = CDLL("/root/darknet-nnpack/libdarknet.so", RTLD_GLOBAL)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /root/darknet-nnpack/libdarknet.so: undefined symbol: nnp_convolution_inference
root@rpi-3:~/darknet-nnpack#

I feel that some compile options will be needed to static link the nnpack library into libdarknet.so, or some environment variable to point to the NNPACK-darknet, but I was not able to figure it out.

Any suggestion on how I could move forward will be highly appreciated.

ligc avatar Nov 21 '17 02:11 ligc