(已经解决)在做深度学习分类时或者其他应用出现RuntimeError:Input type and weight type should be the same。
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same.已经解决显示这里有错误:model = nn.Sequential(*list(trained_model.children())[:-1], #[b, 512, 1, 1]取前1...
·
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same.已经解决
显示这里有错误:
model = nn.Sequential(*list(trained_model.children())[:-1], #[b, 512, 1, 1] 取前17层
Flatten(), # [b, 512, 1, 1] => [b, 512]
nn.Linear(9216, 3)
)
仔细看了一下,原来没有把模型to到cuda上,那么在末尾加上.to(torch.device('cuda'))就可以,即:
model = nn.Sequential(*list(trained_model.children())[:-1], #[b, 512, 1, 1] 取前17层
Flatten(), # [b, 512, 1, 1] => [b, 512]
nn.Linear(9216, 3)
).to(device)
问题解决。
更多推荐




所有评论(0)