lazydevpro
lazydevpro

Reputation: 127

tflite models from tfhub.dev not working in Android

I am trying to use custom model detection using TensorFlow in android and I am using pre-train models from the official TensorFlow site. 3 out of 4 models are not working getting this error in the log.

E/CameraXDetectionActivit: onFailure: 
    com.google.mlkit.common.MlKitException: Failed to initialize detector. Unexpected number of dimensions for output index 0: got 3D, expected either 2D (BxN with B=1) or 4D (BxHxWxN with B=1, W=1, H=1).
        at com.google.mlkit.vision.vkp.PipelineManager.start(com.google.mlkit:vision-internal-vkp@@18.0.0:63)
        at com.google.mlkit.vision.objects.custom.internal.zzg.tryLoad(com.google.mlkit:object-detection-custom@@16.3.1:3)
        at com.google.mlkit.common.sdkinternal.model.CustomModelLoader.load(com.google.mlkit:common@@17.1.1:3)
        at com.google.mlkit.vision.objects.custom.internal.zzh.load(com.google.mlkit:object-detection-custom@@16.3.1:2)
        at com.google.mlkit.common.sdkinternal.ModelResource.zza(Unknown Source:18)
        at com.google.mlkit.common.sdkinternal.zzn.run(Unknown Source:10)
        at com.google.mlkit.common.sdkinternal.zzp.run(com.google.mlkit:common@@17.1.1:2)
        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@17.1.1:4)
        at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(Unknown Source:8)
        at com.google.mlkit.common.sdkinternal.zzj.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(Unknown Source:10)
        at com.google.mlkit.common.sdkinternal.zzk.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:919)

models which I have tried is:

aiy/vision/classifier/birds_V1 (working)

efficientdet/lite0/detection (not working)

ssd_mobilenet_v1 (not working)

Mobile object_localizer_v1.1 (not working)

Upvotes: 1

Views: 780

Answers (1)

Taehee Jeong
Taehee Jeong

Reputation: 146

Seems you're using ML Kit's object detection API with custom model. It first identifies objects in the image, and run image classification on those objects to determine what the object is. Hence, the model's output is class probability.

On the other hand, other models are actual object detection models, and outputs four tensors representing bounding box positions and classes.

Please refer to following example for using those detection models.

https://www.tensorflow.org/lite/examples/object_detection/overview

Upvotes: 1

Related Questions