MuhammadAdil63 commited on
Commit
5a95121
Β·
1 Parent(s): c6eb6a7

fix3: torch.load

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -48,6 +48,18 @@ def _patch_gradio_client():
48
  pass
49
  _patch_gradio_client()
50
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  import os
52
  import sys
53
  import json
@@ -799,9 +811,9 @@ def run_yolo_seg(frame_rgb: np.ndarray, seg_conf: float) -> np.ndarray:
799
  n_written += int(binary.sum())
800
 
801
  detected_cls = [_YOLO_CLASS_NAMES[min(int(c) + 1, 25)] for c in cls_ids]
802
- print(f"[YOLO] Detections: {len(cls_ids)} | classes: {detected_cls} | "
803
  f"vessel px: {n_written} ({100 * n_written / (h * w):.1f}%)")
804
- print(f"[YOLO] seg_map unique labels: {np.unique(seg_map)}")
805
  return seg_map
806
 
807
  # ─────────────────────────────────────────────────────────────────────────────
@@ -1338,7 +1350,7 @@ def analyse(video_path, sten_conf, seg_conf, px_per_mm_override, progress=gr.Pro
1338
  det["overlap"]=float(binary_mask[y1:y2,x1:x2].sum())/max(area,1)
1339
 
1340
  # Step 3b β€” YOLOv8m-seg 26-class segmentation
1341
- progress(0.65, desc="Running YOLOv8m-seg…")
1342
  seg_map = run_yolo_seg(frame_rgb, seg_conf)
1343
  seg_overlay = render_nnunet_overlay(frame_rgb, seg_map)
1344
 
@@ -1498,7 +1510,7 @@ with gr.Blocks(css=CSS, title="Angio AI") as demo:
1498
  )
1499
  seg_conf = gr.Slider(
1500
  minimum=0.05, maximum=0.95, value=0.25, step=0.05,
1501
- label="Segmentation confidence threshold ",
1502
  info="Detections below this confidence are discarded by NMS",
1503
  )
1504
  px_per_mm = gr.Slider(
 
48
  pass
49
  _patch_gradio_client()
50
 
51
+ # ── PyTorch 2.7 global weights_only patch ────────────────────────────────────
52
+ # YOLO and other libraries call torch.load internally without weights_only=False.
53
+ # Monkey-patch torch.load to default to weights_only=False for all calls.
54
+ import torch as _torch
55
+ _orig_torch_load = _torch.load
56
+ def _patched_torch_load(f, map_location=None, pickle_module=None,
57
+ weights_only=False, mmap=None, **kwargs):
58
+ return _orig_torch_load(f, map_location=map_location,
59
+ pickle_module=pickle_module,
60
+ weights_only=False, **kwargs)
61
+ _torch.load = _patched_torch_load
62
+
63
  import os
64
  import sys
65
  import json
 
811
  n_written += int(binary.sum())
812
 
813
  detected_cls = [_YOLO_CLASS_NAMES[min(int(c) + 1, 25)] for c in cls_ids]
814
+ print(f"Segmentation Detections: {len(cls_ids)} | classes: {detected_cls} | "
815
  f"vessel px: {n_written} ({100 * n_written / (h * w):.1f}%)")
816
+ print(f"seg_map unique labels: {np.unique(seg_map)}")
817
  return seg_map
818
 
819
  # ─────────────────────────────────────────────────────────────────────────────
 
1350
  det["overlap"]=float(binary_mask[y1:y2,x1:x2].sum())/max(area,1)
1351
 
1352
  # Step 3b β€” YOLOv8m-seg 26-class segmentation
1353
+ progress(0.65, desc="Running seg model")
1354
  seg_map = run_yolo_seg(frame_rgb, seg_conf)
1355
  seg_overlay = render_nnunet_overlay(frame_rgb, seg_map)
1356
 
 
1510
  )
1511
  seg_conf = gr.Slider(
1512
  minimum=0.05, maximum=0.95, value=0.25, step=0.05,
1513
+ label="Segmentation confidence threshold",
1514
  info="Detections below this confidence are discarded by NMS",
1515
  )
1516
  px_per_mm = gr.Slider(