switchCHWAndHWC
Switch tensor content between a CHW and HWC format. A tensor of CHW format means it is a multi-dimensional tensor of datatype = Tensor.DataType, and 3 dimensions: CxHxW. A tensor of HWC format means it is a multi-dimensional tensor of 2 dimensions: HxW, with datatype = Tensor.DataType.Image.
For example, when you get an RGB image content in a multi-dimensional tensor, e.g. a tensor created using:
auto tensor1 = pipeline.newLocalTensor(MultiDimensionalInitInfo(
DataType.Image.R8G8B8_U,
intArrayOf(1024, 960))But your algorithm, for instance, trained using PyTorch, requires input as a 3 matrices stack together, i.e., a tensor created using
auto tensor2 = pipeline.newLocalTensor(MultiDimensionalInitInfo(
DataType.UINT8, intArrayOf(3, 1024, 960))Under such circumstance, this method allow you to efficiently extract the R, G, and B channel from the tensor1 and assign per-channel image to subtensor tensor2[0], tensor2[1] and tensor2[2]:
pipeline.switchCHWAndHWC(tensor1, tensor2)Parameters
the tensor whose format to be switched. It must either be of CHW format, or HWC format.
Throws
If the usage is not allowed by the SpatialML run-time Framework, or if the framework encounters internal error and cannot perform the requested behavior.