原文:Pytoch的nn.CrossEntropyLoss 报错 RuntimeError: expected scalar type Long but found Float

当我想测试时nn.CrossEntropyLoss 是报错,如下: 参考https: stackoverflow.com questions runtimeerror expected scalar type long but found float 原因是categorical target不能为浮点型,只能是整数,比如属于某一类 所以,把target改为整型 ...

2021-11-01 11:10 0 2819 推荐指数:

查看详情

expected scalar type Long but found Float

Pytorch tensor と numpy ndarray の変換 - Pythonいぬ (hatenablog.com) 主要还是 array 转 tensor的时候要确定类型 x = torch.from_numpy(x.astype(np.float32)) ...

Sat Oct 16 20:06:00 CST 2021 0 1318
tf.matmul()报错expected scalar type Float but found Double

tf.matmul(a,b)将矩阵a乘以矩阵b,生成a * b,这里的a,b要有相同的数据类型,否则会因为数据类型不匹配而出错。 如果出错,请看是前后分别是什么类型的,然后把数据类型进行转换。 ...

Sat Aug 03 19:31:00 CST 2019 0 891
nn.CrossEntropyLoss

nn.CrossEntropyLoss pytorch中交叉熵计算方式为: \[H(p,q) = -\sum p(i)logq(i) \] 其中,p为真实值矩阵,q为预测值矩阵 当P使用one-hot embedding时,只有在分类正确时 nn.CrossEntropyLoss ...

Sun Mar 06 00:28:00 CST 2022 0 916
pytorch中的nn.CrossEntropyLoss()

nn.CrossEntropyLoss()这个损失函数和我们普通说的交叉熵还是有些区别。 $x$是模型生成的结果,$class$是数据对应的label $loss(x,class)=-log(\frac{exp(x[class])}{\sum_j exp(x[j])})=-x[class ...

Thu Dec 12 00:13:00 CST 2019 0 3235
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM