(model, criterion, input, target, mask)
| 187 | |
| 188 | |
| 189 | def test(model, criterion, input, target, mask): |
| 190 | model.eval() |
| 191 | with torch.no_grad(): |
| 192 | output = model(*input) |
| 193 | output, target = output[mask], target[mask] |
| 194 | |
| 195 | loss = criterion(output, target) |
| 196 | acc = (output.argmax(dim=1) == target).float().sum() / len(target) |
| 197 | return loss.item(), acc.item() |
| 198 | |
| 199 | |
| 200 | if __name__ == '__main__': |
no outgoing calls
no test coverage detected