mayool:

How is your loss function calculated. Shouldn’t y and output have the same dimensions? Or is that something special NLLLoss does?


nn.CrossEntropyLoss (and thus also nn.NLLLoss) expect the model output to have the shape [batch_size, nb_classes, height, width] and the target [batch_size, height, width] containing the class indices for a segmentation use case.



 mayool:

Is it just try and error or is there some trick? 


For even inputs shapes and “simple” convolutions, you can easily create the transposed conv so that you’ll get the same output shape.
However, if you are using odd input shapes, dilations, etc. you might need to use output_padding in your transposed convs.
Usually, I add print statements after each layer and make sure I get the shape I need.