import torch def evaluate_model(model, testloader): """ Evaluates the model on the test set. """ correct = 0 total = 0 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model.to(device) model.eval() with torch.no_grad(): for data in testloader: images, labels = data[0].to(device), data[1].to(device) outputs = model(images) _, predicted = torch.max(outputs.data, 1) total += labels.size(0) correct += (predicted == labels).sum().item() accuracy = correct / total return accuracy