How to train multiple targets at once?

The PyTorch example at for face landmarks seems to suggest that training with that many target (in sets of two) is possible.

I have attempted to incorporate their working in order to set up my own dataset, but when I try to train, I just get:

RuntimeError: multi-target not supported

I am at a loss how one would train the dataset they’ve shown there. I would greatly appreciate any insight into how one may train this dataset, as it is directly applicable for my project.

Which criterion have you used?
It seems you used a criterion, which is not suitable for multi-target prediction, e.g. NLLLoss.
Could you try it again with e.g. MSELoss?

2 Likes

This fixed my problem! Thank you very much!

MSELoss allowed me to train with multiple targets.

Is there a list that outlines which loss functions allow for multi target training?

It’s good to hear that it fixed your problem.
You can have a look at the different loss functions. The documentation mentions, what kind of target is expected.
However, it’s sometimes a bit tricky, since for example the BCELoss can be used for multi-label classification (i.e. more than one class is valid for the sample).

For a lot of use cases, you will just need BCELoss, NLLLoss and MSELoss. :wink:

1 Like