I want to use cameraX to detect live stream to accomplish object detection, so I use ML Kit .
I'm failed to put image into my model.
my model's
inputs:
Type : Image<float32>
shape: [1,640,640,3]
Min/Max :[-1] / [1]
outputs:
Type : BoundingBox<float32>
shape: [1,9,8400]
Min/Max :[] / []
below is my error message and related code:
Pass image to an ML Kit failed: 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 B1, W=1, H=1).
val customObjectDetectorOptions =
CustomObjectDetectorOptions.Builder(localModel)
.setDetectorMode(CustomObjectDetectorOptions.STREAM_MODE)
.enableClassification()
.setClassificationConfidenceThreshold(0.5f)
.setMaxPerObjectLabelCount(3)
.build()
val objectDetector =
ObjectDetection.getClient(customObjectDetectorOptions)
private class ImageAnalyzer : ImageAnalysis.Analyzer {
@OptIn(ExperimentalGetImage::class) override fun analyze(imageProxy: ImageProxy) {
//@OptIn(ExperimentalGetImage::class) override fun analyze(imageProxy: ImageProxy) {
val mediaImage = imageProxy.image
if (mediaImage != null) {
Log.d(TAG, "mediaImage != null: succeed")
val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
// Pass image to an ML Kit Vision API
objectDetector.process(image)
.addOnSuccessListener { ...}
I guess I need to transform my model's output shape from (1,9,8400) to 2D or 4D dimension,but I have no idea how to do . Hope someone can help me!!!