Spaces:
Sleeping
Sleeping
changes num_frames
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ from pathlib import Path
|
|
| 19 |
# 1. MODEL CONFIGURATION (Giữ nguyên logic của bạn)
|
| 20 |
# ============================================================
|
| 21 |
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 22 |
-
MODEL_PATH = "
|
| 23 |
|
| 24 |
class EfficientNetLSTM(nn.Module):
|
| 25 |
def __init__(self, hidden_size=256, num_layers=2, dropout=0.5):
|
|
@@ -71,7 +71,7 @@ transform = A.Compose([
|
|
| 71 |
class FallDetectionSystem:
|
| 72 |
def __init__(self):
|
| 73 |
# Config
|
| 74 |
-
self.num_frames =
|
| 75 |
self.conf_thres = 0.5
|
| 76 |
self.output_dir = Path("fall_videos")
|
| 77 |
self.output_dir.mkdir(exist_ok=True)
|
|
@@ -111,8 +111,8 @@ class FallDetectionSystem:
|
|
| 111 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 112 |
|
| 113 |
# Logic lấy 16 frames (như code cũ)
|
| 114 |
-
if total_frames >=
|
| 115 |
-
indices = np.linspace(0, total_frames - 1,
|
| 116 |
else:
|
| 117 |
indices = np.arange(total_frames)
|
| 118 |
|
|
@@ -125,7 +125,7 @@ class FallDetectionSystem:
|
|
| 125 |
cap.release()
|
| 126 |
|
| 127 |
# Pad frame nếu thiếu
|
| 128 |
-
while len(frames) <
|
| 129 |
|
| 130 |
# Predict
|
| 131 |
video_tensor = torch.stack(frames).unsqueeze(0).to(DEVICE)
|
|
@@ -231,7 +231,7 @@ class FallDetectionSystem:
|
|
| 231 |
self._stop_recording_if_active(save=True)
|
| 232 |
|
| 233 |
else:
|
| 234 |
-
cv2.putText(frame_bgr, f"Buffering: {len(self.buffer)}/
|
| 235 |
|
| 236 |
# Cập nhật Log
|
| 237 |
if log_entry:
|
|
|
|
| 19 |
# 1. MODEL CONFIGURATION (Giữ nguyên logic của bạn)
|
| 20 |
# ============================================================
|
| 21 |
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 22 |
+
MODEL_PATH = "best_model_efficientnet_lstm_v2.pth"
|
| 23 |
|
| 24 |
class EfficientNetLSTM(nn.Module):
|
| 25 |
def __init__(self, hidden_size=256, num_layers=2, dropout=0.5):
|
|
|
|
| 71 |
class FallDetectionSystem:
|
| 72 |
def __init__(self):
|
| 73 |
# Config
|
| 74 |
+
self.num_frames = 32
|
| 75 |
self.conf_thres = 0.5
|
| 76 |
self.output_dir = Path("fall_videos")
|
| 77 |
self.output_dir.mkdir(exist_ok=True)
|
|
|
|
| 111 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 112 |
|
| 113 |
# Logic lấy 16 frames (như code cũ)
|
| 114 |
+
if total_frames >= 32:
|
| 115 |
+
indices = np.linspace(0, total_frames - 1, 32, dtype=int)
|
| 116 |
else:
|
| 117 |
indices = np.arange(total_frames)
|
| 118 |
|
|
|
|
| 125 |
cap.release()
|
| 126 |
|
| 127 |
# Pad frame nếu thiếu
|
| 128 |
+
while len(frames) < 32: frames.append(frames[-1])
|
| 129 |
|
| 130 |
# Predict
|
| 131 |
video_tensor = torch.stack(frames).unsqueeze(0).to(DEVICE)
|
|
|
|
| 231 |
self._stop_recording_if_active(save=True)
|
| 232 |
|
| 233 |
else:
|
| 234 |
+
cv2.putText(frame_bgr, f"Buffering: {len(self.buffer)}/32", (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 0), 2)
|
| 235 |
|
| 236 |
# Cập nhật Log
|
| 237 |
if log_entry:
|