anilsathyan7 / Portrait-Segmentation

Real-time portrait segmentation for mobile devices
MIT License
638 stars 133 forks source link

Cannot run the Segme_v2 application #13

Closed Nerdyvedi closed 3 years ago

Nerdyvedi commented 4 years ago

Hi, I am building the segme_v2 android application using Android studio. The Build is successful , but on running the apk file, I am getting an internal error:Failed to apply Delegate. Following is the whole error log I am getting.

java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: TfLiteGpuDelegate Init: New object definition is not supported.
TfLiteGpuDelegate Prepare: delegate is not initialized
Node number 94 (TfLiteGpuDelegateV2) failed to prepare.

Restored previous execution plan after delegate application failure.
 at org.tensorflow.lite.NativeInterpreterWrapper.applyDelegate(Native Method)
 at org.tensorflow.lite.NativeInterpreterWrapper.init(NativeInterpreterWrapper.java:85)
 at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:61)
 at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:223)
 at com.example.android.tflitecamerademo4.ImageSegmentor.recreateInterpreter(ImageSegmentor.java:147)
 at com.example.android.tflitecamerademo4.ImageSegmentor.useGpu(ImageSegmentor.java:156)
 at com.example.android.tflitecamerademo4.Camera2BasicFragment.lambda$updateActiveModel$0$Camera2BasicFragment(Camera2BasicFragment.java:457)
 at com.example.android.tflitecamerademo4.-$$Lambda$Camera2BasicFragment$eoo74V6qLXRuzvkCmA1gEfC0acM.run(Unknown Source:8)
 at android.os.Handler.handleCallback(Handler.java:873)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loop(Looper.java:201)
 at android.os.HandlerThread.run(HandlerThread.java:65)

I am not even able to understand this error. Any help would be hugely appreciated. Thanks for uploading such a brilliant work.

anilsathyan7 commented 4 years ago

I think it is due to the opencl driver issue with tflite-gpu opencl delegate in android. I was getting similar error in redmi note 7 pro; but not on redmi note 8 pro.It could be due to the device specific opencl drivers issue.

So, here are some other options that you could try

  1. It may work if you change the tflite-gpu version in gradle settings(versions).

  2. Please see if you can run it on some other device(worked with redmi note 8 pro) It seems to be an internal problem with tflite-gpu due to lack of standardization. Also keep in mind that tflite-gpu is still in experimental stage.

  3. Run the model on cpu with num_threads=2 or 4.(speed may be decreased)

  4. Use the benchmark tool to verify that model works on your android device. I have uploaded the binary of the benchmark tool here(two versions)

Also, if you have time try building the latest benchmark tool with bazel from source(tensorflow) and verify if the problem still persists.

See if you are getting the same error on the final apk: SegVid

Nerdyvedi commented 4 years ago

Thank you so much for your response.

I tried to run the apk file you attached and got the same error. I am running the application on Note 7 Pro as well.

Can you tell me how can I run the model on CPU ? The app crashes on launching. I have almost 0 experience with android development , Sorry if it's a silly question.

anilsathyan7 commented 4 years ago

Ok, there is a silly solution though... As soon as you start the app press the CPU option in the list from GUI !!!

If you are interested in these kinds of apps, perhaps you should start with something simple, say : Tflite Android Classification Google

SInce these API's are still in experimental phase you may encounter lots of errors across devices, especially if you try to run a custom app/model.

Nerdyvedi commented 4 years ago

Umm, I don't think the solution of pressing CPU works. I am pressing it as quickly as possible, but it still crashes. Maybe, I should try and set default to CPU.

Thank you

san-guy commented 3 years ago

Hi @Nerdyvedi , I am facing the exact problems that you faced. Did you happen to find any workaround? Would be happy if you could share :)