mkhodary101 commited on
Commit
81284aa
·
verified ·
1 Parent(s): 1228283

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -135,7 +135,14 @@ class FallDetection:
135
  @spaces.GPU
136
  def fall_detect(self, video_path):
137
  try:
 
 
 
 
 
 
138
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
139
  if not os.path.exists(self.model_path):
140
  model = YOLO("yolov8l.pt")
141
  model.save(self.model_path)
@@ -160,8 +167,12 @@ class FallDetection:
160
  ret, frame = cap.read()
161
  if not ret:
162
  break
 
163
  frame = cv2.resize(frame, (width, height))
164
- results = model(frame)
 
 
 
165
  for result in results:
166
  boxes = result.boxes.xyxy.cpu().numpy()
167
  classes = result.boxes.cls.cpu().numpy()
 
135
  @spaces.GPU
136
  def fall_detect(self, video_path):
137
  try:
138
+ import torch
139
+ import os
140
+ import cv2
141
+ import numpy as np
142
+ from ultralytics import YOLO
143
+
144
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
145
+
146
  if not os.path.exists(self.model_path):
147
  model = YOLO("yolov8l.pt")
148
  model.save(self.model_path)
 
167
  ret, frame = cap.read()
168
  if not ret:
169
  break
170
+
171
  frame = cv2.resize(frame, (width, height))
172
+
173
+ # ✅ FIX: Use `.predict()` to ensure proper YOLO inference
174
+ results = model.predict(frame, imgsz=640, device=device)
175
+
176
  for result in results:
177
  boxes = result.boxes.xyxy.cpu().numpy()
178
  classes = result.boxes.cls.cpu().numpy()