MCPcopy Create free account
hub / github.com/pytorch/tutorials / test

Function test

beginner_source/knowledge_distillation_tutorial.py:200–219  ·  view source on GitHub ↗
(model, test_loader, device)

Source from the content-addressed store, hash-verified

198 print(f"Epoch {epoch+1}/{epochs}, Loss: {running_loss / len(train_loader)}")
199
200def test(model, test_loader, device):
201 model.to(device)
202 model.eval()
203
204 correct = 0
205 total = 0
206
207 with torch.no_grad():
208 for inputs, labels in test_loader:
209 inputs, labels = inputs.to(device), labels.to(device)
210
211 outputs = model(inputs)
212 _, predicted = torch.max(outputs.data, 1)
213
214 total += labels.size(0)
215 correct += (predicted == labels).sum().item()
216
217 accuracy = 100 * correct / total
218 print(f"Test Accuracy: {accuracy:.2f}%")
219 return accuracy
220
221######################################################################
222# Cross-entropy runs

Calls 1

modelFunction · 0.70

Tested by

no test coverage detected