Skip to content

Instantly share code, notes, and snippets.

View the-dagger's full-sized avatar
🚀
To Boldly Go Where No Man Has Gone Before

Harshit Dwivedi the-dagger

🚀
To Boldly Go Where No Man Has Gone Before
View GitHub Profile
...
#include "tensorflow/lite/java/src/main/native/normalize.h"
#include "tensorflow/lite/java/src/main/native/predict.h"
#include "tensorflow/lite/java/src/main/native/extract_feature.h"
namespace tflite {
...
...
hdrs = [
"exception_jni.h",
"nativeinterpreterwrapper_jni.h",
"tensor_jni.h",
"tensorflow_lite_jni.h",
"normalize.h",
"predict.h",
"extract_feature.h",
],
bazel build --cxxopt='--std=c++11' -c opt \
--fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
//tensorflow/lite/java:tensorflow-lite
> Task :crash:app:preDebugBuild FAILED
Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.
Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.
> Task :admob:app:preDebugBuild FAILED
Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.
> Task :appindexing:app:preDebugBuild FAILED
Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.
dependencies {
// ...
// Add the In-App Messaging depencency:
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.0'
}
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
val pokeArray: Array<String> = arrayOf("abra", "aerodactyl", "alakazam", "arbok", "arcanine", "articuno", "beedrill", "bellsprout",
"blastoise", "bulbasaur", "butterfree", "caterpie", "chansey", "charizard", "charmander", "charmeleon", "clefable", "clefairy", "cloyster", "cubone", "dewgong",
"diglett", "ditto", "dodrio", "doduo", "dragonair", "dragonite", "dratini", "drowzee", "dugtrio", "eevee", "ekans", "electabuzz",
"electrode", "exeggcute", "exeggutor", "farfetchd", "fearow", "flareon", "gastly", "gengar", "geodude", "gloom",
"golbat", "goldeen", "golduck", "golem", "graveler", "grimer", "growlithe", "gyarados", "haunter", "hitmonchan",
"hitmonlee", "horsea", "hypno", "ivysaur", "jigglypuff", "jolteon", "jynx", "kabuto",
"kabutops", "kadabra", "kakuna", "kangaskhan", "kingler", "koffing", "krabby", "lapras", "lickitung", "machamp",
"machoke", "machop", "magikarp", "magmar", "magnemite", "magneton", "mankey", "marowak", "meowth", "metapod",
"m
override fun onCreate(savedInstanceState: Bundle?) {
//...
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 {
override fun onCreate(savedInstanceState: Bundle?) {
//...
val firebaseModelOptions = FirebaseModelOptions.Builder()
.setLocalModelName("pokedex")
.setCloudModelName("pokedex")
.build()
fireBaseInterpreter = FirebaseModelInterpreter.getInstance(firebaseModelOptions)!!
//...
}
class PokemonDetectorActivity : BaseCameraActivity() {
companion object {
/** Dimensions of inputs. */
const val DIM_IMG_SIZE_X = 224
const val DIM_IMG_SIZE_Y = 224
const val DIM_BATCH_SIZE = 1
const val DIM_PIXEL_SIZE = 3
const val IMAGE_MEAN = 128
private const val IMAGE_STD = 128.0f