Spaces:
Sleeping
Sleeping
Zhen Ye
commited on
Commit
·
fe670b9
1
Parent(s):
3a793fe
feat: Radar historic traces and fix DETR crash
Browse files- frontend/js/ui/radar.js +67 -7
- models/detectors/detr.py +1 -1
frontend/js/ui/radar.js
CHANGED
|
@@ -177,13 +177,73 @@ APP.ui.radar.render = function (canvasId, trackSource) {
|
|
| 177 |
ctx.font = "bold 11px monospace";
|
| 178 |
ctx.fillText(det.id, px + 8, py + 3);
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
ctx.setLineDash([]);
|
| 188 |
|
| 189 |
const mx = (cx + px) * 0.5;
|
|
|
|
| 177 |
ctx.font = "bold 11px monospace";
|
| 178 |
ctx.fillText(det.id, px + 8, py + 3);
|
| 179 |
|
| 180 |
+
// Draw Trail (Breadcrumbs)
|
| 181 |
+
if (det.history && det.history.length > 0 && det.gpt_distance_m) {
|
| 182 |
+
// Stadiametric Ranging Logic:
|
| 183 |
+
// D_new = D_0 * (H_0 / H_new)
|
| 184 |
+
// We assume det.history[0] is roughly frame 0 or close to it?
|
| 185 |
+
// No, history is rolling window of 30 frames.
|
| 186 |
+
// We need the reference height H_0 from the first measurement.
|
| 187 |
+
// det.gpt_distance_m corresponds to the box size at the moment GPT ran.
|
| 188 |
+
// Let's assume current box H corresponds to current Distance D.
|
| 189 |
+
// For past history point i: D_i = D_curr * (H_curr / H_i)
|
| 190 |
+
|
| 191 |
+
// det.bbox is current.
|
| 192 |
+
// det.history = [bbox_old, ..., bbox_new]
|
| 193 |
+
|
| 194 |
+
const currH = det.bbox.h;
|
| 195 |
+
const currDist = det.gpt_distance_m;
|
| 196 |
+
|
| 197 |
+
ctx.save();
|
| 198 |
+
ctx.globalAlpha = 0.4;
|
| 199 |
+
|
| 200 |
+
// Draw line
|
| 201 |
+
ctx.beginPath();
|
| 202 |
+
|
| 203 |
+
det.history.forEach((hBox, i) => {
|
| 204 |
+
// hBox is [x, y, x2, y2] raw pixels (from inference.py history)
|
| 205 |
+
// Logic: we need to normalize to current frame w/h to match radar logic?
|
| 206 |
+
// radar logic uses:
|
| 207 |
+
// rPx = (dist / maxRange) * R
|
| 208 |
+
// angle = fov mapping
|
| 209 |
+
|
| 210 |
+
// Problem: hBox is RAW pixels from backend inference.py (see SpeedEstimator)
|
| 211 |
+
// tracker logic `normBBox` normalized the *current* bbox.
|
| 212 |
+
// But history in `det` might be passed through from backend?
|
| 213 |
+
// In `inference.py`, `track['history']` stores `track['bbox']`, which is [x1, y1, x2, y2] pixels.
|
| 214 |
+
// Backend sends this. `tracker.js` copies it.
|
| 215 |
+
|
| 216 |
+
// We need frame dimensions `fw`, `fh` (defined earlier in visualizer or state)
|
| 217 |
+
// If fw not available, use state.frame.w
|
| 218 |
+
const fw = state.frame.w || 1280;
|
| 219 |
+
const fh = state.frame.h || 720;
|
| 220 |
+
|
| 221 |
+
const hH = (hBox[3] - hBox[1]) / fh; // Normalized height
|
| 222 |
+
const hX = ((hBox[0] + hBox[2]) / 2) / fw; // Normalized center X
|
| 223 |
+
|
| 224 |
+
if (hH <= 0.001) return;
|
| 225 |
+
|
| 226 |
+
// Stadiametric: D_hist = D_curr * (currH_norm / hH_norm)
|
| 227 |
+
let distHist = currDist * (det.bbox.h / hH);
|
| 228 |
+
|
| 229 |
+
// Project to Radar
|
| 230 |
+
const rPxHist = (clamp(distHist, 0, maxRangeM) / maxRangeM) * R;
|
| 231 |
+
const txHist = hX - 0.5;
|
| 232 |
+
const angleHist = (-Math.PI / 2) + (txHist * fovRad);
|
| 233 |
+
|
| 234 |
+
const pxHist = cx + Math.cos(angleHist) * rPxHist;
|
| 235 |
+
const pyHist = cy + Math.sin(angleHist) * rPxHist;
|
| 236 |
+
|
| 237 |
+
if (i === 0) ctx.moveTo(pxHist, pyHist);
|
| 238 |
+
else ctx.lineTo(pxHist, pyHist);
|
| 239 |
+
});
|
| 240 |
+
|
| 241 |
+
ctx.strokeStyle = col;
|
| 242 |
+
ctx.lineWidth = 1;
|
| 243 |
+
ctx.stroke();
|
| 244 |
+
ctx.restore();
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
ctx.setLineDash([]);
|
| 248 |
|
| 249 |
const mx = (cx + px) * 0.5;
|
models/detectors/detr.py
CHANGED
|
@@ -22,7 +22,7 @@ class DetrDetector(ObjectDetector):
|
|
| 22 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
logging.info("Loading %s onto %s", self.MODEL_NAME, self.device)
|
| 24 |
self.processor = DetrImageProcessor.from_pretrained(self.MODEL_NAME, revision="no_timm")
|
| 25 |
-
self.model = DetrForObjectDetection.from_pretrained(self.MODEL_NAME, revision="no_timm")
|
| 26 |
self.model.to(self.device)
|
| 27 |
self.model.eval()
|
| 28 |
|
|
|
|
| 22 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
logging.info("Loading %s onto %s", self.MODEL_NAME, self.device)
|
| 24 |
self.processor = DetrImageProcessor.from_pretrained(self.MODEL_NAME, revision="no_timm")
|
| 25 |
+
self.model = DetrForObjectDetection.from_pretrained(self.MODEL_NAME, revision="no_timm", use_safetensors=False)
|
| 26 |
self.model.to(self.device)
|
| 27 |
self.model.eval()
|
| 28 |
|