Hi Michael!
First, to clear up some terminology:
An integer class label is a single integer that specifies the class.
These values run from 0 to nClass - 1, inclusive.  Pytorch’s
CrossEntropyLoss takes integer class labels.
One-hot encoding encodes exactly the same information as an
integer class label.  (You can convert back and forth between the
two without loss of information.)  A one-hot-encoded value is a
vector of nClass 0's and 1's, where there is exactly one 1 and
nClass - 1 0's.  The index of the location of the 1 is equal to the
integer class label.
CrossEntropyLoss does not take one-hot-encoded targets, but
instead takes integer class labels, which, to reiterate, contain exactly
the same information.
BCEWithLogitsLoss (and BCELoss) also do not take one-hot
encoded targets.  This is because they are used for somewhat
different classification problems, and one-hot targets (or, equivalently,
integer class labels) don’t contain the correct information for these
problems.



 Michael_Lempart:

If I use BCEwithLogits, i do not have to use a one hot encoded label,


Correct.
And, as outlined above, you would never want to use one-hot-encoded
targets with BCEWithLogitsLoss.


In that case a simple binary image with 1 channel would be enough?


Correct.


(using a Sigmoid activation function)


But you shouldn’t use sigmoid() with BCEWithLogitsLoss, as
BCEWithLogitsLoss  has, in effect, the sigmoid() built in.  Just
pass the raw-score logits that are the output of your final Linear
layer as the input to BCEWithLogitsLoss.  (You can use an explicit
sigmoid() to feed BCELoss, but, although mathematically equivalent
to feeding logits to BCEWithLogitsLoss, using BCELoss is
numerically less stable.)


Otherwise I could one hot encode my image and use a  Crossentropy loss instead?


No.  As outlined above, CrossEntropyLoss takes integer class labels
rather than one-hot-encoded labels.


(using a Softmax function)?


Again, no.  CrossEntropyLoss has, in effect, softmax() built in,
so you should feed the output of your final Linear layer directly to
CrossEntropyLoss as its input (without passing it through a
softmax()).
Best.
K. Frank