Skip to content

Instantly share code, notes, and snippets.

fun processOutput(data: Array<Array<Array<FloatArray>>>): Map<Int, Float> {
val output = data[0] //output is now 13x13x285
val flatOutput = mutableListOf<Float>()
output.forEach { flatOutput.addAll(it.flatten()) }
val resultsMap = mutableMapOf<Int, Float>()
val gridHeight = 13
val gridWidth = 13
@tomekdz
tomekdz / run.kt
Last active September 20, 2018 12:35
override fun process(bitmap: Bitmap): List<Detection> {
convertBitmapToByteBuffer(bitmap)
tensorflow.run(imgData, output)
return processOutput(output)
}
private fun convertBitmapToByteBuffer(bitmap: Bitmap) {
imgData.rewind()
val resizedBitmap = Bitmap.createScaledBitmap(bitmap, 416, 416, true)
resizedBitmap.getPixels(intValues, 0, resizedBitmap.width, 0, 0, resizedBitmap.width, resizedBitmap.height)
@tomekdz
tomekdz / gist:b16c5d5f649cf2bb363719e13f8aa0cb
Created September 20, 2018 12:29
Converting tensorflow frozen graph to .tflite
./bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=yolov2-tiny.pb \
--output_file=foo.tflite  \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_arrays=input \
--input_shapes=1,416,416,3 \
--output_arrays=output
classes= 52
train = cards/train.txt
valid = cards/test.txt
names = obj.names
backup = output/