错误处理:RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be

使用torchsummary的时候,出现以下错误:

(涉及板块:

python 库整理:Timm(1)_UQI-LIUWJ的博客-CSDN博客

pytorch 笔记:torchsummary_UQI-LIUWJ的博客-CSDN博客

 代码部分

import timm
model = timm.create_model('resnet18', pretrained=True)
model.to_device('cpu')
model.eval()
from torchsummary import summary
summary(model,(3,244,244))

错误:

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

 这是由于模型和summary一个是cpu版本一个是gpu版本

解决方法:(看最后一行)

方法1:

import timm
model = timm.create_model('resnet18', pretrained=True)
model.eval()
from torchsummary import summary
summary(model.cuda(),(3,244,244))

方法2:

import timm
model = timm.create_model('resnet18', pretrained=True)
model.eval()
from torchsummary import summary
summary(model,(3,244,244),device='cpu')

你可能感兴趣的:(pytorch学习,其他,pytorch)