Just to make sure you’re aware, calling



 SherlockLiao:

img = img.view(w, b, h)


doesn’t actually transpose the width into the first position of the matrix. It will just reshape your data into the shape you want. (In this case, probably with rather unfortunate consequences, since it will bleed data between elements of your batch.)
The second approach with batch_first=True works fine because you’re viewing a (b,1,h,w) matrix as a (b,w,h) matrix. Since w and h are the same in this context, this will really just squeeze out the singleton axis.
If you really want to flip axes around, you should use torch.transpose instead: http://pytorch.org/docs/torch.html#torch.transpose 52