JosephGK
JosephGK

Reputation: 11

Standard TFlite object detection model not working in MLKit

If I use the Pre-Trained TFLite Object detection model in MLKit, I get the following error:

 CalculatorGraph::Run() failed in Run: 
    Calculator::Open() for node "BoxClassifierCalculator" failed: #vk 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).

Any Idea what I might be doing wrong?

Upvotes: 1

Views: 3764

Answers (3)

Alex Conner
Alex Conner

Reputation: 260

You can now create MLKit Custom Models with Google's Vertex AI/AutoML Cloud service and it works well with the CameraX API using an ImageAnalysis Analyzer. Follow the guide here to make and train the TFLite model with your own images via browser (or use the Google Cloud CLI if you have many to upload). After that, this guide walks you through pretty much everything you need to add the model to your project, and how detect and label objects with MLKit.

Upvotes: 0

Luis
Luis

Reputation: 143

Well, since I found out through this post here on SO, I went on to look for other options. And the tutorial posted here: Tensor Flow Lite OBJ detection did the trick just nicely.

First of all added the

implementation 'org.tensorflow:tensorflow-lite-task-vision:0.2.0'

To build.gradle, and this simple code worked like a charm. Obviously I have to make some changes to reflect my specific needs, but it's detecting without errors.

val image = TensorImage.fromBitmap(bitmap)
val options = ObjectDetector.ObjectDetectorOptions.builder()
    .setMaxResults(5)
    .setScoreThreshold(0.5f)
    .build()
val detector = ObjectDetector.createFromFileAndOptions(
    this, // the application context
    "model.tflite", // must be same as the filename in assets folder
    options
)

A more in depth explanation is given in that link, too much to be thrown here. Hope this helps somebody else.

Upvotes: 2

Dong Chen
Dong Chen

Reputation: 882

ML Kit does not currently support custom object detection model yet. ML Kit currently only allows developers to use custom image classification models. All TFLite models that are compatible with ML Kit are listed here:

https://tfhub.dev/ml-kit/collections/image-classification/1

If you want to do object detection, you can try out ML Kit's Object Detection API: https://developers.google.com/ml-kit/vision/object-detection

If you want to use a custom object detection model, you can try TFLite task library:

https://www.tensorflow.org/lite/inference_with_metadata/task_library/overview.

Upvotes: 5

Related Questions