googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.56k stars 2.93k forks source link

[Bug report] Failed to create MediaPipe image segmenter #783

Closed SamedHrmn closed 7 months ago

SamedHrmn commented 8 months ago

Hi, Im trying to implement subject segmentation model in Android project but im getting that error during initialization of segmenter. Here error logs and my AndroidManifest.xml.

2024-02-26 19:09:22.214 23087-23158 emuglGLESv2_enc         com...le.background_remover_flutter  E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glCreateShader:2043 GL error 0x500
2024-02-26 19:09:22.215 23087-23140 native                  com...le.background_remover_flutter  E  E0000 00:00:1708963762.416956   23140 calculator_graph.cc:892] INTERNAL: CalculatorGraph::Run() failed: 
                                                                                                    Calculator::Open() for node "mediapipe_tasks_vision_image_segmenter_imagesegmentergraph__mediapipe.tasks.TensorsToSegmentationCalculator" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argument.: glCreateShader in third_party/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:53
                                                                                                    === Source Location Trace: ===
                                                                                                    ./third_party/tensorflow/lite/delegates/gpu/gl/gl_call.h:61
                                                                                                    third_party/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:53
                                                                                                    third_party/mediapipe/tasks/cc/vision/image_segmenter/calculators/ssbo_to_texture_converter.cc:90
                                                                                                    third_party/mediapipe/tasks/cc/vision/image_segmenter/calculators/segmentation_postprocessor_gl.cc:460
                                                                                                    third_party/mediapipe/tasks/cc/vision/image_segmenter/calculators/segmentation_postprocessor_gl.cc:331
                                                                                                    third_party/mediapipe/tasks/cc/vision/image_segmenter/calculators/tensors_to_segmentation_calculator.cc:353
                                                                                                    third_party/mediapipe/framework/calculator_node.cc:560
2024-02-26 19:09:22.237 23087-23140 MLKSubjectSegmenter     com...le.background_remover_flutter  E  Failed to create MediaPipe image segmenter
                                                                                                    com.google.mediapipe.framework.MediaPipeException: internal: CalculatorGraph::Run() failed: 
                                                                                                    Calculator::Open() for node "mediapipe_tasks_vision_image_segmenter_imagesegmentergraph__mediapipe.tasks.TensorsToSegmentationCalculator" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argument.: glCreateShader in third_party/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:53
                                                                                                        at com.google.mediapipe.framework.Graph.nativeWaitUntilGraphIdle(Native Method)
                                                                                                        at com.google.mediapipe.framework.Graph.l(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):20)
                                                                                                        at com.google.android.gms.mlkit.segmentation.subject.SubjectSegmenter.c(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):1250)
                                                                                                        at m.awk.v(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):68)
                                                                                                        at m.as.onTransact(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):21)
                                                                                                        at android.os.Binder.transact(Binder.java:1064)
                                                                                                        at com.google.android.gms.internal.mlkit_vision_subject_segmentation.zza.zzc(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:2)
                                                                                                        at com.google.android.gms.internal.mlkit_vision_subject_segmentation.zzub.zze(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:2)
                                                                                                        at com.google.mlkit.vision.segmentation.subject.internal.zzj.load(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:18)
                                                                                                        at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2)
                                                                                                        at java.lang.Thread.run(Thread.java:920)
