ptrblck:

CrossEntropyLoss


Thanks. But I have one further question.
I have target with shape [n, w, h]  which n is the batch size;  output with shape [n, c, w, h]; and my mask is binary mask with ignore index 255.
I tried with your script and find it only works when the output channel dimension is 2, namely output shape [n,2,w,h] , one channel for 0, and one channel for 1.
It kinda makes sense coz the weight dimension should match the class dimension in the output, but just since it is a binary class problem, I wanna save some memory to output just 1 channel with 0 and 1 in the same channel. output [n,1,w,h]
Then to use the weights, do  I stil lhave to reshape it into 2 channel? or am I doing something wrong here.
Thanks