Spaces:
Sleeping
Sleeping
Update tasks/audio.py
Browse files- tasks/audio.py +8 -8
tasks/audio.py
CHANGED
@@ -61,7 +61,7 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
61 |
model, device = load_model(model_path)
|
62 |
|
63 |
def preprocess_audio(example, target_length=32000):
|
64 |
-
|
65 |
Convert dataset into tensors:
|
66 |
- Convert to tensor
|
67 |
- Normalize waveform
|
@@ -94,13 +94,13 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
94 |
predictions = []
|
95 |
|
96 |
with torch.no_grad():
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
#--------------------------------------------------------------------------------------------
|
106 |
# YOUR MODEL INFERENCE STOPS HERE
|
|
|
61 |
model, device = load_model(model_path)
|
62 |
|
63 |
def preprocess_audio(example, target_length=32000):
|
64 |
+
"""
|
65 |
Convert dataset into tensors:
|
66 |
- Convert to tensor
|
67 |
- Normalize waveform
|
|
|
94 |
predictions = []
|
95 |
|
96 |
with torch.no_grad():
|
97 |
+
for waveforms, labels in train_loader:
|
98 |
+
waveforms, labels = waveforms.to(device), labels.to(device)
|
99 |
+
|
100 |
+
outputs = model(waveforms)
|
101 |
+
predicted_label = torch.argmax(F.softmax(outputs, dim=1), dim=1)
|
102 |
+
true_labels.extend(labels.cpu().numpy())
|
103 |
+
predicted_labels.extend(predicted_label.cpu().numpy())
|
104 |
|
105 |
#--------------------------------------------------------------------------------------------
|
106 |
# YOUR MODEL INFERENCE STOPS HERE
|