Hi,
This 2 and this 2 didn’t really help.
I want to use two losses. First loss uses smooth labels and the second one uses the one_hot vector. For the smooth label, i converted the one_hot vector targets = torch.tensor([[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0] ...) into a smooth vector. Since pytorch doesn’t provide a ready function for smooth target, I did this and want to confirm I’m doing things right?
outputs = torch.randn(6, 10)
targets_onehot = torch.zeros(outputs.size())
smooth_label = 1. / self.eps # 0.2
smooth_target = targets_onehot.scatter(1, targets.unsqueeze(1), smooth_label)
logfeat = F.log_softmax(outputs, dim=1)
smooth_loss = logfeat * smooth_target 
smooth_loss = torch.sum(smooth_loss, 1) / smooth_loss.size(1)

real_target = targets_onehot.scatter(1, targets.unsqueeze(1), float(1))
real_loss = logfeat * real_target 
real_loss = torch.sum(real_loss, 1) / real_loss.size(1)

loss = - real_loss * ( 1 - self.flags)  - self.flags * smooth_loss

I short, i would like to use a loss based on torch.tensor([[0.2, 0, 0, 0, 0, 0, 0], [0, 0.2, 0, 0, 0, 0], [0, 0, 0.2, 0, 0, 0] ...)`` and another one based on targets `
Looking at torch.scatter, I’m a little bit confused how the operation is done. Am I doing things right?
Thank you.