litert-models / android /DetectorTargets.kt
unicorn who dev
Complete FireViewer Android learning SDK, source and verification records
dee7f43 verified
Raw History Blame Contribute Delete
829 Bytes
package org.fireviewer.litert.training
/** Coordinates refer to the normalized image supplied to the model. */
data class ReviewedBox(val x1: Float, val y1: Float, val x2: Float, val y2: Float, val label: Int)
fun detectorTargets(boxes: List<ReviewedBox>, classCount: Int): FloatArray {
require(classCount > 0 && boxes.size <= 100)
val values = FloatArray(600)
boxes.forEachIndexed { index, box ->
require(listOf(box.x1, box.y1, box.x2, box.y2).all { it.isFinite() && it in 0f..1f })
require(box.x1 < box.x2 && box.y1 < box.y2 && box.label in 0 until classCount)
val row = index * 6
values[row] = box.x1; values[row + 1] = box.y1
values[row + 2] = box.x2; values[row + 3] = box.y2
values[row + 4] = box.label.toFloat(); values[row + 5] = 1f
}
return values
}