snowzach / doods

DOODS - Dedicated Open Object Detection Service
MIT License
303 stars 31 forks source link

REALLY slow performance with Arm H3 #56

Closed 1ubuntuuser closed 2 years ago

1ubuntuuser commented 3 years ago

Hello, I started using doods with a H3 based board. As far as specs go, the H3 boards are comparable to a RasberryPi 3, but the performance was REALLY slow.

Pi 4 0.127 secs for 640*460 0.239241275 secs for 1500x1500

Pi 3+ 0.22891855 -0.240357849 secs for for 640*460 0.452125477 - 0.432114728 secs for 1500x1500

ARM H3 NanoPi 3.538851496 secs for for 640*460 9.828188412 secs for 1500x1500

1ubuntuuser commented 3 years ago

I tried to remove the raspberry pi flags from the dockerfile and rebuild but I got the following error. ERROR: /opt/tensorflow/tensorflow/core/kernels/BUILD:5991:1: C++ compilation of rule '//tensorflow/core/kernels:training_ops' failed (Exit 4)

1ubuntuuser commented 3 years ago

tried running docker build -t doods:local -f Dockerfile.arm32 . on the arm device itself but got.

dpkg: error processing archive bazel_2.0.0-linux-x86_64.deb (--install):
 package architecture (amd64) does not match system (armhf)

Any ideas?

snowzach commented 3 years ago

Is it running out of memory and swapping? How much memory does it have?

1ubuntuuser commented 3 years ago

EDIT: Switched to source code from the latest release instead of the head branch. docker make builds the image successfully now. Might be somthing wierd happening with the master branch.

Thanks for your response! Yep that was exactly right :) I found that yesterday. I have 16gb. I added --local_resources 8000,4,1 and it got through most of it! But then it hit the below. I didn't want to turn this thread into a long winded dialog of me trying to get a build done so I thought I would wait to hear if i was going in the right direction first.

docker make 
....
Step 41/55 : RUN make
....
# Compiling...
go build -ldflags "-X github.com/snowzach/doods/conf.Executable=doods -X github.com/snowzach/doods/conf.GitVersion=v0.2.6-0-gb2a1c53-dirty" -o doods
# gocv.io/x/gocv
In file included from features2d.cpp:1:0:
features2d.h:23:21: error: 'SIFT' is not a member of 'cv'
 typedef cv::Ptr<cv::SIFT>* SIFT;
                     ^~~~
features2d.h:23:21: error: 'SIFT' is not a member of 'cv'
features2d.h:23:25: error: template argument 1 is invalid
 typedef cv::Ptr<cv::SIFT>* SIFT;
                         ^
features2d.cpp: In function 'int* SIFT_Create()':
features2d.cpp:478:28: error: 'SIFT' is not a member of 'cv'
     return new cv::Ptr<cv::SIFT>(cv::SIFT::create());
                            ^~~~
features2d.cpp:478:28: note: suggested alternative:
In file included from features2d.cpp:1:0:
features2d.h:23:28: note:   'SIFT'
 typedef cv::Ptr<cv::SIFT>* SIFT;
                            ^~~~
features2d.cpp:478:28: error: 'SIFT' is not a member of 'cv'
     return new cv::Ptr<cv::SIFT>(cv::SIFT::create());
                            ^~~~
features2d.cpp:478:28: note: suggested alternative:
In file included from features2d.cpp:1:0:
features2d.h:23:28: note:   'SIFT'
 typedef cv::Ptr<cv::SIFT>* SIFT;
                            ^~~~
features2d.cpp:478:32: error: template argument 1 is invalid
     return new cv::Ptr<cv::SIFT>(cv::SIFT::create());
                                ^
features2d.cpp:478:38: error: 'cv::SIFT' has not been declared
     return new cv::Ptr<cv::SIFT>(cv::SIFT::create());
                                      ^~~~
features2d.cpp: In function 'KeyPoints SIFT_Detect(SIFT, Mat)':
features2d.cpp:487:9: error: base operand of '->' is not a pointer
     (*d)->detect(*src, detected);
         ^~
features2d.cpp: In function 'KeyPoints SIFT_DetectAndCompute(SIFT, Mat, Mat, Mat)':
features2d.cpp:504:9: error: base operand of '->' is not a pointer
     (*d)->detectAndCompute(*src, *mask, detected, *desc);
         ^~
Makefile:42: recipe for target 'doods' failed
make: *** [doods] Error 2
The command '/bin/sh -c make' returned a non-zero code: 2
make: *** [Makefile:54: docker] Error 2
snowzach commented 3 years ago

The Dockerfiles for arm are actually designed to cross compile on x86_64 machines because otherwise it takes FOREVER to run on an actually pi. If you want to edit the Dockerfile.arm32 and compile on an x86 machine you can then transfer the docker image. The other thing you can try is to just use the plain Dockerfile on the arm device. You actually go pretty far though. That looks like some sort of error when OpenCV was compiled it's missing support for something that the Go library needs. Try rolling back to master and building using just Dockerfile and see if it works (or customize that file to your liking)

1ubuntuuser commented 3 years ago

Done thanks @snowzach, I was using the master branch. Once I downloaded the latest release, everything went well. I was able to build images for arm32 and x86_64.

Both images start just fine but when it comes to processing an image I get the following. {"error":"could not decode image: image: unknown format","code":3,"message":"could not decode image: image: unknown format"}

Have I missed something?

EDIT: I tried jpeg and png

1ubuntuuser commented 3 years ago

I know this is round about thread, but it will get back on topic once I get builds working properly.

snowzach commented 3 years ago

@danielwilson654 how are you sending the image format? If you are using HTTP POST it needs to be a JSON post body with base64 encoded image data in the body. (See the README for an example)

1ubuntuuser commented 3 years ago

@snowzach I run programmatically run identical requests to snowzach/doods:latest (which worked) then to snowzach/doods:local to make sure it was a clean test. Still haven't been able to figure this out...

Thought maybe there was a package missing based on this: https://github.com/golang/go/issues/9184

You forgot to add
import _ "image/jpeg"
the image package itself doesn't know how to decode jpeg, you need to
import image/jpeg to register the jpeg decoder.

It's there /detector/detector.go, but missing in /detector/tflite/detector.go. That's probably by design though... does it inherit the packages somehow? I'm going to add it in anyway and see what happens. I'll also try calling the tensorflow detector and see if that has the same issue.

1ubuntuuser commented 3 years ago

Tried those, didn't work. I am running on AMD Rizen 7, not Intel. could that be the cause?

1ubuntuuser commented 3 years ago

Figured it out... the latest release (0.2.1) does not support the "file" attribute.

1ubuntuuser commented 3 years ago

I'm running a NanoPi Neo Air. Based on these benchmarks, the nanopi should be running faster the the Raspberry Pi 3b. https://www.cnx-software.com/2019/08/06/tensorflow-lite-for-microcontrollers-benchmarked-on-linux-sbcs/

But as mentioned above, it's running over 20 times slower... I'll keep rebuilding with different flags but I think I may have ventured outside my field a bit here. Any idea why doods is so slow on other arm devices?

1ubuntuuser commented 3 years ago

Accidentally closed the issue.

snowzach commented 2 years ago

If you want to try with the the new python version and open a ticket there if there's an issue still: https://github.com/snowzach/doods2