[英]Python Error RuntimeError: expected scalar type Long but found Double
[英]Pytorch Error, RuntimeError: expected scalar type Long but found Double
在分類任務中,輸入標簽的數據類型應該是 Long,但您將它們分配為 float64
type(b_labels[i]) = tensor(1., dtype=torch.float64)
=>
type(b_labels[i]) = tensor(1., dtype=torch.long)
您可以使用torch.Tensor.long
將張量轉換為預期long
類型。
# Here, you can pass parameter like this in your call
..., labels = b_labels.long())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.