Update handler.py
Browse files- handler.py +13 -0
handler.py
CHANGED
@@ -12,13 +12,26 @@ class EndpointHandler:
|
|
12 |
self.model.eval()
|
13 |
|
14 |
def __call__(self, data):
|
|
|
|
|
|
|
15 |
frames = np.array(data['frames'])
|
16 |
frames = torch.tensor(frames).float() # Ensure the data is in the correct format
|
|
|
|
|
|
|
17 |
|
18 |
# Perform inference
|
19 |
with torch.no_grad():
|
20 |
outputs = self.model(frames.unsqueeze(0)) # Add batch dimension
|
21 |
predictions = torch.softmax(outputs.logits, dim=-1)
|
|
|
|
|
|
|
|
|
22 |
predicted_class = torch.argmax(predictions, dim=-1).item()
|
|
|
|
|
|
|
23 |
|
24 |
return {"predicted_class": predicted_class, "predictions": predictions.tolist()}
|
|
|
12 |
self.model.eval()
|
13 |
|
14 |
def __call__(self, data):
|
15 |
+
# ๋๋ฒ๊น
: ์
๋ ฅ ๋ฐ์ดํฐ ํ์ธ
|
16 |
+
print("Received data:", data)
|
17 |
+
|
18 |
frames = np.array(data['frames'])
|
19 |
frames = torch.tensor(frames).float() # Ensure the data is in the correct format
|
20 |
+
|
21 |
+
# ๋๋ฒ๊น
: ํ๋ ์ ๋ฐ์ดํฐ ํ์ธ
|
22 |
+
print("Frames shape:", frames.shape)
|
23 |
|
24 |
# Perform inference
|
25 |
with torch.no_grad():
|
26 |
outputs = self.model(frames.unsqueeze(0)) # Add batch dimension
|
27 |
predictions = torch.softmax(outputs.logits, dim=-1)
|
28 |
+
|
29 |
+
# ๋๋ฒ๊น
: ์์ธก ๊ฒฐ๊ณผ ํ์ธ
|
30 |
+
print("Predictions:", predictions)
|
31 |
+
|
32 |
predicted_class = torch.argmax(predictions, dim=-1).item()
|
33 |
+
|
34 |
+
# ๋๋ฒ๊น
: ์์ธก ํด๋์ค ํ์ธ
|
35 |
+
print("Predicted class:", predicted_class)
|
36 |
|
37 |
return {"predicted_class": predicted_class, "predictions": predictions.tolist()}
|