danielle2035 commited on
Commit
45ee044
·
verified ·
1 Parent(s): e0d9b3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- app.py TrackIQ Backend (v6 — CORRIGÉ : Human/Person, CONF, modèle)
3
  """
4
  import os
5
  os.environ.setdefault("YOLO_CONFIG_DIR", "/tmp")
@@ -30,10 +30,9 @@ LOG_DIR = BASE / "logs"; LOG_DIR.mkdir(exist_ok=True)
30
  MODELS_DIR = BASE / "models"; MODELS_DIR.mkdir(exist_ok=True)
31
  JOB_STATE_PATH = LOG_DIR / "jobs_state.json"
32
 
33
- # ── CORRECTION 1 : "Person" → "Human" pour matcher l'UI ─────────────────────
34
- # Mapping COCO réel → nom affiché (index COCO officiel)
35
  COCO_TO_LABEL = {
36
- 0: "Human", # ← WAS "Person" — doit correspondre à ce que l'UI envoie
37
  1: "Bicycle",
38
  2: "Vehicle",
39
  3: "Motorcycle",
@@ -58,17 +57,17 @@ CLASS_COLORS = {
58
  "Motorcycle": (80, 200, 80),
59
  "Truck": (0, 180, 255),
60
  "Bus": (220, 80, 255),
61
- "Human": (236, 72, 153), # ← WAS "Person"
62
  "Bicycle": (6, 182, 212),
63
  "Traffic light": (239, 68, 68),
64
  "Road sign": (249, 115, 22),
65
  }
66
 
67
  # ── CORRECTION 2 : seuil de confiance abaissé + résolution augmentée ─────────
68
- CONF = 0.25 #WAS 0.40 (trop élevé pour webcam intérieure)
69
  IOU = 0.45
70
  SKIP = 1
71
- INFER_SZ = 640 # ← WAS 320 (plus de précision)
72
 
73
  _jobs: Dict[str, dict] = {}
74
  _sse_queues: Dict[str, queue.Queue] = {}
@@ -902,7 +901,7 @@ def api_webcam_start():
902
  _webcam_current_counts = defaultdict(int)
903
  _webcam_seen_track_ids = set()
904
 
905
- print(f" Webcam started with classes: {classes}")
906
  return jsonify({"status": "started"}), 200
907
 
908
  @app.route("/api/webcam/frame", methods=["POST"])
@@ -978,17 +977,20 @@ def api_webcam_stop():
978
  @app.route("/api/webcam/stats")
979
  def api_webcam_stats():
980
  with _webcam_lock:
981
- by_class = dict(_webcam_detections_by_class)
 
 
 
982
  frame_counts = dict(_webcam_current_counts)
983
  return jsonify({
984
  "active": _webcam_active,
985
  "frame": _webcam_frame_count,
986
- "detections": _webcam_detections,
987
- "detections_by_class": by_class,
 
988
  "frame_counts": frame_counts,
989
- "unique_counts": by_class
990
  }), 200
991
-
992
  # ── Video streaming endpoints ─────────────────────────────────────────────────
993
 
994
  @app.route("/api/mjpeg/<jid>")
 
1
  """
2
+ app.py TrackIQ Backend
3
  """
4
  import os
5
  os.environ.setdefault("YOLO_CONFIG_DIR", "/tmp")
 
30
  MODELS_DIR = BASE / "models"; MODELS_DIR.mkdir(exist_ok=True)
31
  JOB_STATE_PATH = LOG_DIR / "jobs_state.json"
32
 
33
+ #
 
34
  COCO_TO_LABEL = {
35
+ 0: "Human",
36
  1: "Bicycle",
37
  2: "Vehicle",
38
  3: "Motorcycle",
 
57
  "Motorcycle": (80, 200, 80),
58
  "Truck": (0, 180, 255),
59
  "Bus": (220, 80, 255),
60
+ "Human": (236, 72, 153),
61
  "Bicycle": (6, 182, 212),
62
  "Traffic light": (239, 68, 68),
63
  "Road sign": (249, 115, 22),
64
  }
65
 
66
  # ── CORRECTION 2 : seuil de confiance abaissé + résolution augmentée ─────────
67
+ CONF = 0.25 # WAS 0.40 (trop élevé pour webcam intérieure)
68
  IOU = 0.45
69
  SKIP = 1
70
+ INFER_SZ = 640
71
 
72
  _jobs: Dict[str, dict] = {}
73
  _sse_queues: Dict[str, queue.Queue] = {}
 
901
  _webcam_current_counts = defaultdict(int)
902
  _webcam_seen_track_ids = set()
903
 
904
+ print(f" Webcam started with classes: {classes}")
905
  return jsonify({"status": "started"}), 200
906
 
907
  @app.route("/api/webcam/frame", methods=["POST"])
 
977
  @app.route("/api/webcam/stats")
978
  def api_webcam_stats():
979
  with _webcam_lock:
980
+ # unique_counts = objets uniques vus depuis le début
981
+ unique_only = dict(_webcam_detections_by_class)
982
+ total_unique = sum(unique_only.values())
983
+ # frame_counts = ce qui est visible sur la frame courante seulement
984
  frame_counts = dict(_webcam_current_counts)
985
  return jsonify({
986
  "active": _webcam_active,
987
  "frame": _webcam_frame_count,
988
+ # detections = total uniques, pas cumul frames
989
+ "detections": total_unique,
990
+ "detections_by_class": unique_only,
991
  "frame_counts": frame_counts,
992
+ "unique_counts": unique_only,
993
  }), 200
 
994
  # ── Video streaming endpoints ─────────────────────────────────────────────────
995
 
996
  @app.route("/api/mjpeg/<jid>")