Skip to content

Instantly share code, notes, and snippets.

@the-dagger
Last active August 1, 2018 08:00
Show Gist options
  • Select an option

  • Save the-dagger/7b4db62bed38e8057d134b0fd35170dc to your computer and use it in GitHub Desktop.

Select an option

Save the-dagger/7b4db62bed38e8057d134b0fd35170dc to your computer and use it in GitHub Desktop.
private fun getPokemonFromBitmap(bitmap: Bitmap?) {
val inputs = FirebaseModelInputs.Builder()
.add(convertBitmapToByteBuffer(bitmap)) // add() as many input arrays as your model requires
.build()
fireBaseInterpreter.run(inputs, inputOutputOptions)
?.addOnSuccessListener {
val pokeList = mutableListOf<Pokemon>()
/**
* Run a foreach loop through the output float array containing the probabilities
* corresponding to each label
* @see pokeArray to know what labels are supported
* it here is the list of probabilities for the detected pokemons, so we can loop through it easily
*/
it.getOutput<Array<FloatArray>>(0)[0].forEachIndexed { index, fl ->
//Only consider a pokemon when the accuracy is more than 40%
if (fl > .40)
Log.d("Detected Pokemon ", pokeArray[index])
}
//Update UI here by setting pokeList to the adapter
}
?.addOnFailureListener {
it.printStackTrace()
fabProgressCircle.hide()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment