webapp1 commited on
Commit
fc35f8f
·
verified ·
1 Parent(s): 527c826

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -164,21 +164,21 @@ def run_temporal_analysis(stream_id, frames_3d_copy, prob_max, prob_mean, prob_m
164
 
165
  try:
166
  ensemble_probs = model_svm.predict_proba(combined)[0]
167
- final_idx = int(model_svm.predict(combined)[0])
168
  confidence = float(ensemble_probs[final_idx] * 100)
169
  severity = classes[final_idx]
170
- except Exception as svm_err:
171
- final_idx = min(int(np.argmax(prob_max)), 2) if np.sum(prob_max) > 0 else min(int(np.argmax(prob_3d)), 2)
172
- confidence = float(np.max(prob_max)) * 100 if np.sum(prob_max) > 0 else float(np.max(prob_3d)) * 100
173
  severity = classes[final_idx]
174
 
175
  state["severity"] = severity.capitalize()
176
  state["confidence"] = round(confidence, 1)
 
177
  state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
178
 
179
- # 🚨 FIX: Strict Dual-Consensus checks to prevent IP camera frame-drop false positives!
180
- # Requires 75% overall confidence AND at least 50% spatial confirmation from YOLO of an actual object collision.
181
- if confidence > 75 and yolo_max_conf > 50.0:
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()
@@ -186,7 +186,7 @@ def run_temporal_analysis(stream_id, frames_3d_copy, prob_max, prob_mean, prob_m
186
  state["label"] = f"Analyzing... ({severity.capitalize()})"
187
 
188
  except Exception as e:
189
- print(f"AI Error in Temporal Engine: {e}", flush=True)
190
  finally:
191
  if state: state["is_analyzing"] = False
192
 
 
164
 
165
  try:
166
  ensemble_probs = model_svm.predict_proba(combined)[0]
167
+ final_idx = model_svm.predict(combined)[0]
168
  confidence = float(ensemble_probs[final_idx] * 100)
169
  severity = classes[final_idx]
170
+ except:
171
+ final_idx = min(int(np.argmax(prob_max)), 2)
172
+ confidence = float(np.max(prob_max)) * 100
173
  severity = classes[final_idx]
174
 
175
  state["severity"] = severity.capitalize()
176
  state["confidence"] = round(confidence, 1)
177
+ state["cnn"] = round(yolo_max_conf, 1)
178
  state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
179
 
180
+ # FIX: Restored threshold back to 85 from 75 to completely eliminate false positives on noisy live feeds
181
+ if confidence > 85:
 
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()
 
186
  state["label"] = f"Analyzing... ({severity.capitalize()})"
187
 
188
  except Exception as e:
189
+ print(f"AI Error: {e}", flush=True)
190
  finally:
191
  if state: state["is_analyzing"] = False
192