Rearrange#

vision_architectures.utils.rearrange.make_channels_first(x)[source]#

Convert an n-dimensional tensor or array to channels first format.

Parameters:

x (Tensor | ndarray) – The input tensor / array. Should have at least 3 dimensions.

Returns:

The input tensor / array in channels first format.

vision_architectures.utils.rearrange.make_channels_last(x)[source]#

Convert an n-dimensional tensor or array to channels last format.

Parameters:

x (Tensor | ndarray) – The input tensor / array. Should have at least 3 dimensions.

Returns:

The input tensor / array in channels last format.

vision_architectures.utils.rearrange.rearrange_channels(x, cur_channels_first, new_channels_first)[source]#

Rearrange the channels of a tensor / array to either channels_first or channels_last format.

Parameters:
  • x (Tensor | ndarray) – The input tensor / array.

  • cur_channels_first (bool) – Whether the input tensor / array is in channels first format.

  • new_channels_first (bool) – Whether the output should be in channels first format.

Returns:

The input tensor / array with the channels rearranged.