Skip to main content
Version: 0.11.x

Function: toChannelsFirst()

toChannelsFirst(src, dst): Tensor

Defined in: extensions/cv/ops/image.ts:179

Transposes an image tensor layout from HWC (Height, Width, Channel) to CHW (Channel, Height, Width).

Commonly required for PyTorch Edge models which expect channels-first inputs.

Parameters​

src​

Tensor

The source image tensor in HWC layout. Expected shape [H, W, C] (channels-last). Supports any numeric data type.

dst​

Tensor

The pre-allocated destination image tensor in CHW layout. Expected shape [C, H, W] (channels-first) and the same data type as src.

Returns​

Tensor

The destination image tensor in CHW layout of shape [C, H, W] and matching data type.

Throws​

With code INVALID_ARGUMENT if tensor shapes, layouts, or data types are invalid, RESOURCE_BUSY if a tensor is in use, or RESOURCE_DISPOSED if either tensor was disposed.

We are Software Mansion.