MCPcopy Create free account
hub / github.com/aks2203/deep-thinking / test_default

Function test_default

deepthinking/utils/testing.py:55–79  ·  view source on GitHub ↗
(net, testloader, iters, problem, device)

Source from the content-addressed store, hash-verified

53
54
55def test_default(net, testloader, iters, problem, device):
56 max_iters = max(iters)
57 net.eval()
58 corrects = torch.zeros(max_iters)
59 total = 0
60
61 with torch.no_grad():
62 for inputs, targets in tqdm(testloader, leave=False):
63 inputs, targets = inputs.to(device), targets.to(device)
64
65 all_outputs = net(inputs, iters_to_do=max_iters)
66
67 for i in range(all_outputs.size(1)):
68 outputs = all_outputs[:, i]
69 predicted = get_predicted(inputs, outputs, problem)
70 targets = targets.view(targets.size(0), -1)
71 corrects[i] += torch.amin(predicted == targets, dim=[1]).sum().item()
72
73 total += targets.size(0)
74
75 accuracy = 100.0 * corrects / total
76 ret_acc = {}
77 for ite in iters:
78 ret_acc[ite] = accuracy[ite-1].item()
79 return ret_acc
80
81
82def test_max_conf(net, testloader, iters, problem, device):

Callers 1

testFunction · 0.85

Calls 1

get_predictedFunction · 0.85

Tested by

no test coverage detected