I encountered this piece of code in
def pil2tensor(image:Union[NPImage,NPArray],dtype:np.dtype)->TensorImage: "Convert PIL style `image` array to torch style image tensor." a = np.asarray(image) if a.ndim==2 : a = np.expand_dims(a,2) a = np.transpose(a, (1, 0, 2)) a = np.transpose(a, (2, 1, 0)) return torch.from_numpy( a.astype(dtype, copy=False) )
Could I please ask why the double transpose? Would replacing the two transpose with the following
a = np.transpose(a, (2, 0, 1))
not have the same effect?
(I am not trying to be picky - just would like to confirm my understanding, maybe there is something I am not seeing here which could lead to bugs in the code that I write).
Thx a lot!