import torch


def test_model(model, dset_loader):
    """
    Tests a model on a given data set and returns the accuracy of the model
    on the set.
    """
    model.train(False)

    running_corrects = 0

    for inputs, labels in dset_loader:
        # wrap them in Variable
#         inputs, labels = Variable(inputs.cuda()), \
#                          Variable(labels.cuda())

        # forward
        outputs = model.forward_prediction(inputs)
        _, preds = torch.max(outputs.data, 1)

        running_corrects += torch.sum(preds == labels.data)

    return running_corrects/(len(dset_loader) * dset_loader.batch_size)