Search code examples
androidfirebasekotlinfirebase-mlkit

How to run two FirebaseVisionFaceDetector independently?


I have two instances of FirebaseVisionFaceDetector, that I've got from different FirebaseApps.

Initializing of FirebaseApps in App class:

FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this)!!, "accurate")
FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this)!!, "fast")

Getting detectors:

private val detector = FirebaseVision.getInstance(FirebaseApp.getInstance("accurate"))
    .getVisionFaceDetector(optOpts)
private val detector2 = FirebaseVision.getInstance(FirebaseApp.getInstance("fast"))
    .getVisionFaceDetector(optOpts2)

Hovewer, when I'm calling Tasks.await(detector.detectInImage(image)) and Tasks.await(detector2.detectInImage(image)) in different threads, one of calls blocks another so they're performing consistently.

I think that detectors are using the same object under the hood, so I cannot call this methods asynchronously. Does anybody know how to resolve this problem?


Solution

  • I've contacted the support team and they told me that at the current moment all instances of firebase app are using the same thread, so it's not possible to parallel.
    Additionally, they've told me that they've created a feature request, so it will be fixed in the future versions of MLKit.