|
6 | 6 | "use client"; |
7 | 7 | import { useRef, useEffect } from "react"; |
8 | 8 | import type { PipelineResult } from "../types/inference"; |
| 9 | +import { BEHAVIOR_CLASSES } from "../types/inference"; |
9 | 10 |
|
10 | 11 | // COCO-17 skeleton connections |
11 | 12 | const SKELETON: [number, number][] = [ |
@@ -163,21 +164,41 @@ export default function DetectorVideoCanvas({ videoRef, canvasRef, result, isCam |
163 | 164 | </div> |
164 | 165 | )} |
165 | 166 |
|
166 | | - {/* Behavior label */} |
167 | | - {result?.behavior && ( |
168 | | - <div style={{ |
169 | | - position: "absolute", top: 8, left: 8, padding: "6px 14px", |
170 | | - borderRadius: "var(--r-md)", fontSize: "0.85rem", fontWeight: 700, |
171 | | - fontFamily: "'Fredoka',sans-serif", |
172 | | - background: "rgba(0,0,0,0.65)", color: "white", |
173 | | - border: "1px solid rgba(255,255,255,0.15)", |
174 | | - }}> |
175 | | - {fmt(result.behavior.className)} |
176 | | - <span style={{ marginLeft: 8, fontSize: "0.75rem", opacity: 0.7 }}> |
177 | | - {(result.behavior.probabilities[result.behavior.predictedClass] * 100).toFixed(0)}% |
178 | | - </span> |
179 | | - </div> |
180 | | - )} |
| 167 | + {/* Behavior label — show "Normal Activity" when non_autistic > 50%, otherwise top ASD class */} |
| 168 | + {result?.behavior && result.behavior.probabilities.length >= 6 && (() => { |
| 169 | + const probs = result.behavior!.probabilities; |
| 170 | + const nonAutisticProb = probs[5]; |
| 171 | + let displayClass: string; |
| 172 | + let displayProb: number; |
| 173 | + if (nonAutisticProb > 0.5) { |
| 174 | + displayClass = "Normal Activity"; |
| 175 | + displayProb = nonAutisticProb; |
| 176 | + } else { |
| 177 | + // Find highest ASD behavior (indices 0-4) |
| 178 | + let maxIdx = 0, maxP = probs[0]; |
| 179 | + for (let i = 1; i < 5; i++) { |
| 180 | + if (probs[i] > maxP) { maxP = probs[i]; maxIdx = i; } |
| 181 | + } |
| 182 | + displayClass = fmt(BEHAVIOR_CLASSES[maxIdx]); |
| 183 | + displayProb = maxP; |
| 184 | + } |
| 185 | + const isNormal = nonAutisticProb > 0.5; |
| 186 | + return ( |
| 187 | + <div style={{ |
| 188 | + position: "absolute", top: 8, left: 8, padding: "6px 14px", |
| 189 | + borderRadius: "var(--r-md)", fontSize: "0.85rem", fontWeight: 700, |
| 190 | + fontFamily: "'Fredoka',sans-serif", |
| 191 | + background: isNormal ? "rgba(58,99,68,0.75)" : "rgba(0,0,0,0.65)", |
| 192 | + color: "white", |
| 193 | + border: "1px solid rgba(255,255,255,0.15)", |
| 194 | + }}> |
| 195 | + {displayClass} |
| 196 | + <span style={{ marginLeft: 8, fontSize: "0.75rem", opacity: 0.7 }}> |
| 197 | + {(displayProb * 100).toFixed(0)}% |
| 198 | + </span> |
| 199 | + </div> |
| 200 | + ); |
| 201 | + })()} |
181 | 202 | </div> |
182 | 203 | ); |
183 | 204 | } |
0 commit comments