@ -39,9 +39,6 @@ class YOLOOnnxDetector(private val context: Context) {
var DEBUG_CLASS_FILTER : String ? = null // Set to class name to show only that class
var DEBUG_CLASS_FILTER : String ? = null // Set to class name to show only that class
var SHOW_ALL_CONFIDENCES = false // Show all detections with their confidences
var SHOW_ALL_CONFIDENCES = false // Show all detections with their confidences
// Benchmarking for CRITICAL-003
var BENCHMARKING_MODE = true // Enable detailed performance logging
private val detectionTimes = mutableListOf < Long > ( )
fun setCoordinateMode ( mode : String ) {
fun setCoordinateMode ( mode : String ) {
COORD_TRANSFORM_MODE = mode
COORD_TRANSFORM_MODE = mode
@ -55,25 +52,6 @@ class YOLOOnnxDetector(private val context: Context) {
Log . i ( TAG , " 📊 Show all confidences: $SHOW_ALL_CONFIDENCES " )
Log . i ( TAG , " 📊 Show all confidences: $SHOW_ALL_CONFIDENCES " )
}
}
fun printBenchmarkStats ( ) {
if ( detectionTimes . isNotEmpty ( ) ) {
val avg = detectionTimes . average ( )
val min = detectionTimes . minOrNull ( ) ?: 0L
val max = detectionTimes . maxOrNull ( ) ?: 0L
val count = detectionTimes . size
Log . i ( TAG , " 📈 BENCHMARK STATS ( ${if (ENABLE_MULTI_PREPROCESSING) "MULTI" else "SINGLE"} -PROCESSING): " )
Log . i ( TAG , " Count: $count detections " )
Log . i ( TAG , " Average: ${String.format("%.1f", avg)} ms " )
Log . i ( TAG , " Min: ${min} ms " )
Log . i ( TAG , " Max: ${max} ms " )
Log . i ( TAG , " Total: ${detectionTimes.sum()} ms " )
}
}
fun resetBenchmarkStats ( ) {
detectionTimes . clear ( )
Log . i ( TAG , " 📊 Benchmark stats reset " )
}
// Preprocessing enhancement techniques
// Preprocessing enhancement techniques
private const val ENABLE_CONTRAST_ENHANCEMENT = true
private const val ENABLE_CONTRAST_ENHANCEMENT = true
@ -395,19 +373,6 @@ class YOLOOnnxDetector(private val context: Context) {
val finalDetections = mergeAndFilterDetections ( allDetections , inputMat . cols ( ) , inputMat . rows ( ) )
val finalDetections = mergeAndFilterDetections ( allDetections , inputMat . cols ( ) , inputMat . rows ( ) )
val totalTime = System . currentTimeMillis ( ) - startTime
val totalTime = System . currentTimeMillis ( ) - startTime
// Record benchmark data
if ( BENCHMARKING_MODE ) {
detectionTimes . add ( totalTime )
val preprocessingType = if ( ENABLE_MULTI_PREPROCESSING ) " MULTI " else " SINGLE "
Log . i ( TAG , " 📊 BENCHMARK: $preprocessingType -processing took ${totalTime} ms ( ${detectionTimes.size} samples) " )
// Print stats every 10 detections
if ( detectionTimes . size % 10 == 0 ) {
printBenchmarkStats ( )
}
}
Log . i ( TAG , " ✅ Enhanced ONNX detection complete: ${finalDetections.size} objects in ${totalTime} ms " )
Log . i ( TAG , " ✅ Enhanced ONNX detection complete: ${finalDetections.size} objects in ${totalTime} ms " )
return finalDetections
return finalDetections