Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -177,8 +177,11 @@ def run_temporal_analysis(stream_id, frames_3d_copy, prob_max, prob_mean, prob_m
|
|
| 177 |
state["cnn"] = round(yolo_max_conf, 1)
|
| 178 |
state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
|
| 179 |
|
| 180 |
-
# FIX:
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
| 182 |
state["final_decision"] = True
|
| 183 |
state["label"] = f"Incident Logged: {severity.capitalize()}"
|
| 184 |
threading.Thread(target=process_accident_async, args=(stream_id, raw_frame, location, confidence, severity)).start()
|
|
@@ -337,7 +340,7 @@ def video_stream_gen(stream_id, source, location):
|
|
| 337 |
if w > 1280: frame = cv2.resize(frame, (1280, int(h * 1280 / w)))
|
| 338 |
|
| 339 |
if is_live:
|
| 340 |
-
state['progress'] = 100
|
| 341 |
elif total_frames > 0:
|
| 342 |
state['progress'] = (current_frame_idx / total_frames) * 100
|
| 343 |
|
|
@@ -365,7 +368,6 @@ def video_stream_gen(stream_id, source, location):
|
|
| 365 |
yolo_probs.append(probs)
|
| 366 |
if len(yolo_probs) > 10: yolo_probs.pop(0)
|
| 367 |
|
| 368 |
-
# LIVE update of Spatial UI data
|
| 369 |
if len(yolo_probs) > 0:
|
| 370 |
curr_max = np.max(yolo_probs, axis=0)
|
| 371 |
acc_conf = float(np.max(curr_max[:3])) * 100 if len(curr_max) >= 3 else float(np.max(curr_max)) * 100
|
|
@@ -376,12 +378,13 @@ def video_stream_gen(stream_id, source, location):
|
|
| 376 |
f_3d = cv2.resize(frame, (112, 112))
|
| 377 |
frames_3d.append(cv2.cvtColor(f_3d, cv2.COLOR_BGR2RGB))
|
| 378 |
|
| 379 |
-
# FIX: Removed artificial frame padding. It now strictly waits for 16 genuine frames.
|
| 380 |
-
# This prevents network stutters from being interpreted as "crashes" by the 3D-CNN.
|
| 381 |
if len(frames_3d) > 16:
|
| 382 |
frames_3d.pop(0)
|
| 383 |
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
| 385 |
state["is_analyzing"] = True
|
| 386 |
|
| 387 |
analysis_frames = list(frames_3d)
|
|
|
|
| 177 |
state["cnn"] = round(yolo_max_conf, 1)
|
| 178 |
state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
|
| 179 |
|
| 180 |
+
# FIX: Dynamic Threshold - 85% for strict Live IP noise filtering, 75% for fast Uploads detection
|
| 181 |
+
is_live_stream = state.get("is_live", False)
|
| 182 |
+
threshold = 85 if is_live_stream else 75
|
| 183 |
+
|
| 184 |
+
if confidence > threshold:
|
| 185 |
state["final_decision"] = True
|
| 186 |
state["label"] = f"Incident Logged: {severity.capitalize()}"
|
| 187 |
threading.Thread(target=process_accident_async, args=(stream_id, raw_frame, location, confidence, severity)).start()
|
|
|
|
| 340 |
if w > 1280: frame = cv2.resize(frame, (1280, int(h * 1280 / w)))
|
| 341 |
|
| 342 |
if is_live:
|
| 343 |
+
state['progress'] = 100
|
| 344 |
elif total_frames > 0:
|
| 345 |
state['progress'] = (current_frame_idx / total_frames) * 100
|
| 346 |
|
|
|
|
| 368 |
yolo_probs.append(probs)
|
| 369 |
if len(yolo_probs) > 10: yolo_probs.pop(0)
|
| 370 |
|
|
|
|
| 371 |
if len(yolo_probs) > 0:
|
| 372 |
curr_max = np.max(yolo_probs, axis=0)
|
| 373 |
acc_conf = float(np.max(curr_max[:3])) * 100 if len(curr_max) >= 3 else float(np.max(curr_max)) * 100
|
|
|
|
| 378 |
f_3d = cv2.resize(frame, (112, 112))
|
| 379 |
frames_3d.append(cv2.cvtColor(f_3d, cv2.COLOR_BGR2RGB))
|
| 380 |
|
|
|
|
|
|
|
| 381 |
if len(frames_3d) > 16:
|
| 382 |
frames_3d.pop(0)
|
| 383 |
|
| 384 |
+
# FIX: Adaptive Polling Rate - Analyzes 2x faster (every 5 frames instead of 10) for uploads
|
| 385 |
+
analyze_interval = 10 if is_live else 5
|
| 386 |
+
|
| 387 |
+
if len(frames_3d) == 16 and frame_count % analyze_interval == 0 and not state.get("is_analyzing"):
|
| 388 |
state["is_analyzing"] = True
|
| 389 |
|
| 390 |
analysis_frames = list(frames_3d)
|