lvpengyuan/corner

RuntimeError: dimension specified as 1 but tensor has no dimensions

litchi99 opened this issue · 1 comments

Traceback (most recent call last):
File "/home/work/Code/Corner/train.py", line 255, in
train()
File "/home/work/Code/Corner/train.py", line 236, in train
loss_l, loss_c, loss_s = criterion(out, targets, segs)
File "/home/panda/pytorch_corner/local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call
result = self.forward(*input, **kwargs)
File "/home/work/Code/Corner/layers/modules/multibox_loss.py", line 79, in forward
loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False)
File "/home/panda/pytorch_corner/local/lib/python2.7/site-packages/torch/nn/functional.py", line 1161, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, size_average, ignore_index, reduce)
File "/home/panda/pytorch_corner/local/lib/python2.7/site-packages/torch/nn/functional.py", line 786, in log_softmax
return torch._C._nn.log_softmax(input, dim)
RuntimeError: dimension specified as 1 but tensor has no dimensions

It seems that ./layers/multibox_loss.py 75 line 'conf_p = conf_data_v[(pos_idx + neg_idx).gt(0)].view(-1, self.num_classes)' have bug?

这个错误是因为使用了icdar.py来加载数据集,它有可能会出现ground truth加载不全,导致在计算交叉熵时缺失gt数据,即conf_p = conf_data_v[(pos_idx + neg_idx).gt(0)].view(-1, self.num_classes)的输出为空。解决方法是使用mlt.py函数来加载训练或测试数据集。