MCPcopy Index your code
hub / github.com/pytorch/tutorials / test

Function test

beginner_source/basics/quickstart_tutorial.py:160–173  ·  view source on GitHub ↗
(dataloader, model, loss_fn)

Source from the content-addressed store, hash-verified

158# We also check the model's performance against the test dataset to ensure it is learning.
159
160def test(dataloader, model, loss_fn):
161 size = len(dataloader.dataset)
162 num_batches = len(dataloader)
163 model.eval()
164 test_loss, correct = 0, 0
165 with torch.no_grad():
166 for X, y in dataloader:
167 X, y = X.to(device), y.to(device)
168 pred = model(X)
169 test_loss += loss_fn(pred, y).item()
170 correct += (pred.argmax(1) == y).type(torch.float).sum().item()
171 test_loss /= num_batches
172 correct /= size
173 print(f"Test Error: \n Accuracy: {(100*correct):>0.1f}%, Avg loss: {test_loss:>8f} \n")
174
175##############################################################################
176# The training process is conducted over several iterations (*epochs*). During each epoch, the model learns

Callers 1

Calls 2

loss_fnFunction · 0.85
modelFunction · 0.50

Tested by

no test coverage detected