Pytorch CrossEntropyLoss调错记录

1、dimension out of range (expected to be in range of [-1, 0], but got 1)

参考https://github.com/pytorch/pytorch/issues/5554

二分类问题,target.size         [batch_size,]

修改,output_class.size()   为[batch_size,2]

 

2、RuntimeError: multi-target not supported at  ...

target.size =[batch_size,1]出错

参考:https://blog.csdn.net/ccbrid/article/details/79844005

https://blog.csdn.net/york1996/article/details/81875508

修改,target=target.squeeze()

 

3、element 0 of tensors does not require grad and does not have a grad_fn

参考:https://blog.csdn.net/jacke121/article/details/82733197

element 0 of tensors does not require grad and does not have a grad_fn

这个是因为requires_grad=False,应该为true
x = Variable(torch.ones(2,2),requires_grad=False)

4、CrossEntropyLoss(output,target)

output type : torch.FloatTorch

target type : torch.LongTorch

output_class = Variable(output_class.type(torch.FloatTensor)
label = Variable(label.type(torch.LongTensor))

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值