Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -312,8 +312,11 @@ def lstm_anomaly_detection(X, feature_columns, num_anomalies=10, epochs=100, bat
|
|
| 312 |
|
| 313 |
def emotion_anomaly_detection(emotion_data, num_anomalies=10, epochs=100, batch_size=64):
|
| 314 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 315 |
-
X = torch.FloatTensor(emotion_data.values
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
model = LSTMAutoencoder(input_size=1).to(device)
|
| 319 |
criterion = nn.MSELoss()
|
|
@@ -495,7 +498,7 @@ def process_video(video_path, num_anomalies, num_components, desired_fps, batch_
|
|
| 495 |
anomaly_scores_all = normalize_scores(anomaly_scores_all)
|
| 496 |
anomaly_scores_comp = normalize_scores(anomaly_scores_comp)
|
| 497 |
|
| 498 |
-
# Perform anomaly detection for each emotion
|
| 499 |
emotion_anomalies = {}
|
| 500 |
for emotion in ['fear', 'sad', 'angry', 'happy', 'surprise', 'neutral']:
|
| 501 |
anomalies, scores, indices = emotion_anomaly_detection(df[emotion], num_anomalies=num_anomalies)
|
|
|
|
| 312 |
|
| 313 |
def emotion_anomaly_detection(emotion_data, num_anomalies=10, epochs=100, batch_size=64):
|
| 314 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 315 |
+
X = torch.FloatTensor(emotion_data.values).to(device)
|
| 316 |
+
if X.dim() == 1:
|
| 317 |
+
X = X.unsqueeze(0).unsqueeze(2) # Add batch and feature dimensions
|
| 318 |
+
elif X.dim() == 2:
|
| 319 |
+
X = X.unsqueeze(0) # Add batch dimension
|
| 320 |
|
| 321 |
model = LSTMAutoencoder(input_size=1).to(device)
|
| 322 |
criterion = nn.MSELoss()
|
|
|
|
| 498 |
anomaly_scores_all = normalize_scores(anomaly_scores_all)
|
| 499 |
anomaly_scores_comp = normalize_scores(anomaly_scores_comp)
|
| 500 |
|
| 501 |
+
# Perform anomaly detection for each emotion using LSTM autoencoder
|
| 502 |
emotion_anomalies = {}
|
| 503 |
for emotion in ['fear', 'sad', 'angry', 'happy', 'surprise', 'neutral']:
|
| 504 |
anomalies, scores, indices = emotion_anomaly_detection(df[emotion], num_anomalies=num_anomalies)
|