(model: nn.Module, loader: DataLoader, device: torch.device)
| 113 | |
| 114 | |
| 115 | def evaluate(model: nn.Module, loader: DataLoader, device: torch.device) -> float: |
| 116 | model.eval() |
| 117 | correct = 0 |
| 118 | total = 0 |
| 119 | with torch.no_grad(): |
| 120 | for data, target in loader: |
| 121 | data, target = data.to(device), target.to(device) |
| 122 | output = model(data) |
| 123 | pred = output.argmax(dim=1) |
| 124 | correct += (pred == target).sum().item() |
| 125 | total += target.size(0) |
| 126 | return correct / total |
| 127 | |
| 128 | |
| 129 | def parse_hidden_dims(raw: Sequence[int]) -> list[int]: |
no outgoing calls
no test coverage detected