@pjreddie
Hi,
I have added numpy into the code to transform ndarrays to image, this avoids the need to write and read images before predictions. Do not know if you have a contrib repo but I just wanted to let you know since this might be helpful.
I'd love this addition! Could you add it as a pull request or make it public in some other way?
@Fred-Erik
Sure I pushed the changes here:
https://github.com/braca51e/nparray_image_darknet
Hope you make it work too and if you find any problems let me know please!
Thanks, will do!
Okay, I tried to get it to work but didn't manage it. How am I supposed to use it? I compiled DarkNet with your files added. Instead of using DarkNets load_image I used im = nparray_to_image(cv2.imread(image, 0)). But it only waits for a long time and ends in a segmentation fault. When I try to compile with DEBUG=1 I get these errors for every .o file:
libdarknet.a(reorg_layer.o): In function `_import_array':
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1451: undefined reference to `PyImport_ImportModule'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1455: undefined reference to `PyExc_ImportError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1455: undefined reference to `PyErr_SetString'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1458: undefined reference to `PyObject_GetAttrString'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1461: undefined reference to `PyExc_AttributeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1461: undefined reference to `PyErr_SetString'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1473: undefined reference to `PyCObject_Type'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1474: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1474: undefined reference to `PyErr_SetString'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1478: undefined reference to `PyCObject_AsVoidPtr'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1482: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1482: undefined reference to `PyErr_SetString'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1488: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1488: undefined reference to `PyErr_Format'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1494: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1494: undefined reference to `PyErr_Format'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1506: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1506: undefined reference to `PyErr_Format'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1517: undefined reference to `PyExc_RuntimeError'
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1517: undefined reference to `PyErr_Format'
Sorry to hear that. Yes you should replace the files and it should work. Here is the output I get:
Load Image [('dog', 0.8212552666664124, (218.2001495361328, 397.21099853515625, 220.81719970703125, 297.32769775390625)), ('car', 0.7433851957321167, (573.0895385742188, 127.70292663574219, 208.7532958984375, 92.79159545898438)), ('bicycle', 0.5871230363845825, (325.6228332519531, 291.4398498535156, 526.6577758789062, 295.44146728515625))]
Opencv Image [('dog', 0.8212552666664124, (218.2001495361328, 397.21099853515625, 220.81719970703125, 297.32769775390625)), ('car', 0.7433851957321167, (573.0895385742188, 127.70292663574219, 208.7532958984375, 92.79159545898438)), ('bicycle', 0.5871230363845825, (325.6228332519531, 291.4398498535156, 526.6577758789062, 295.44146728515625))]
However you might wanna check your numpy and python paths based on the error ouput, they are in the makefile in my case the paths are:
-I/usr/include/python2.7/ -I/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
-I/home/luis/opencv/include/opencv -I/home/luis/opencv/include/opencv2
Anyways attached is my darknet. I have created a branch called nparray you can check it. Let me know if you make it work!
You can check test.py inside the python folder.
I'm also using numpy version 1.13.1 opecv 3.3.0-dev
Hi @braca51e , great work !
I am just wondering if you noticed that detection time is about twice the time it takes at the original darknet of @pjreddie
The array_to_image function is a bottleneck in the detection. While the detection itself takes around 0.03 s on a GPU, the array_to_image operation, specifically the arr[:] = values takes around 0.6s. How can I make sure the latter operation runs on the GPU or does it already(if so then it's very slow)
Most helpful comment
Sorry to hear that. Yes you should replace the files and it should work. Here is the output I get:
Load Image [('dog', 0.8212552666664124, (218.2001495361328, 397.21099853515625, 220.81719970703125, 297.32769775390625)), ('car', 0.7433851957321167, (573.0895385742188, 127.70292663574219, 208.7532958984375, 92.79159545898438)), ('bicycle', 0.5871230363845825, (325.6228332519531, 291.4398498535156, 526.6577758789062, 295.44146728515625))]
Opencv Image [('dog', 0.8212552666664124, (218.2001495361328, 397.21099853515625, 220.81719970703125, 297.32769775390625)), ('car', 0.7433851957321167, (573.0895385742188, 127.70292663574219, 208.7532958984375, 92.79159545898438)), ('bicycle', 0.5871230363845825, (325.6228332519531, 291.4398498535156, 526.6577758789062, 295.44146728515625))]
However you might wanna check your numpy and python paths based on the error ouput, they are in the makefile in my case the paths are:
-I/usr/include/python2.7/ -I/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
-I/home/luis/opencv/include/opencv -I/home/luis/opencv/include/opencv2
darknet.tar.gz
Anyways attached is my darknet. I have created a branch called nparray you can check it. Let me know if you make it work!
You can check test.py inside the python folder.
I'm also using numpy version 1.13.1 opecv 3.3.0-dev