I am trying to pass soft targets to mobilenet v2 (with the only change that I am using 2 classes instead of 1000).
According to CrossEntropyLoss — PyTorch 2.1 documentation and various similar posts, since ~2022 float targets are accepted by CrossEntropyLoss. However, for me it still fails.
Thanks a lot, it works. I thought at first that you mean that the batch size must be 1 (it’s 4 in the example), but if my targets are [4,2] the softmax is computed fine, so I am doing smth like this for now:
targets_float = torch.FloatTensor([[t, 1-t] for t in targets_float])
since F.one_hot would crash on vector that has floats.