pytorch错误收集

import torch.nn.functional as F

loss_func = F.cross_entropy

def model(xb):
    return xb @ weights + bias

报错:
unsupported operand type(s) for @: ‘numpy.ndarray’ and ‘Tensor’
解决:
左边的x转换成tensor,才能和右边的权重相乘
xb, = map (torch.tensor, (xb, ))

bs = 64  # batch size

xb = x_train[0:bs]  # a mini-batch from x
preds = model(xb)  # predictions
preds[0], preds.shape
print(preds[0], preds.shape)
yb = y_train[0:bs]
print(preds, yb)

报错:
‘int’ object is not callable
解决:
错误定位:
loss = loss(5,2)+1
TypeError: ‘int’ object is not callable
原因:
函数名loss
变量名loss
重合!!!
以此类推到其他类型的错误

你可能感兴趣的:(pytorch)