MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / eval

Function eval

model-experiments/gnn-based-experiments/src/main.py:62–85  ·  view source on GitHub ↗
(model, device, loader, evaluator)

Source from the content-addressed store, hash-verified

60
61
62def eval(model, device, loader, evaluator):
63 model.eval()
64
65 y_true = []
66 y_pred = []
67 for step, batch in enumerate(tqdm(loader, desc="Iteration")):
68 # one b(atch) per device
69 batch = [b for b in batch if not b.x.shape[0] == 1]
70 if batch:
71 with torch.no_grad():
72 pred = model(batch)
73
74 y_true += [b.y.view(-1, 1).detach().cpu() for b in batch]
75 y_pred.append(torch.argmax(pred.detach(), dim=1).view(-1, 1).cpu())
76
77 y_pred = torch.cat(y_pred, dim=0)
78 y_true = torch.cat(y_true, dim=0).view(y_pred.shape)
79 y_true = y_true.numpy()
80 y_pred = y_pred.numpy()
81 # print(y_true)
82 # print(y_pred)
83 input_dict = {"y_true": y_true, "y_pred": y_pred}
84
85 return evaluator.eval(input_dict)
86
87
88def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected