MCPcopy Index your code
hub / github.com/microsoft/AI-System / test

Function test

Labs/BasicLabs/Lab4/mnist_basic.py:82–98  ·  view source on GitHub ↗
(model, device, test_loader)

Source from the content-addressed store, hash-verified

80
81
82def test(model, device, test_loader):
83 model.eval()
84 test_loss = 0
85 correct = 0
86 with torch.no_grad():
87 for data, target in test_loader:
88 data, target = data.to(device), target.to(device)
89 output = model(data)
90 test_loss += F.nll_loss(output, target, reduction='sum').item() # sum up batch loss
91 pred = output.argmax(dim=1, keepdim=True) # get the index of the max log-probability
92 correct += pred.eq(target.view_as(pred)).sum().item()
93
94 test_loss /= len(test_loader.dataset)
95
96 print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
97 test_loss, correct, len(test_loader.dataset),
98 100. * correct / len(test_loader.dataset)))
99
100
101def main():

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected