()
| 180 | |
| 181 | |
| 182 | def test(): |
| 183 | with torch.no_grad(): |
| 184 | model.eval() |
| 185 | test_loss = 0 |
| 186 | correct = 0 |
| 187 | for data, target in test_loader: |
| 188 | data, target = data.to(device), target.to(device) |
| 189 | output = model(data) |
| 190 | |
| 191 | # sum up batch loss |
| 192 | test_loss += F.nll_loss(output, target, size_average=False).item() |
| 193 | # get the index of the max log-probability |
| 194 | pred = output.max(1, keepdim=True)[1] |
| 195 | correct += pred.eq(target.view_as(pred)).sum().item() |
| 196 | |
| 197 | test_loss /= len(test_loader.dataset) |
| 198 | print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n' |
| 199 | .format(test_loss, correct, len(test_loader.dataset), |
| 200 | 100. * correct / len(test_loader.dataset))) |
| 201 | |
| 202 | ###################################################################### |
| 203 | # Visualizing the STN results |
no test coverage detected