Azure-Samples / cognitive-services-android-customvision-sample

Sample Anroid app for image classification using a TensorFlow model exported from Microsoft Cognitive Services Custom Vision
58 stars 57 forks source link

IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected (declaration of 'org.tensorflow.lite.Tensor' #44

Closed Leci37 closed 9 months ago

Leci37 commented 9 months ago

Please provide us with the following information:

Minimal steps to reproduce

I am following the tutorial at https://learn.microsoft.com/en-us/azure/ai-services/custom-vision-service/export-your-model

By installing the default (without any code modification) example app from https://github.com/Azure-Samples/cognitive-services-android-customvision-sample/tree/master/object_detection

I update the gradle as requested, and when I try to run it in the code I get this next error Caused by: ai.customvision.visionskills.VisionSkillsException: {"NativeRuntimeError":"Skill[ObjectDetector] Build Exception <JNIWrapperException: Failed to load model; Model name = <sample-tflite.cvmodel/cvexport.manifest>; details: java.lang.IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected I don't understand why if it is freshly downloaded it is not able to load the file (original location : https://github.com/Azure-Samples/cognitive-services-android-customvision-sample/blob/master/object_detection/app/src/main/assets/sample-tflite.cvmodel/cvexport.manifest )

I/tensorflow: CameraActivity: Camera API lv2?: true
I/InterpreterApi: Loaded native library: tensorflowlite_jni
I/InterpreterApi: Didn't load native library: tensorflowlite_jni_gms_client
I/tflite: Initialized TensorFlow Lite runtime.
E/libc: Access denied finding property "ro.hardware.chipname"
I/tflite: Created TensorFlow Lite XNNPACK delegate for CPU.
I/tflite: Replacing 31 out of 31 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 1 partitions for the whole graph.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: demo.tensorflow.org.customvision_sample, PID: 28126
    java.lang.RuntimeException: Unable to start activity ComponentInfo{demo.tensorflow.org.customvision_sample/demo.tensorflow.org.customvision_sample.ObjectDetectorActivity}: ai.customvision.visionskills.VisionSkillsException: {"NativeRuntimeError":"Skill[ObjectDetector] Build Exception <JNIWrapperException: Failed to load model; Model name = <sample-tflite.cvmodel/cvexport.manifest>; details: java.lang.IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected (declaration of 'org.tensorflow.lite.Tensor' appears in /data/app/demo.tensorflow.org.customvision_sample-WLh5PAvRkwWxnn7l6J8JjA==/base.apk)>"}
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3313)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3462)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7565)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: ai.customvision.visionskills.VisionSkillsException: {"NativeRuntimeError":"Skill[ObjectDetector] Build Exception <JNIWrapperException: Failed to load model; Model name = <sample-tflite.cvmodel/cvexport.manifest>; details: java.lang.IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected (declaration of 'org.tensorflow.lite.Tensor' appears in /data/app/demo.tensorflow.org.customvision_sample-WLh5PAvRkwWxnn7l6J8JjA==/base.apk)>"}
        at ai.customvision.visionskills.VisionSkillsManager.throwIfJNIFailed(VisionSkillsManager.java:24)
        at ai.customvision.visionskills.VisionSkillsManager.SkillConfigurationBuild_orThrow(VisionSkillsManager.java:553)
        at ai.customvision.visionskills.VisionSkillsManager.skillConfigurationBuild(VisionSkillsManager.java:309)
        at ai.customvision.visionskills.ConfigurationBase.build(ConfigurationBase.java:41)
        at ai.customvision.visionskills.CVSObjectDetector$Configuration.build(CVSObjectDetector.java:66)
        at demo.tensorflow.org.customvision_sample.MSCognitiveServicesCustomVisionObjectDetector.<init>(MSCognitiveServicesCustomVisionObjectDetector.java:61)
        at demo.tensorflow.org.customvision_sample.ObjectDetectorActivity.onCreate(ObjectDetectorActivity.java:52)
        at android.app.Activity.performCreate(Activity.java:7916)
        at android.app.Activity.performCreate(Activity.java:7903)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3288)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3462) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:224) 
        at android.app.ActivityThread.main(ActivityThread.java:7565) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
I/Process: Sending signal. PID: 28126 SIG: 9
Disconnected from the target VM, address: 'localhost:51296', transport: 'socket'

I hope that the example of object detetion app, download it and be able to run it on my phone.

Leci37 commented 9 months ago

I solved the problem using version '2.0.0' of the TensorFlow Lite library. implementation 'org.tensorflow:tensorflow-lite:2.0.0'

in file 'build.gradle'