MCPcopy Create free account
hub / github.com/Intelligent-Computing-Lab-Panda/NDA_SNN / test

Function test

main.py:77–92  ·  view source on GitHub ↗
(model, test_loader, device)

Source from the content-addressed store, hash-verified

75
76@torch.no_grad()
77def test(model, test_loader, device):
78 correct = 0
79 total = 0
80 model.eval()
81 for batch_idx, (inputs, targets) in enumerate(test_loader):
82 inputs = inputs.to(device)
83 outputs = model(inputs)
84 mean_out = outputs.mean(1)
85 _, predicted = mean_out.cpu().max(1)
86 total += float(targets.size(0))
87 correct += float(predicted.eq(targets).sum().item())
88
89 correct = torch.tensor([correct]).cuda()
90 total = torch.tensor([total]).cuda()
91 final_acc = 100 * correct / total
92 return final_acc.item()
93
94
95if __name__ == '__main__':

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected