Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问darknet的python接口更新后,make_boxes...这几个函数用什么替代? #679

Open
notobject opened this issue Apr 11, 2018 · 7 comments

Comments

@notobject
Copy link

notobject commented Apr 11, 2018

file: examples/detector-scipy-opencv.py

# Stupid python path shit.
# Instead just add darknet.py to somewhere in your python path
# OK actually that might not be a great idea, idk, work in progress
# Use at your own risk. or don't, i don't care

from scipy.misc import imread
import cv2
import sys, os
sys.path.append(os.path.join(os.getcwd(),'python/'))
import darknet as dn

def array_to_image(arr):
    arr = arr.transpose(2,0,1)
    c = arr.shape[0]
    h = arr.shape[1]
    w = arr.shape[2]
    arr = (arr/255.0).flatten()
    data = dn.c_array(dn.c_float, arr)
    im = dn.IMAGE(w,h,c,data)
    return im

def detect2(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45):
    boxes = dn.make_boxes(net)
    probs = dn.make_probs(net)
    num =   dn.num_boxes(net)
    dn.network_detect(net, image, thresh, hier_thresh, nms, boxes, probs)
    res = []
    for j in range(num):
        for i in range(meta.classes):
            if probs[j][i] > 0:
                res.append((meta.names[i], probs[j][i], (boxes[j].x, boxes[j].y, boxes[j].w, boxes[j].h)))
    res = sorted(res, key=lambda x: -x[1])
    dn.free_ptrs(dn.cast(probs, dn.POINTER(dn.c_void_p)), num)
    return res



# Darknet
net = dn.load_net("cfg/yolov3.cfg", "yolov3.weights", 0)
meta = dn.load_meta("cfg/coco.data")
# r = dn.detect(net, meta, "data/dog.jpg")
# print r

# scipy
# arr= imread('data/dog.jpg')
# im = array_to_image(arr)
# r = detect2(net, meta, im)
# print r

# OpenCV
cap = cv2.VideoCapture(1)
while True:
    rect,frame = cap.read()
    im = array_to_image(frame)
    dn.rgbgr_image(im)
    r = detect2(net, meta, im)
    cv2.imshow("Demo",frame)
    print r

Error Messgae

.....
.....
Loading weights from yolov3.weights...Done!
Traceback (most recent call last):
  File "examples/detector-scipy-opencv.py", line 56, in <module>
    r = detect2(net, meta, im)
  File "examples/detector-scipy-opencv.py", line 23, in detect2
    boxes = dn.make_boxes(net)
AttributeError: 'module' object has no attribute 'make_boxes'
@lwplw
Copy link

lwplw commented Apr 12, 2018

同问

...
Traceback (most recent call last):
File "ship_demo.py", line 5, in
import darknet as dn
File "/media/lwp/lwplw/lwptuthinkjoy/demo/darknet.py", line 116, in
make_boxes = lib.make_boxes
File "/home/lwp/lwptuapp/anaconda3/lib/python3.6/ctypes/init.py", line 361, in getattr
func = self.getitem(name)
File "/home/lwp/lwptuapp/anaconda3/lib/python3.6/ctypes/init.py", line 366, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: libdarknet.so: undefined symbol: make_boxes

@khaerulumam42
Copy link

Are you try recompile with #289 ? Maybe @TheMikeyR post that code just for previous version. I tried like you do too, and get the same error.

Hello @TheMikeyR :)

@lwplw
Copy link

lwplw commented Apr 12, 2018

darknet.py文件中,我最后这样改写的
...

def detect(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45):
    im = load_image(image, 0, 0)
    num = c_int(0)
    pnum = pointer(num)
    predict_image(net, im)
    dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum)
    num = pnum[0]
    if (nms): do_nms_obj(dets, num, meta.classes, nms)
    res = []
    for j in range(num):
        for i in range(meta.classes):
            if dets[j].prob[i] > 0:
                b = dets[j].bbox
                res.append((meta.names[i], dets[j].prob[i], (b.x, b.y, b.w, b.h)))
    res = sorted(res, key=lambda x: -x[1])
    free_image(im)
    free_detections(dets, num)
    return res

def detect_np(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45):
    im = array_to_image(image)
    num = c_int(0)
    pnum = pointer(num)
    predict_image(net, im)
    dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum)
    num = pnum[0]
    if (nms): do_nms_obj(dets, num, meta.classes, nms)
    res = []
    for j in range(num):
        for i in range(meta.classes):
            if dets[j].prob[i] > 0:
                b = dets[j].bbox
                res.append((meta.names[i], dets[j].prob[i], (b.x, b.y, b.w, b.h)))
    res = sorted(res, key=lambda x: -x[1])
    free_image(im)
    free_detections(dets, num)
    return res

...
array_to_image()是参考的/examples/detector-scipy-opencv.py中的:

def array_to_image(arr):
    arr = arr.transpose(2,0,1)
    c = arr.shape[0]
    h = arr.shape[1]
    w = arr.shape[2]
    arr = (arr/255.0).flatten()
    data = dn.c_array(dn.c_float, arr)
    im = dn.IMAGE(w,h,c,data)
    return im

