В Pytorch с помощью графического процессора (cuda) необходимо набрать набор изображений с учетом обученного NN.
Следующий код предназначен для оценки набора преобразованных изображений одно за другим.
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)
стек ошибок:
RuntimeError Traceback (most recent call last)
<ipython-input-24-948390e2b25a> in <module>()
5 for ii, (inputs, classes) in enumerate(dataloaders['test']):
6 inputs, classes = inputs, classes
----> 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:
--> 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):
---> 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:
--> 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():
---> 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:
--> 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,
--> 301 self.padding, self.dilation, self.groups)
302
303
RuntimeError: Ожидаемый объект типа torch.FloatTensor, но найден тип torch.cuda.FloatTensor для аргумента # 2 'weight'
Модель сделана на GPU (cuda).