Create Test_model.py
Browse files- Test_model.py +22 -0
Test_model.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# test_model.py
|
2 |
+
import torch
|
3 |
+
from models.moe_model import MoEModel
|
4 |
+
from utils.data_loader import load_data
|
5 |
+
from utils.helper_functions import save_model, load_model
|
6 |
+
|
7 |
+
def test_model():
|
8 |
+
model = MoEModel(input_dim=512, num_experts=3)
|
9 |
+
test_loader = load_data()
|
10 |
+
|
11 |
+
correct, total = 0, 0
|
12 |
+
with torch.no_grad():
|
13 |
+
for data in test_loader:
|
14 |
+
vision_input, audio_input, sensor_input, labels = data
|
15 |
+
outputs = model(vision_input, audio_input, sensor_input)
|
16 |
+
_, predicted = torch.max(outputs.data, 1)
|
17 |
+
total += labels.size(0)
|
18 |
+
correct += (predicted == labels).sum().item()
|
19 |
+
print(f"Accuracy: {100 * correct / total}%")
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
test_model()
|