MiDaS
MiDaS copied to clipboard
why need np.transpose(image,(2,0,1)) before feed image to model
Hi I wonder why we need a np.transpose(image,(2,0,1)) before feed image to the model? https://github.com/intel-isl/MiDaS/blob/master/midas/transforms.py#L219
@bigtree2020 It's a pytorch thing, unrelated to MiDaS; see, for example, https://discuss.pytorch.org/t/swap-axes-in-pytorch/970.
@bigtree2020
OpenCV img = cv2.imread(path)
loads an image with HWC-layout (height, width, channels), while Pytorch requires CHW-layout. So we have to do np.transpose(image,(2,0,1))
for HWC->CHW transformation.
Thanks.
@bigtree2020
OpenCV
img = cv2.imread(path)
loads an image with HWC-layout (height, width, channels), while Pytorch requires CHW-layout. So we have to donp.transpose(image,(2,0,1))
for HWC->CHW transformation.
Thank you, it helped me a lot!