iostensorflowobject-detection-apigoogle-mlkitgoogle-cloud-automl

Issue with Custom Object Detector model from GCP Vision


My full tech stack is:

I am trying to use a Custom Object detector using MLKit and one model trained in GCP AutoML Vision.
I created the model and exported as tflite file, but when trying to do objectDetector processImage:visionImage, I always get the error:
Error Domain=com.google.visionkit.pipeline.error Code=3 "Pipeline failed to fully start: 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)." UserInfo={com.google.visionkit.status=<MLKITvk_VNKStatusWrapper: 0x280841270>, NSLocalizedDescription=Pipeline failed to fully start: 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).}.
I have downloaded the mlkit examples from https://github.com/googlesamples/mlkitand there is something similar in the vision project, (to detect birds) when I try to replace my own tflite file, it breaks in the exact same way as in my own project.
I presume the tflite is created in a very different way as MLVision does.
Any insight? (Sorry if this is so obvious, but I'm pretty new to TensorFlow and MLVision) Thanks in advance


Solution

  • The issue is exactly as what the error message says: got 3D, expected either 2D (BxN with B=1) or 4D (BxHxWxN with B=1, W=1, H=1). That means your model is not compatible with ML Kit, as its tensor has incorrect dimension. The model compatibility requirements are specified here.