import torch


def get_accuracy(net, dataloader, config):
    """Get accuracy of net relative to dataloader."""
    net.eval()
    correct = 0
    total = 0
    with torch.no_grad():
        for i, (inputs, targets) in enumerate(dataloader):
            inputs = inputs.to(device=config['setup']['device'], dtype=config['setup']['dtype'])
            targets = targets.to(device=config['setup']['device'], dtype=torch.long)
            outputs = net(inputs)
            _, predicted = torch.max(outputs.data, 1)
            total += targets.size(0)
            correct += (predicted == targets).sum().item()
    return correct / total