mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

How to build AAR for holistic android? (slower than prebuilt apk)

Open jihwan1park opened this issue 3 years ago • 1 comments

I'm trying to test the performance of holitic for android, so I tried following things:

  • build example from source using bazel build system (https://google.github.io/mediapipe/getting_started/android.html)

  • build AAR and use following link (https://google.github.io/mediapipe/getting_started/android_archive_library.html)

In the above two trials, I was able to get 8-9 fps. However, when using the prebuilt apk provided on the homepage, it was confirmed that it shows a faster speed. (https://drive.google.com/file/d/1o-Trp2GIRitA0OvmZWUQjVMa476xpfgK/view?usp=sharing) So, finally, after extracting the libmediapipe_jni.so and libopencv_java3.so file from the prebuilt apk, I re-created the AAR file, and as a result, I was able to get the same 15fps as the prebuilt apk.

What I'm curious about is how to generate an AAR file or libmediapipe_jni.so file that can get 15fps.

Here's the method that I tried to build AAR.

  • add following BUILD file on mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example
load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar")

mediapipe_aar(
    name = "mediapipe_holistic",
    calculators = ["//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu_deps",],
)
  • build using following command:
#!/bin/bash
bazel build -c opt --strip=ALWAYS \
    --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
    --fat_apk_cpu=arm64-v8a,armeabi-v7a \
    --legacy_whole_archive=0 \
    --features=-legacy_whole_archive \
    --copt=-fvisibility=hidden \
    --copt=-ffunction-sections \
    --copt=-fdata-sections \
    --copt=-fstack-protector \
    --copt=-O3 \
    --copt=-fomit-frame-pointer \
    --copt=-DABSL_MIN_LOG_LEVEL=2 \
    --linkopt=-Wl,--gc-sections,--strip-all \
    --jobs=4 \
    //mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example:mediapipe_holistic.aar \
    --linkopt="-s"

NDK version is: 21.0.6113669 Testing mediapipe version: v0.8.10.2

jihwan1park avatar Sep 19 '22 08:09 jihwan1park

Hi @jihwan1park, MediaPipe fps can be higher if you have the powerful device or more simple graph structure. Please follow this closed issue #1160 and #1160(comment) which will give you the better understanding to achieve the higher fps in android. Thank you!

kuaashish avatar Sep 19 '22 09:09 kuaashish

Hi @kuaashish, I wrote it a little bit confusingly. To be more precise, I tested using the same graph on the same device. However, in the case of the apk distributed by Google, it operates at 15fps, and when I build it myself, the performance was half that. The command used for the build is as mentioned above. I think there's something wrong with the build options, but I was curious about that.

jihwan1park avatar Sep 22 '22 00:09 jihwan1park

Hi @jihwan1park, As per the above comment, you need to make the graph structure simpler while building the aar on the device. If a simple graph structure the possibility to achieve higher fps is more. Thank you!

kuaashish avatar Sep 23 '22 09:09 kuaashish

Hi @kuaashish, my question wasn't meant to get a faster framerate. Instead, I want to know the exact way to create a "real" release version of libmediapipe_jni.so. I use same .tflite, .pbtxt and .binarypb with prebuilt apk. I think I should be able to get the same performance as the prebuilt apk by compiling the AAR file my self using the bazel build I linked at the beginning, and using the graph and graph structure obtained through the holistic sample application build. Because the graph and graph structure (.tflite + .binarypb) was exactly the same as the version included in the prebuilt apk. However my results were not. Anyway, thanks for replying!

jihwan1park avatar Sep 27 '22 01:09 jihwan1park

Hi @kuaashish! Is there any updates on this issue? Thanks!

jihwan1park avatar Oct 13 '22 00:10 jihwan1park

Actually, I got the answer while testing with older version. With v0.8.9, I can get a good performance version like pre-built apk, but after v0.8.10, the inference performance of holistic will be slower. I don't know why, but I think I should let you know here. Thanks @kuaashish !

jihwan1park avatar Nov 01 '22 08:11 jihwan1park

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Nov 01 '22 08:11 google-ml-butler[bot]