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

Performance optimisation #8

Open
lemberh opened this issue Nov 28, 2019 · 7 comments
Open

Performance optimisation #8

lemberh opened this issue Nov 28, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@lemberh
Copy link
Contributor

lemberh commented Nov 28, 2019

Do you support neon instruction set optimization from this thread davisking/dlib#276

@lemberh lemberh changed the title Speed optimization Performance optimisation Nov 28, 2019
@Luca96
Copy link
Owner

Luca96 commented Nov 29, 2019

Hi @lemberh, unfortunately I support only the basic architectures.

@lemberh
Copy link
Contributor Author

lemberh commented Nov 30, 2019

Did you try to use those optimizations?
I have changed cmake to :

  ${AndroidCmake}   -DBUILD_SHARED_LIBS=1 \
	  -DANDROID_NDK=${NDK} \
	  -DCMAKE_SYSTEM_NAME=Android \
	  -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} \
	  -DCMAKE_BUILD_TYPE=Release \
	  -DCMAKE_CXX_FLAGS="-std=c++11 -frtti -fexceptions -march=armv7-a -mfpu=neon" \
	  -DANDROID_ARM_NEON=TRUE \
	  -DCMAKE_C_FLAGS=-O3 \
	  -DANDROID_ABI=${abi} \
	  -DANDROID_PLATFORM=${MIN_SDK} \
	  -DANDROID_TOOLCHAIN=clang \
	  -DANDROID_STL=c++_shared \
	  -DANDROID_CPP_FEATURES=rtti exceptions \
	  -DCMAKE_PREFIX_PATH=../../ \
	  ../../			  

But it doesnt seems to have any impact on performance

@Luca96
Copy link
Owner

Luca96 commented Nov 30, 2019

Have you tried to add the ABI "armeabi-v7a with NEON" in the script?

You should edit line 17 of setup.sh (I guess you're using Linux), having something like this:

ABI=('armeabi-v7a' 'armeabi-v7a with NEON' 'arm64-v8a' 'x86' 'x86_64')

Let me know if now it works.

For more information you can read this.

@Luca96 Luca96 added the enhancement New feature or request label Nov 30, 2019
@lemberh
Copy link
Contributor Author

lemberh commented Nov 30, 2019

I have tried this.
Unfortunately, I don't see any difference.
In Android CMake documentation it is said that

armeabi-v7a with NEON | Same as -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON.

https://developer.android.com/ndk/guides/cmake#android_abi

I'm using face recognition, this example http://dlib.net/dnn_face_recognition_ex.cpp.html
but slightly modified without face detection.
On devices with arm64-v8a it takes around 700ms to calculate face vector.
But on devices with 'armeabi-v7a' from 2 up to 5 seconds to calculate face vector.
I'm wondering if that can be improved with NEON instructions.

@Luca96
Copy link
Owner

Luca96 commented Dec 5, 2019

To gain a performance speed you can try to:

  • Process grayscale images, instead of rgb.
  • Downscale the input images, as well as the network input.
  • Reduce the neural network size, i.e. less layers, less filters.

@lemberh
Copy link
Contributor Author

lemberh commented Dec 6, 2019

Thanks for suggestions, will try them!

@opiumfive
Copy link

building dlib with linked OpenBLAS improve performance greatly. Instructions can be found here davisking/dlib#1238 (comment)

for example on redmi 7a
face descriptor calculation took ~3.5 sec for me on default prebuilt dlib .so's,
after rebuilding dlib with OpenBLAS it takes ~350ms
10 times faster

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

No branches or pull requests

3 participants