class LinearNet(nn.Module):
def __init__(self, num_inputs, num_outputs):
super(LinearNet, self).__init__()
self.linear = nn.Linear(num_inputs, num_outputs)
def forward(self, x):
y = self.linear(x.view(x.shape[0], -1))
return y
python3.6 pytorch1.7中,运行该段代码后,提示
RuntimeError: Tensor for 'out' is on cpu, Tensor for argument #1 'self' is on cpu, but expected them to be on GPU
请问如何解决?谢谢!
model = LinearNet().to('cuda')
模型必须放到gpu上