bennetthardwick / darknet.js

A NodeJS wrapper of pjreddie's darknet / yolo.
65 stars 27 forks source link

Dependencie node-ffi is not working on ARM64 #20

Closed MaDumont closed 5 years ago

MaDumont commented 5 years ago

Hi,

I'm trying to install the project on a jetson tx2 (arm64). I get that the dependence node-ffi can't be install.

After testing a lot of things, I was able to install https://github.com/zsmweb/node-ffi-aarch64. I know it's not made for my architecture and I was not really surprise when darknet didn't work with it. (If you want the error I get I can give it to you)

I know it's not the issue of this project, but I would like to know if it's possible to replace the node-ffi with something else or a previous version that would work on my architecture.

Usually I would have ask the node-ffi community to help me with that but the issue have been known for more then a year and nothing really happen.

Thank you

bennetthardwick commented 5 years ago

Hey @MaDumont, if you could send through the errors you got that would be great.

Have you been able to get the darknet cli working on it's own? If that works I don't see any reason why we couldn't get darknet.js to work with little effort. Another thing to test would be the darknet python wrapper. If that doesn't work then it might be a little bit more difficult.

MaDumont commented 5 years ago

Hey thank you for the fast answer.

*The error when I try to install darknet. So the error while installing darknet:

../deps/libffi/src/x86/ffi.c:62:31: error: ‘FFI_TYPE_MS_STRUCT’ undeclared (first use in this function) || ecif->cif->flags == FFI_TYPE_MS_STRUCT) ^ ../deps/libffi/src/x86/ffi.c:62:31: note: each undeclared identifier is reported only once for each function it appears in ../deps/libffi/src/x86/ffi.c: In function ‘ffi_prep_cif_machdep’: ../deps/libffi/src/x86/ffi.c:262:24: error: ‘FFI_TYPE_SMALL_STRUCT_1B’ undeclared (first use in this function) cif->flags = FFI_TYPE_SMALL_STRUCT_1B; / same as char size / ^ ../deps/libffi/src/x86/ffi.c:266:24: error: ‘FFI_TYPE_SMALL_STRUCT_2B’ undeclared (first use in this function) cif->flags = FFI_TYPE_SMALL_STRUCT_2B; / same as short size / ^ ../deps/libffi/src/x86/ffi.c: In function ‘ffi_call’: ../deps/libffi/src/x86/ffi.c:359:28: error: ‘FFI_TYPE_MS_STRUCT’ undeclared (first use in this function) || cif->flags == FFI_TYPE_MS_STRUCT)) ^ ../deps/libffi/src/x86/ffi.c: At top level: ../deps/libffi/src/x86/ffi.c:431:6: warning: ‘regparm’ attribute directive ignored [-Wattributes] attribute ((regparm(1))); ^ ../deps/libffi/src/x86/ffi.c:433:6: warning: ‘regparm’ attribute directive ignored [-Wattributes] attribute ((regparm(1))); ^ ../deps/libffi/src/x86/ffi.c:435:6: warning: ‘regparm’ attribute directive ignored [-Wattributes] attribute ((regparm(1))); ^ ../deps/libffi/src/x86/ffi.c:482:1: warning: ‘regparm’ attribute directive ignored [-Wattributes] { ^ ../deps/libffi/src/x86/ffi.c: In function ‘ffi_prep_incoming_args_SYSV’: ../deps/libffi/src/x86/ffi.c:525:25: error: ‘FFI_TYPE_MS_STRUCT’ undeclared (first use in this function) || cif->flags == FFI_TYPE_MS_STRUCT ) { ^ ../deps/libffi/src/x86/ffi.c: In function ‘ffi_prep_closure_loc’: ../deps/libffi/src/x86/ffi.c:594:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] unsigned int fun = (unsigned int)(FUN); \ ^ ../deps/libffi/src/x86/ffi.c:667:7: note: in expansion of macro ‘FFI_INIT_TRAMPOLINE’ FFI_INIT_TRAMPOLINE (&closure->tramp[0], ^ ../deps/libffi/src/x86/ffi.c:595:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] unsigned int ctx = (unsigned int)(CTX); \ ^ ../deps/libffi/src/x86/ffi.c:667:7: note: in expansion of macro ‘FFI_INIT_TRAMPOLINE’ FFI_INIT_TRAMPOLINE (&closure->tramp[0], ^ ../deps/libffi/src/x86/ffi.c: In function ‘ffi_prep_raw_closure_loc’: ../deps/libffi/src/x86/ffi.c:594:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] unsigned int __fun = (unsigned int)(FUN); \ ^ ../deps/libffi/src/x86/ffi.c:740:3: note: in expansion of macro ‘FFI_INIT_TRAMPOLINE’ FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_raw_SYSV, ^ ../deps/libffi/src/x86/ffi.c:595:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] unsigned int __ctx = (unsigned int)(CTX); \ ^ ../deps/libffi/src/x86/ffi.c:740:3: note: in expansion of macro ‘FFI_INIT_TRAMPOLINE’ FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_raw_SYSV, ^ ../deps/libffi/src/x86/ffi.c: In function ‘ffi_raw_call’: ../deps/libffi/src/x86/ffi.c:782:28: error: ‘FFI_TYPE_MS_STRUCT’ undeclared (first use in this function) || cif->flags == FFI_TYPE_MS_STRUCT)) ^ deps/libffi/ffi.target.mk:117: recipe for target 'Release/obj.target/ffi/deps/libffi/src/x86/ffi.o' failed make: *** [Release/obj.target/ffi/deps/libffi/src/x86/ffi.o] Error 1 make: Leaving directory '/home/nvidia/nova_git/nodejs-rest-api/node_modules/ffi/build' gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23) gyp ERR! stack at ChildProcess.emit (events.js:198:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12) gyp ERR! System Linux 4.4.38 gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/nvidia/nova_git/nodejs-rest-api/node_modules/ffi gyp ERR! node -v v10.16.0 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok npm WARN nodejs-rest-api@1.0.0 No description

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ffi@2.3.0 install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ffi@2.3.0 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/nvidia/.npm/_logs/2019-07-11T11_46_14_464Z-debug.log