2024-02-26 19:09:22.271 23087-23087 MobileVisionBase        com...le.background_remover_flutter  E  Error preloading model resource
                                                                                                    com.google.mlkit.common.MlKitException: Failed to init module subject segmenter
                                                                                                        at com.google.mlkit.vision.segmentation.subject.internal.zzj.load(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:20)
                                                                                                        at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2)
                                                                                                        at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2)
                                                                                                        at java.lang.Thread.run(Thread.java:920)
                                                                                                    Caused by: android.os.RemoteException: Failed to create MediaPipe image segmenter
                                                                                                        at com.google.android.gms.mlkit.segmentation.subject.SubjectSegmenter.c(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):1549)
                                                                                                        at m.awk.v(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):68)
                                                                                                        at m.as.onTransact(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):21)
                                                                                                        at android.os.Binder.transact(Binder.java:1064)
                                                                                                        at com.google.android.gms.internal.mlkit_vision_subject_segmentation.zza.zzc(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:2)
                                                                                                        at com.google.android.gms.internal.mlkit_vision_subject_segmentation.zzub.zze(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:2)
                                                                                                        at com.google.mlkit.vision.segmentation.subject.internal.zzj.load(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:18)
                                                                                                        at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4) 
                                                                                                        at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10) 
                                                                                                        at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2) 
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4) 
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1) 
                                                                                                        at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2) 
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
                                                                                                        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2) 
                                                                                                        at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2) 
                                                                                                        at java.lang.Thread.run(Thread.java:920) 
                                                                                                    Caused by: com.google.mediapipe.framework.MediaPipeException: internal: CalculatorGraph::Run() failed: 
                                                                                                    Calculator::Open() for node "mediapipe_tasks_vision_image_segmenter_imagesegmentergraph__mediapipe.tasks.TensorsToSegmentationCalculator" failed: [GL_INVALID_ENUM]: An unacceptable value is specified for an enumerated argument.: glCreateShader in third_party/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:53
                                                                                                        at com.google.mediapipe.framework.Graph.nativeWaitUntilGraphIdle(Native Method)
                                                                                                        at com.google.mediapipe.framework.Graph.l(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):20)
                                                                                                        at com.google.android.gms.mlkit.segmentation.subject.SubjectSegmenter.c(:com.google.android.gms.optional_mlkit_subject_segmentation@240615049@24.06.15 (100800-0):1250)
                                                                                                        ... 17 more

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:label="background_remover_flutter"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data
            android:name="com.google.mlkit.vision.DEPENDENCIES"
            android:value="subject_segment" />
    </application>
</manifest>

To Reproduce Example Steps to reproduce the behavior in sample app:

  1. Run the app and see error

Expected behavior No error.

SDK Info:

Smartphone:

SilverDestiny commented 8 months ago

Hi, from [Pixel 3, Android API 31], are you running the API on emulator?

SamedHrmn commented 8 months ago

I tried both, emulator and my android device(API 33). Same result.

RiteshJariwala commented 8 months ago

I am also getting same error for subject segmentation as follows:

MobileVisionBase com.google.mlkit.vision.demo E Error preloading model resource com.google.mlkit.common.MlKitException: Waiting for the subject segmentation optional module to be downloaded. Please wait. at com.google.mlkit.vision.segmentation.subject.internal.zzj.load(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:5) at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4) at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10) at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1) at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2) at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2) at java.lang.Thread.run(Thread.java:1012) 2024-03-06 16:51:30.283 15690-15690 VisionProcessorBase com.google.mlkit.vision.demo D Failed to process. Error: Waiting for the subject segmentation optional module to be downloaded. Please wait.

I am on pixel 7 pro and used mlkit vision example of subject segmentation

SilverDestiny commented 8 months ago

I am also getting same error for subject segmentation as follows:

MobileVisionBase com.google.mlkit.vision.demo E Error preloading model resource com.google.mlkit.common.MlKitException: Waiting for the subject segmentation optional module to be downloaded. Please wait. at com.google.mlkit.vision.segmentation.subject.internal.zzj.load(com.google.android.gms:play-services-mlkit-subject-segmentation@@16.0.0-beta1:5) at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@18.10.0:4) at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10) at com.google.mlkit.common.sdkinternal.zzt.run(com.google.mlkit:common@@18.10.0:2) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@18.10.0:4) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@18.10.0:1) at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@18.10.0:2) at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2) at java.lang.Thread.run(Thread.java:1012) 2024-03-06 16:51:30.283 15690-15690 VisionProcessorBase com.google.mlkit.vision.demo D Failed to process. Error: Waiting for the subject segmentation optional module to be downloaded. Please wait.

I am on pixel 7 pro and used mlkit vision example of subject segmentation

This is a different error. It just means the model is being downloaded. You can retry the app to see if it works.

SilverDestiny commented 8 months ago

I tried both, emulator and my android device(API 33). Same result.

The error is probably due to OpenGL version is too low on the device. Could you try to update your system to latest, which might update OpenGL to workable version?

SilverDestiny commented 8 months ago

emuglGLESv2_enc might indicate it's using GL ES2.0, which is too old to support this feature.

SilverDestiny commented 7 months ago

Close this issue now since there's no reply for a while.

Feel free to reopen it if you have any more concern. Thanks!