Multi-dimensional Labels in pytorch

I have an image and I want to pass it through convolution net and the output of the net is the same dimensional matrix as the input.
eg. Suppose I have an input of 3x32x32 the output is the same as 32x32.
Now I want to calculate the loss with a label of 32x32 but pytorch does not support multi-dimensional label to be fed in the loss function.
Is there a way to do this

First thing, you probably want your image ot be Bx3x32x32 - we only support batched inputs in CHW data ordering, but I think you meant to use a HWC order. You need to transpose the image.

Secondly, what kind of loss would you like to use exactly? If it’s segmentation then, nn.NLLLoss2d should do it.

I have some co-ordinates for bounding boxes in the train dataset and I want the net to train on those.

What kind of loss function do you want to use then?

My training labels would be 0 for non bounding box regions and 1 for bounding box regions. So I want to use L2 and L1 penalities. Which loss function should I use.

Sooo you’re predicting a 0 or 1 for each pixel? Why does your output have 3 channels then?

1 Like

L1 and L2 losses should be easy to write yourself using only autograd operations. It’s just a subtraction + abs or pow.

1 Like