Spaces:
Paused
Paused
Zhen Ye commited on
Commit ·
fe670b9
1
Parent(s): 3a793fe
feat: Radar historic traces and fix DETR crash
Browse filesFiles changed (2)
176 unmodified lines177178179180181182183184185186187188189176 unmodified linesctx.font = "bold 11px monospace";ctx.fillText(det.id, px + 8, py + 3);ctx.strokeStyle = "rgba(255, 255, 255, 0.4)";ctx.lineWidth = 1;ctx.setLineDash([2, 2]);ctx.beginPath();ctx.moveTo(cx, cy);ctx.lineTo(px, py);ctx.stroke();ctx.setLineDash([]);const mx = (cx + px) * 0.5;176 unmodified lines177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249176 unmodified linesctx.font = "bold 11px monospace";ctx.fillText(det.id, px + 8, py + 3);// Draw Trail (Breadcrumbs)if (det.history && det.history.length > 0 && det.gpt_distance_m) {// Stadiametric Ranging Logic:// D_new = D_0 * (H_0 / H_new)// We assume det.history[0] is roughly frame 0 or close to it?// No, history is rolling window of 30 frames.// We need the reference height H_0 from the first measurement.// det.gpt_distance_m corresponds to the box size at the moment GPT ran.// Let's assume current box H corresponds to current Distance D.// For past history point i: D_i = D_curr * (H_curr / H_i)// det.bbox is current.// det.history = [bbox_old, ..., bbox_new]const currH = det.bbox.h;const currDist = det.gpt_distance_m;ctx.save();ctx.globalAlpha = 0.4;// Draw linectx.beginPath();det.history.forEach((hBox, i) => {// hBox is [x, y, x2, y2] raw pixels (from inference.py history)// Logic: we need to normalize to current frame w/h to match radar logic?// radar logic uses:// rPx = (dist / maxRange) * R// angle = fov mapping// Problem: hBox is RAW pixels from backend inference.py (see SpeedEstimator)// tracker logic `normBBox` normalized the *current* bbox.// But history in `det` might be passed through from backend?// In `inference.py`, `track['history']` stores `track['bbox']`, which is [x1, y1, x2, y2] pixels.// Backend sends this. `tracker.js` copies it.// We need frame dimensions `fw`, `fh` (defined earlier in visualizer or state)// If fw not available, use state.frame.wconst fw = state.frame.w || 1280;const fh = state.frame.h || 720;const hH = (hBox[3] - hBox[1]) / fh; // Normalized heightconst hX = ((hBox[0] + hBox[2]) / 2) / fw; // Normalized center Xif (hH <= 0.001) return;// Stadiametric: D_hist = D_curr * (currH_norm / hH_norm)let distHist = currDist * (det.bbox.h / hH);// Project to Radarconst rPxHist = (clamp(distHist, 0, maxRangeM) / maxRangeM) * R;const txHist = hX - 0.5;const angleHist = (-Math.PI / 2) + (txHist * fovRad);const pxHist = cx + Math.cos(angleHist) * rPxHist;const pyHist = cy + Math.sin(angleHist) * rPxHist;if (i === 0) ctx.moveTo(pxHist, pyHist);else ctx.lineTo(pxHist, pyHist);});ctx.strokeStyle = col;ctx.lineWidth = 1;ctx.stroke();ctx.restore();}ctx.setLineDash([]);const mx = (cx + px) * 0.5;
21 unmodified lines2223242526272821 unmodified linesself.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")logging.info("Loading %s onto %s", self.MODEL_NAME, self.device)self.processor = DetrImageProcessor.from_pretrained(self.MODEL_NAME, revision="no_timm")self.model = DetrForObjectDetection.from_pretrained(self.MODEL_NAME, revision="no_timm")self.model.to(self.device)self.model.eval()21 unmodified lines2223242526272821 unmodified linesself.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")logging.info("Loading %s onto %s", self.MODEL_NAME, self.device)self.processor = DetrImageProcessor.from_pretrained(self.MODEL_NAME, revision="no_timm")self.model = DetrForObjectDetection.from_pretrained(self.MODEL_NAME, revision="no_timm", use_safetensors=False)self.model.to(self.device)self.model.eval()
frontend/js/ui/radar.js+67-7
models/detectors/detr.py+1-1