-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtester.py
More file actions
34 lines (26 loc) · 795 Bytes
/
tester.py
File metadata and controls
34 lines (26 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import torch
def test(model, test_loader, config):
device = config.device
# send model to device
model.eval()
model.to(device)
# Summarize results
labels = []
pred = []
correct = 0
total = 0
with torch.no_grad():
# Iterate through data
for inputs, labels in test_loader:
inputs = inputs.to(device)
labels = labels.to(device)
outputs = model(inputs)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
# Print results
print(
"Accuracy of the network on the {} test images: {}".format(total, (100 * correct / total))
)
# Return results
return correct / total, labels, pred