(test_loader, MLP, loss_func)
| 92 | |
| 93 | |
| 94 | def SingleLayerTest(test_loader, MLP, loss_func): |
| 95 | auc = 0.0 |
| 96 | train_loss = 0.0 |
| 97 | l = 0 |
| 98 | for test_x, test_y in test_loader: |
| 99 | l += 1 |
| 100 | predicted = MLP(test_x) |
| 101 | y = torch.unsqueeze(test_y, 1) |
| 102 | loss = loss_func(predicted, y) |
| 103 | train_loss += loss.item() * test_x.size(0) |
| 104 | |
| 105 | predicted = torch.sigmoid(predicted) |
| 106 | predicted = torch.max(predicted, 1) |
| 107 | predicted = int(predicted.values >= 0.5) |
| 108 | auc += int(predicted == test_y) |
| 109 | return train_loss/l, auc/l |
| 110 | |
| 111 | |
| 112 |