This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor: allow posibiliy of gpu

+31 -8
+1
posedetection/build.gradle.kts
··· 94 94 implementation("com.google.ai.edge.litert:litert:1.4.1") 95 95 implementation("com.google.ai.edge.litert:litert-support:1.4.1") 96 96 implementation("com.google.ai.edge.litert:litert-metadata:1.4.1") 97 + implementation("com.google.ai.edge.litert:litert-gpu:1.4.1") 97 98 } 98 99 99 100 }
+2 -2
posedetection/src/androidMain/kotlin/com.performancecoachlab/posedetection/camera/CameraView.android.kt
··· 141 141 142 142 // Throttle detectors to avoid doing heavy work every frame. 143 143 // Tune these to balance smoothness vs CPU usage. 144 - val objectIntervalMs = 66L // ~10 FPS 145 - val poseIntervalMs = 66L // ~10 FPS 144 + val objectIntervalMs = 20L 145 + val poseIntervalMs = 20L 146 146 val lastObjectRunAtMs = remember { AtomicLong(0L) } 147 147 val lastPoseRunAtMs = remember { AtomicLong(0L) } 148 148
-3
posedetection/src/androidMain/kotlin/com/performancecoachlab/posedetection/camera/Utils.android.kt
··· 553 553 ) 554 554 555 555 fun ModelInfo.label(cls: Int): String{ 556 - Logger.d{ "ModelInfo.label: cls=$cls" } 557 556 this.labels.let { labelsList -> 558 557 if (cls in labelsList.indices) { 559 - Logger.d{ "ModelInfo.label: $cls = ${labelsList[cls]}" } 560 558 return labelsList[cls] 561 559 } 562 560 } 563 - Logger.d{ "ModelInfo.label: $cls not in labels" } 564 561 return "$cls" 565 562 } 566 563
+28 -3
posedetection/src/androidMain/kotlin/com/performancecoachlab/posedetection/custom/CustomObjectModel.android.kt
··· 4 4 import androidx.compose.ui.platform.LocalContext 5 5 import co.touchlab.kermit.Logger 6 6 import org.tensorflow.lite.Interpreter 7 + import org.tensorflow.lite.gpu.CompatibilityList 8 + import org.tensorflow.lite.gpu.GpuDelegate 9 + import org.tensorflow.lite.gpu.GpuDelegateFactory 7 10 import org.tensorflow.lite.support.common.FileUtil 8 11 import org.tensorflow.lite.support.metadata.MetadataExtractor 9 12 import java.nio.MappedByteBuffer ··· 13 16 if (modelPath.androidModelPath == null) { 14 17 throw IllegalArgumentException("Android model path cannot be null") 15 18 } 16 - val options = Interpreter.Options().apply { 17 - this.setNumThreads(4) 19 + // Prefer GPU if available, fall back to CPU. 20 + val (options, gpuDelegate) = runCatching { 21 + val delegate = GpuDelegate() 22 + val opts = Interpreter.Options().apply { 23 + addDelegate(delegate) 24 + // Threads often don’t matter with GPU delegate; keep small to reduce contention. 25 + setNumThreads(2) 26 + } 27 + Logger.d{ "TFLite GPU delegate available" } 28 + opts to delegate 29 + }.onFailure { t -> 30 + Logger.w(t) { "TFLite GPU delegate not available; falling back to CPU" } 31 + }.getOrElse { 32 + Interpreter.Options().apply { setNumThreads(4) } to null 18 33 } 19 34 20 35 val model = FileUtil.loadMappedFile(LocalContext.current, modelPath.androidModelPath) 21 36 val labels = labels(model) 22 - val interpreter = Interpreter(model, options) 37 + 38 + val interpreter = runCatching { 39 + Interpreter(model, options) 40 + }.onFailure { t -> 41 + // If GPU interpreter creation fails, retry on CPU. 42 + Logger.w(t) { "TFLite GPU Failed to create GPU TFLite interpreter; retrying on CPU" } 43 + gpuDelegate?.close() 44 + }.getOrElse { 45 + val cpuOptions = Interpreter.Options().apply { setNumThreads(4) } 46 + Interpreter(model, cpuOptions) 47 + } 23 48 24 49 val inputShape = interpreter.getInputTensor(0)?.shape() 25 50 val outputShape = interpreter.getOutputTensor(0)?.shape()