Epoch 48/49
----------
train Loss: 0.1041 Acc: 0.9642
val Loss: 1.0708 Acc: 0.7543
Epoch 49/49
----------
train Loss: 0.0983 Acc: 0.9671
val Loss: 0.9702 Acc: 0.7900
Training complete in 88m 8s
Best val Acc: 0.846000
保存文件成功
保存文件成功
保存文件成功
Traceback (most recent call last):
File "main.py", line 72, in <module>
outputs = model_ft(images)
File "/home/seu/anaconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/media/seu/Linux-doc/wwh/pytorchproj/MyResnet.py", line 196, in forward
x = self.conv1(x)
File "/home/seu/anaconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/home/seu/anaconda3/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 320, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
已经解决了,是因为模型权重的数据类型和训练数据的数据类型不统一造成的,权重是cuda型的,但数据在cpu当中不是,只需要每次将数据to(device)就可以了。