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

Function test_accuracy

beginner_source/hyperparameter_tuning_tutorial.py:372–390  ·  view source on GitHub ↗
(net, device="cpu", data_dir=None)

Source from the content-addressed store, hash-verified

370# test set to estimate the generalization error:
371
372def test_accuracy(net, device="cpu", data_dir=None):
373 _trainset, testset = load_data(data_dir)
374
375 testloader = torch.utils.data.DataLoader(
376 testset, batch_size=4, shuffle=False, num_workers=2
377 )
378
379 correct = 0
380 total = 0
381 with torch.no_grad():
382 for data in testloader:
383 image_batch, labels = data
384 image_batch, labels = image_batch.to(device), labels.to(device)
385 outputs = net(image_batch)
386 _, predicted = torch.max(outputs.data, 1)
387 total += labels.size(0)
388 correct += (predicted == labels).sum().item()
389
390 return correct / total
391
392######################################################################
393# Configure and run Ray Tune

Callers 1

mainFunction · 0.85

Calls 1

load_dataFunction · 0.85

Tested by

no test coverage detected