Skip to content

get_acc

Compute top-1 classification accuracy of model on dataset.

Puts the model in eval mode for the pass and restores train mode before returning so the caller's training loop is unaffected.

Parameters:

Name Type Description Default
model Module

Classifier returning logits of shape [batch, num_classes].

required
dataset Dataset

Iterable yielding (data, target) pairs.

required
batch_size int

DataLoader batch size.

128
device str

Device to run evaluation on.

'cuda'

Returns:

Type Description
Tensor

Scalar torch.Tensor with the accuracy in [0, 1].