code: def evaluateModel(model, loader, device,
                    batches_in_epoch=sys.maxsize,
                    criterion=F.nll_loss, progress=None):
    
    model.eval()
    loss = 0
    correct = 0
    dataset_len = len(loader.sampler)
  
    if progress is not None:
      loader = tqdm(loader, **progress)
  
    with torch.no_grad():
      for batch_idx, (data, target) in enumerate(loader):
        data, target = data.to(device), target.to(device)
        output = model(data)
        loss += criterion(output, target, reduction='sum').item()
        pred = output.max(1, keepdim=True)[1]
        correct += pred.eq(target.view_as(pred)).sum().item()
  
        if batch_idx >= batches_in_epoch:
          break
  
    if progress is not None:
      loader.close()
  
    loss /= dataset_len
    accuracy = correct / dataset_len
  
    return {"total_correct": correct,
            "loss": loss,
            "accuracy": accuracy}
docs: Evaluate pre-trained model using given test dataset loader.
  
    :param model: Pretrained pytorch model
    :type model: torch.nn.Module
    :param loader: test dataset loader
    :type loader: :class:`torch.utils.data.DataLoader`
    :param device: device to use ('cpu' or 'cuda')
    :type device: :class:`torch.device
    :param batches_in_epoch: Max number of mini batches to test on.
    :param criterion: loss function to use
    :type criterion: function
    :param progress: Optional :class:`tqdm` progress bar args. None for no progress bar
    :type progress: dict or None
  
    :return: dictionary with computed "accuracy", "loss", "total_correct". The
             loss value is computed using :func:`torch.nn.functional.nll_loss`
    :rtype: dict