Skip to content
Permalink
Browse files

make interpreter global and thread safe

  • Loading branch information...
VictorAlbertos committed Mar 8, 2019
1 parent 5e3224a commit 843ff43645c17cf59a0728e1163332eeee7fbe7a
@@ -66,11 +66,8 @@ fun Bitmap.debugHeatMap(
pixels.forEach { pixel -> inputBuffer.putFloat((pixel shr 16 and 0xFF) / 255f) }
pixels.forEach { pixel -> inputBuffer.putFloat((pixel shr 8 and 0xFF) / 255f) }
pixels.forEach { pixel -> inputBuffer.putFloat((pixel and 0xFF) / 255f) }
val intpr = Interpreter(rawModel, Interpreter.Options().apply {
setNumThreads(1)
})
intpr.run(inputBuffer, output)
intpr.close()

intpreter.runThreadSafe(inputBuffer, output)

// calculate tempered softmax
val flattened = output[0][0].flattened()
@@ -116,11 +113,7 @@ fun Bitmap.debugHeatMap(
}
}

private val intpreter by lazy {
Interpreter(rawModel, Interpreter.Options().apply {
setNumThreads(1)
})
}


@Synchronized
fun Interpreter.runThreadSafe(inputBuffer: ByteBuffer, output: Array<Array<Array<FloatArray>>>) {
@@ -1,3 +1,9 @@
package glimpse.core

internal val rawModel by lazy { IOUtils.loadModel(Glimpse.client.applicationContext, "model.tflite") }
import org.tensorflow.lite.Interpreter

private val rawModel by lazy { IOUtils.loadModel(Glimpse.client.applicationContext, "model.tflite") }

internal val intpreter by lazy {
Interpreter(rawModel, Interpreter.Options())
}

0 comments on commit 843ff43

Please sign in to comment.
You can’t perform that action at this time.