Hi Jean Paul!



 jpainam:

i converted the one_hot vector targets = torch.tensor([1, 0, 1, 0, 1, 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 thing right?


I haven’t worked through your code, so I can’t comment on it.
Two side comments, though:
First, I wouldn’t call your example,
targets = torch.tensor([1, 0, 1, 0, 1, 0]),
“one hot.”  You have multiple non-zero entries.  (I might see this
as a “multi-label” target, where classes “0”, “2”, and “4” are active,
and classes “1”, “3”, and “5” are not active.)   But this doesn’t really
change the issue.
One way to smooth a one-hot vector (or a multi-label vector, or
any binary vector made up of zeros and ones) is to run it through
torch.nn.functional.softmax (alpha * target).
(alpha is a smoothing parameter: larger alpha makes the result
sharper, and smaller alpha makes it smoother.)
Good luck.
K. Frank