Spaces:
Sleeping
Sleeping
Update tasks/audio.py
Browse files- tasks/audio.py +38 -0
tasks/audio.py
CHANGED
@@ -50,6 +50,44 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
50 |
|
51 |
#--------------------------------------------------------------------------------------------
|
52 |
# YOUR MODEL INFERENCE CODE HERE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
|
54 |
#--------------------------------------------------------------------------------------------
|
55 |
|
|
|
50 |
|
51 |
#--------------------------------------------------------------------------------------------
|
52 |
# YOUR MODEL INFERENCE CODE HERE
|
53 |
+
load_pretrained(dannywillowliu/frugal_ai_space)
|
54 |
+
losses = []
|
55 |
+
|
56 |
+
total = 0
|
57 |
+
|
58 |
+
correct = 0
|
59 |
+
|
60 |
+
with torch.no_grad():
|
61 |
+
|
62 |
+
for i in range(1000):
|
63 |
+
|
64 |
+
inputs = []
|
65 |
+
|
66 |
+
outputs = []
|
67 |
+
|
68 |
+
for j in range(4):
|
69 |
+
|
70 |
+
data = next(generator)
|
71 |
+
|
72 |
+
x = data['audio']['array']
|
73 |
+
|
74 |
+
y = data['label']
|
75 |
+
|
76 |
+
inputs.append(x)
|
77 |
+
|
78 |
+
outputs.append(y)
|
79 |
+
|
80 |
+
input_values = processor(inputs, return_tensors="pt", padding="longest", sampling_rate=16000).input_values
|
81 |
+
|
82 |
+
logits = model(input_values.cuda()).logits
|
83 |
+
|
84 |
+
loss = torch.nn.functional.cross_entropy(logits, torch.tensor(outputs).cuda())
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
probs = torch.nn.functional.softmax(logits)
|
89 |
+
|
90 |
+
chosen = torch.argmax(probs,dim=1)
|
91 |
# Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
|
92 |
#--------------------------------------------------------------------------------------------
|
93 |
|