tzutalin / dlib-android-app

:dragon: Android app to demo dlib-android(https://github.com/tzutalin/dlib-android). Use the prebuilt shared-lib built from dlib-android
Apache License 2.0
683 stars 246 forks source link

Reduce loading time #20

Closed EzequielAdrianM closed 7 years ago

EzequielAdrianM commented 7 years ago

Hi, Initializing the Face Detector takes more than 10 seconds to load. I have seen this StackOverflow question: http://stackoverflow.com/questions/38435653/detecting-face-landmarks-points-in-android On the first answer says that the 98MB DAT file can be reduced to 18MB approximately, losing very little accuracy. What do you think about it?

tzutalin commented 7 years ago

Hi @EzequielAdrianM , Nice suggestion. Do you have any sample code and DAT file about that?

EzequielAdrianM commented 7 years ago

I have found this keys to achieve our goal: serialize a shape_predictor.dat in packed format: pastebin.com/UqNq5qDV deserialize it in the same format: pastebin.com/UT3w8CmS

I have experience with Android/Java but I do not understand very fine the cpp part. Please tell me if that code can be used to quantize the floats down..

junliu-cn commented 7 years ago

Hi @EzequielAdrianM , I have tried the c++ code.It works for me.The final dat format file size is no more than 18M and the accuracy of the shape predicator is almostly the same as before.What makes me disappointed is that I can't use deserialize function to decode the minified dat file.

junliu-cn commented 7 years ago

Hi @tzutalin, I noticed that size of dot so format files are very small in your dlib-android-app project folder,but when I build the code from your another project dlib-android by myself, I got a bigger size.Your total size of the four different dot so file is 26.7M whereas mine 62M.It's a huge difference.Can you give me some tips?Many thanks to you.

EzequielAdrianM commented 7 years ago

It seems reasonable in some way cause that new file is now like a compressed file. It would be nice if you upload that lightweight file for us so I can test it out. Thanks

junliu-cn commented 7 years ago

Hi @EzequielAdrianM , The only choice of loading the lightweight file is use the code from the link you send before.And the compress code almostly the same as decompress code. You should try the code by yourself according to the guideline provided by the author,it's very easy. If you have any problem,feel free to ask.

EzequielAdrianM commented 7 years ago

@chrisluu Oh come on, I am not familiar at all with cpp and compilers. Just think I don't even know which program use to compile that code on windows. Please, be nice and send me dat file to mail ezequieladrianm@gmail.com

junliu-cn commented 7 years ago

Ok,I will send it to you.Do you know how to minimize size of dot so file?

Sent from my iPhone

On 3 Mar 2017, at 12:52, Ezequiel Adrián notifications@github.com wrote:

@chrisluu Oh come on, I am not familiar at all with cpp and compilers. Just think I don't even know which program use to compile that code on windows. Please, be nice and send me thta file to mail ezequieladrianm@gmail.com

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

EzequielAdrianM commented 7 years ago

I've tested it on the android app with the new 18MB DAT file, but when the camera opens it only shows where the face is, no landmarks at all. Also, the second time I want to open the camera, it does not initialize, shows a black screen waiting for camera to be opened. And the following appears in the log:

CameraConnectionFragment: open Camera
CameraConnectionFragment: Opening camera preview: 640x480
dlib: jniNativeClassInit success
native: I/jni_face_det.cpp:145 jniInit
native: I/detector.h:81 Model Path: /sdcard/person.svm
native: I/detector.h:85 Not exist /sdcard/person.svm
native: I/detector.h:149 Init mFaceDetector

And there it stops. Black screen. Completely unresponsive... Any idea?

Here is the DAT file I have used made by @chrisluu shape_predictor_68_face_landmarks.dat

EzequielAdrianM commented 7 years ago

Okay, I don't know which is the most lightweight way, but this file (63MB) seems to work almost as precise as the original landmarks.dat (98MB) while keeping all landmarks. Here is the link to download and test: sp.dat