pytorch scoring set of images and evaluating results
In Pytorch by using GPU (cuda) need to score a set of images given trained NN.
The following code is meant to score a set of transformed images one by one.

model.to('cuda')
model.eval()

for ii, (inputs, classes) in enumerate(dataloaders['test']):
     inputs, classes = inputs, classes
     results = model.forward(inputs)
     ps = torch.exp(results)


Error Stack:

RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-24-948390e2b25a&gt; in &lt;module&gt;()
      5 for ii, (inputs, classes) in enumerate(dataloaders['test']):
      6      inputs, classes = inputs, classes
----&gt; 7      results = model(inputs)
      8      ps = torch.exp(results)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    489             result = self._slow_forward(*input, **kwargs)
    490         else:
--&gt; 491             result = self.forward(*input, **kwargs)
    492         for hook in self._forward_hooks.values():
    493             hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/models/vgg.py in forward(self, x)
     40 
     41     def forward(self, x):
---&gt; 42         x = self.features(x)
     43         x = x.view(x.size(0), -1)
     44         x = self.classifier(x)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    489             result = self._slow_forward(*input, **kwargs)
    490         else:
--&gt; 491             result = self.forward(*input, **kwargs)
    492         for hook in self._forward_hooks.values():
    493             hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
     89     def forward(self, input):
     90         for module in self._modules.values():
---&gt; 91             input = module(input)
     92         return input
     93 

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    489             result = self._slow_forward(*input, **kwargs)
    490         else:
--&gt; 491             result = self.forward(*input, **kwargs)
    492         for hook in self._forward_hooks.values():
    493             hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/conv.py in forward(self, input)
    299     def forward(self, input):
    300         return F.conv2d(input, self.weight, self.bias, self.stride,
--&gt; 301                         self.padding, self.dilation, self.groups)
    302 
    303 


RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'

Model made on a GPU (cuda).

This solves the problem and provides an Accuracy rate.

model.to('cuda')
model.eval()
accuracy = 0

for ii, (inputs, classes) in enumerate(dataloaders['test']):
        inputs, classes = inputs.to('cuda'), classes.to('cuda')
        # Forward and backward passes
        with torch.no_grad():
            output = model.forward(inputs)
        ps = torch.exp(output)
        equality = (classes.data == ps.max(dim=1)[1])
        accuracy += equality.type(torch.FloatTensor).mean()

accuracy = accuracy/len(dataloaders['test'])
print(accuracy)

