qq_39730690 2022-03-06 18:47 采纳率: 33.3%
浏览 76
已结题

继承CrossEntropyLoss后,调用super之后,pred和 target的size不一样为什么不报错?

class SegmentationLosses(nn.CrossEntropyLoss):
    """2D Cross Entropy Loss with Auxilary Loss"""
    def __init__(self, se_loss=False, se_weight=0.2, nclass=-1, aux_num=2,
                 aux=False, aux_weight=0.1, weight=None,
                 ignore_index=-1):
        super(SegmentationLosses, self).__init__(weight, None, ignore_index)
        self.se_loss = se_loss
        self.aux = aux
        self.nclass = nclass
        self.se_weight = se_weight

    def forward(self, *inputs):  
            pred1, target = tuple(inputs)
            print(pred1.size())
            print(target.size())
            a =  super(SegmentationLosses, self).forward(pred1, target)
            print(a)
            return a

下面是我debeg截图,显示pred1, target这两个参数的size是不一样的,为什么没有报错呢?

img

  • 写回答

1条回答 默认 最新

  • 丨封尘绝念斩丨 2022-03-09 18:59
    关注
    获得5.00元问题酬金

    最后一层维度是1的,是可以看成向量的。能正确预测

    评论

报告相同问题?

问题事件

  • 系统已结题 3月14日
  • 创建了问题 3月6日