小编Gre*_*reg的帖子

在Pytorch中,具有多个值的Tensor的布尔值不明确

我想在pytorch中创建模型,但无法计算损失。它总是返回Tensor的Bool值,并且有多个值是模棱两可的。 实际上,我运行示例代码,它可以工作。

loss = CrossEntropyLoss()
input = torch.randn(8, 5)
input
target = torch.empty(8,dtype=torch.long).random_(5)
target
output = loss(input, target)
Run Code Online (Sandbox Code Playgroud)

这是我的代码,

################################################################################
##
##
import torch
from torch.nn import Conv2d, MaxPool2d, Linear, CrossEntropyLoss, MultiLabelSoftMarginLoss
from torch.nn.functional import relu, conv2d, max_pool2d, linear, softmax
from torch.optim import adadelta
##
##
##  Train
Train = {}
Train["Image"]    = torch.rand(2000, 3, 76, 76)
Train["Variable"] = torch.rand(2000, 6)
Train["Label"] = torch.empty(2000, dtype=torch.long).random_(2)
##
##
##  Valid
Valid = {}
Valid["Image"]    = torch.rand(150, 3, 76, 76)
Valid["Variable"] …
Run Code Online (Sandbox Code Playgroud)

python torch

11
推荐指数
3
解决办法
2万
查看次数

标签 统计

python ×1

torch ×1