bennetthardwick commented 5 years ago

Not quite sure what's going on there. Was then when you were using the original ffi or when you changed it over to use ffi aarch64?

Using ffi was a bit of a hack to begin with, and hasn't worked exactly the way I expected. Just this evening I've been working on making darknet work as a C++ Node addon, so I'll let you know how that goes.

bennetthardwick commented 5 years ago

I've put out a beta version of darknet that doesn't use ffi, you can get it by running npm install darknet@beta. When you get a chance, can you test it and see if it works?

MaDumont commented 5 years ago

Not quite sure what's going on there. Was then when you were using the original ffi or when you changed it over to use ffi aarch64?

It was with the original ffi. Sorry for not being clear enough.

MaDumont commented 5 years ago

I've put out a beta version of darknet that doesn't use ffi, you can get it by running npm install darknet@beta. When you get a chance, can you test it and see if it works?

Just to say I really appreciate your help.

I just test it.

FATAL ERROR: Error::New napi_get_last_error_info 1: 0x8fc3b8 node::Abort() [nodejs] 2: 0x8fc3f8 [nodejs] 3: 0x8feaf4 [nodejs] 4: 0x909c30 napi_fatal_error [nodejs] 5: 0x7f480005e0 Napi::Error::ThrowAsJavaScriptException() const [/nodejs-rest-api/node_modules/darknet/build/Release/darknet.node] 6: 0x7f4800a8b0 Napi::Error::New(napi_env__) [/nodejs-rest-api/node_modules/darknet/build/Release/darknet.node] 7: 0x7f480085f0 Detector::detectImagePath(Napi::CallbackInfo const&) [/nodejs-rest-api/node_modules/darknet/build/Release/darknet.node] 8: 0x7f4800cf90 Napi::ObjectWrap::InstanceMethodCallbackWrapper(napi_env__, napi_callback_info__*) [/nodejs-rest-api/node_modules/darknet/build/Release/darknet.node] 9: 0x907464 [nodejs] 10: 0xb6d480 [nodejs] 11: 0xb6de64 v8::internal::Builtin_HandleApiCall(int, v8::internal::Object*, v8::internal::Isolate) [nodejs] 12: 0x3f3637cc Aborted (core dumped)

MaDumont commented 5 years ago

Hey @MaDumont, if you could send through the errors you got that would be great.

Have you been able to get the darknet cli working on it's own? If that works I don't see any reason why we couldn't get darknet.js to work with little effort. Another thing to test would be the darknet python wrapper. If that doesn't work then it might be a little bit more difficult.

Also, I managed to make work the darknet python wrapper. It was not working because of path issue, but now it's working great.

bennetthardwick commented 5 years ago

Sweet! It seems like the C++ addon version will work. I've only re-implemented the detection from a path at the moment, but will probably finish off the rest of the existing API this week.

MaDumont commented 5 years ago

That's what I thought. That's perfect for me.

bennetthardwick commented 5 years ago

I've added support for opencv4nodejs Mat objects in darknet@2.0.6. I haven't done extensive testing just yet, but it seems to work. Let me know if it works for you.

MaDumont commented 5 years ago

frame = cv.imread('data/dog.jpg'); detections = darknet.detect({ b: frame.getData(), w: frame.cols, h: frame.rows, c: frame.channels });

When I try to execute that, I get the error:

nodejs-rest-api/node_modules/darknet/darknet.js:96 throw new Error('Could not get valid image from input!'); ^

Error: Could not get valid image from input! at Darknet.detect (nodejs-rest-api/node_modules/darknet/darknet.js:96:23) at Object. (nodejs-rest-api/yolov3-tiny.js:29:23) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:829:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

So on my side, it not like the type of image I give to the detector but I'm not sure why.

bennetthardwick commented 5 years ago

Good catch! Until I fix that you should be able to just do darknet.detect(frame).

MaDumont commented 5 years ago

I've added support for opencv4nodejs Mat objects in darknet@2.0.6. I haven't done extensive testing just yet, but it seems to work. Let me know if it works for you.

Hi,

I got an other error. I tried to activate gpu and cudnn. The installation is working but when I try to use it and I get this error:

internal/modules/cjs/loader.js:805 return process.dlopen(module, path.toNamespacedPath(filename)); ^

Error: /nodejs-rest-api/node_modules/darknet/build/Release/darknet.node: undefined symbol: __cudaRegisterFatBinary at Object.Module._extensions..node (internal/modules/cjs/loader.js:805:18) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (nodejs-rest-api/node_modules/darknet/darknet.js:4:22) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) [nodemon] app crashed - waiting for file changes before starting...

bennetthardwick commented 5 years ago

Finally managed to find an old nvidia GPU and get cuda working. I've updated darknet@beta for you to test.

MaDumont commented 5 years ago

I'm not sure if it was a typo to use the beta version (2.0.6). Because I already tested that version.

So I tested with the version 2.0.10 the latest version and it work. I can use the GPU and CUDNN activated now. It's really saving my life.

Thank you for the fast upgrade.

bennetthardwick commented 5 years ago

Great! I'm glad it worked.