fastai / fastai

The fastai deep learning library
http://docs.fast.ai
Apache License 2.0
26.18k stars 7.55k forks source link

mixup reduction problem #2286

Closed L1aoXingyu closed 5 years ago

L1aoXingyu commented 5 years ago

Describe the bug

I want to know if there is something wrong in mixup.py

  def forward(self, output, target):
        if len(target.size()) == 2:
            loss1, loss2 = self.crit(output,target[:,0].long()), self.crit(output,target[:,1].long())
            d = (loss1 * target[:,2] + loss2 * (1-target[:,2])).mean()
        else:  d = self.crit(output, target)
        if self.reduction == 'mean': return d.mean()
        elif self.reduction == 'sum':            return d.sum()
        return d

d should be loss1 lambd + loss2 (1-lambd) before reduction rather than (loss1 lambd + loss2 (1-lambd)).mean(). Is there something I misunderstanding?

Provide your installation details

To Reproduce

Expected behavior

Screenshots

Additional context

sgugger commented 5 years ago

Yes it should! That's a good catch, could you suggest a PR with a fix since you found it?

L1aoXingyu commented 5 years ago

Ok, I will suggest a PR tomorrow.

sgugger commented 5 years ago

Fixed by your PR.