how could I change memory layout from hwc to chw ?
Hi,
I noticed that the default memory order is HWC
which means that the offset is computed as offset = h * im.rows * im.elemSize() + w * im.elemSize() + c
. However, I need to change the layout to CHW
mode, which means that the offset of (h, w, c)
should be offset = c * im.rows * im.cols + h * im.cols + w
.
Is there any built-in method to do this ? If not, is there any c++11/14 built-in method to do this? Or what is the fastest way to do this ?
You can reshape (H, W, C) to (HW, C) and then perform a transpose. Transpose would give (C, HW) which can then be reshaped to (C, H, W).