所以没有再用到make_boxes...这几个函数,现在报错是这样的:
Loading weights from ship_classifier/shipcla_421.weights...Done!
*** Error in `python': double free or corruption (top): 0x000055cf89c15920 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fe48fc057e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fe48fc0e37a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fe48fc1253c]
/home/lwp/lwptuapp/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0xc06d)[0x7fe48d64806d]
python(+0x19dba6)[0x55cef8ecbba6]
python(+0xef0da)[0x55cef8e1d0da]

@TheMikeyR
Copy link

It seems like the python wrapper haven't been updated with yolov3 implementation, it still works with yolov2. When I run it, it doesn't recognize the new layer types.

python webcam.py
Frames per second using video.get(cv2.CAP_PROP_FPS) : 30.0
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32
    1 conv     64  3 x 3 / 2   416 x 416 x  32   ->   208 x 208 x  64
    2 conv     32  1 x 1 / 1   208 x 208 x  64   ->   208 x 208 x  32
    3 conv     64  3 x 3 / 1   208 x 208 x  32   ->   208 x 208 x  64
    4 Shortcut Layer: 1
    5 conv    128  3 x 3 / 2   208 x 208 x  64   ->   104 x 104 x 128
    6 conv     64  1 x 1 / 1   104 x 104 x 128   ->   104 x 104 x  64
    7 conv    128  3 x 3 / 1   104 x 104 x  64   ->   104 x 104 x 128
    8 Shortcut Layer: 5
    9 conv     64  1 x 1 / 1   104 x 104 x 128   ->   104 x 104 x  64
   10 conv    128  3 x 3 / 1   104 x 104 x  64   ->   104 x 104 x 128
   11 Shortcut Layer: 8
   12 conv    256  3 x 3 / 2   104 x 104 x 128   ->    52 x  52 x 256
   13 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   14 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   15 Shortcut Layer: 12
   16 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   17 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   18 Shortcut Layer: 15
   19 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   20 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   21 Shortcut Layer: 18
   22 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   23 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   24 Shortcut Layer: 21
   25 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   26 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   27 Shortcut Layer: 24
   28 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   29 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   30 Shortcut Layer: 27
   31 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   32 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   33 Shortcut Layer: 30
   34 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128
   35 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256
   36 Shortcut Layer: 33
   37 conv    512  3 x 3 / 2    52 x  52 x 256   ->    26 x  26 x 512
   38 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   39 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   40 Shortcut Layer: 37
   41 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   42 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   43 Shortcut Layer: 40
   44 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   45 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   46 Shortcut Layer: 43
   47 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   48 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   49 Shortcut Layer: 46
   50 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   51 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   52 Shortcut Layer: 49
   53 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   54 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   55 Shortcut Layer: 52
   56 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   57 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   58 Shortcut Layer: 55
   59 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256
   60 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512
   61 Shortcut Layer: 58
   62 conv   1024  3 x 3 / 2    26 x  26 x 512   ->    13 x  13 x1024
   63 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   64 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   65 Shortcut Layer: 62
   66 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   67 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   68 Shortcut Layer: 65
   69 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   70 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   71 Shortcut Layer: 68
   72 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   73 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   74 Shortcut Layer: 71
   75 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   76 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   77 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   78 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   79 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512
   80 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024
   81 conv     75  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x  75
   82 Type not recognized: [yolo]
Unused field: 'mask = 6,7,8'
Unused field: 'anchors = 10,13,16,30,33,23,30,61,62,45,59,119,116,90,156,198,373,326'
Unused field: 'classes = 20'
Unused field: 'num = 9'
Unused field: 'jitter = .3'
Unused field: 'ignore_thresh = .5'
Unused field: 'truth_thresh = 1'
Unused field: 'random = 1'
   83 route  79
   84 conv    256  1 x 1 / 1    13 x  13 x 512   ->    13 x  13 x 256
   85 Type not recognized: [upsample]
Unused field: 'stride = 2'
   86 route  85 61
   87 python: [1]    16910 segmentation fault (core dumped)  python webcam.py

@mcximing
Copy link

mcximing commented Apr 18, 2018

Hello @lwplw,

I think the "double free" error is caused by the "free_image(im)" in the last of your "detect_np" function. Since the data of image here is managed by numpy, there is no need to free it as the original function does, or you will get the “double free” error. I deleted this "free_image(im)" and got a correct output. But I'm not sure if this will cause a memory leak. (一句话来说,我觉得是那个 free_image 重复释放了内存,导致你那个错误,我这删掉没报错)

@iloveOREO
Copy link

Hello @lwplw,

I think the "double free" error is caused by the "free_image(im)" in the last of your "detect_np" function. Since the data of image here is managed by numpy, there is no need to free it as the original function does, or you will get the “double free” error. I deleted this "free_image(im)" and got a correct output. But I'm not sure if this will cause a memory leak. (一句话来说,我觉得是那个 free_image 重复释放了内存,导致你那个错误,我这删掉没报错)

Thank you very much! It bothered me for few hours.
It did work for the "double free " problem.

@jiagh2010
Copy link

finally ,HOW TO SOLVE????_-------->>>>makebox error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants