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


 

解决方法:

def conv_2(batch, channel=256):   

mydevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu') ### aimin li, added
for x in batch:
    x.to(mydevice)
weights = torch.ones(channel, in_channel, 2, 2).to(mydevice)
b = torch.ones(channel).to(mydevice)
out = F.conv2d(input=x, weight=weights, bias=b, stride=1, padding=1)

 

posted @ 2025-10-04 16:42  emanlee  阅读(7)  评论(0)    收藏  举报