提问人:Jae Hyo Yi 提问时间:11/13/2023 最后编辑:Jae Hyo Yi 更新时间:11/13/2023 访问量:42
输入类型(火炬。FloatTensor)和权重类型(torch.cuda.FloatTensor)应相同,或者输入应为张量,权重为密集张量
Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same or input should be a tensor and weight is a dense tensor
问:
我是 PyTorch 的菜鸟,我正在尝试训练我的模型(估计两个图像之间的仿射变换)。 该代码在 google colab 上运行。当我尝试在 cpu(没有设备 cuda)上运行它时,它可以工作,但是当我将数据和权重(模型)放入设备时,它会出现以下错误。我已经上传了屏幕截图。
“输入类型(火炬。FloatTensor)和权重类型(torch.cuda.FloatTensor)应相同,否则input应为张量,weight为密集张量”
有什么建议吗?这将非常有帮助 XD
我尝试将输入和权重都放入 GPU 中,但仍然不起作用:(
batch_size = 8
TrainLoader = DataLoader(TrainingData, batch_size)
model = CombinedModel().to(device)
optimizer = optim.Adam(model.parameters(), lr=0.005)
for i, (image1, image2, target) in enumerate(TrainLoader):
image1 = image1.to(device)
image2 = image2.to(device)
target = target.to(device)
outputs = model(image1, image2)
print(outputs)
print(outputs.shape)
答: 暂无答案
评论