Spaces:
Runtime error
Runtime error
Updated app.py and fixed the error
Browse files
app.py
CHANGED
|
@@ -45,22 +45,23 @@ class MyModel(nn.Module):
|
|
| 45 |
def forward(self, x):
|
| 46 |
return self.model(x)
|
| 47 |
|
| 48 |
-
def
|
| 49 |
"""Test the model on the given videos and compute accuracy."""
|
|
|
|
|
|
|
| 50 |
self.model.eval()
|
| 51 |
|
| 52 |
predictions = []
|
| 53 |
|
| 54 |
with torch.no_grad():
|
| 55 |
-
for i, video_path in enumerate(video_paths):
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
return predictions
|
|
@@ -83,12 +84,13 @@ class MyModel(nn.Module):
|
|
| 83 |
|
| 84 |
model = MyModel().load_model('pre_3D_model.h5')
|
| 85 |
|
|
|
|
|
|
|
| 86 |
def classify_video(video):
|
| 87 |
-
prob = model.
|
| 88 |
|
| 89 |
-
label = "Non-violent" if prob >= 0.5 else "Violent"
|
| 90 |
-
|
| 91 |
-
violent_prob_percentage = f"{round((1 - prob) * 100, 2)}% chance of being violent"
|
| 92 |
|
| 93 |
return label, violent_prob_percentage
|
| 94 |
|
|
|
|
| 45 |
def forward(self, x):
|
| 46 |
return self.model(x)
|
| 47 |
|
| 48 |
+
def predict(self, video_path):
|
| 49 |
"""Test the model on the given videos and compute accuracy."""
|
| 50 |
+
print(video_path)
|
| 51 |
+
|
| 52 |
self.model.eval()
|
| 53 |
|
| 54 |
predictions = []
|
| 55 |
|
| 56 |
with torch.no_grad():
|
|
|
|
| 57 |
|
| 58 |
+
X = self.preprocess_video(video_path)
|
| 59 |
|
| 60 |
+
output = self.model(X)
|
| 61 |
+
pred = torch.sigmoid(output) # Apply sigmoid for binary classification
|
| 62 |
|
| 63 |
+
# Track predictions
|
| 64 |
+
predictions.append(pred.item())
|
| 65 |
|
| 66 |
|
| 67 |
return predictions
|
|
|
|
| 84 |
|
| 85 |
model = MyModel().load_model('pre_3D_model.h5')
|
| 86 |
|
| 87 |
+
|
| 88 |
+
|
| 89 |
def classify_video(video):
|
| 90 |
+
prob = model.predict(video)
|
| 91 |
|
| 92 |
+
label = "Non-violent" if prob[0] >= 0.5 else "Violent"
|
| 93 |
+
violent_prob_percentage = f"{round((1 - prob[0]) * 100, 2)}% chance of being violent"
|
|
|
|
| 94 |
|
| 95 |
return label, violent_prob_percentage
|
| 96 |
|