# mmcls.models.utils¶

This package includes some helper functions and common components used in various networks.

mmcls.models.utils

## Common Components¶

 InvertedResidual Inverted Residual Block. SELayer Squeeze-and-Excitation Module. ShiftWindowMSA Shift Window Multihead Self-Attention Module. MultiheadAttention Multi-head Attention Module. ConditionalPositionEncoding The Conditional Position Encoding (CPE) module.

## Helper Functions¶

### channel_shuffle¶

mmcls.models.utils.channel_shuffle(x, groups)[源代码]

Channel Shuffle operation.

This function enables cross-group information flow for multiple groups convolution layers.

• x (Tensor) – The input tensor.

• groups (int) – The number of groups to divide the input tensor in the channel dimension.

The output tensor after channel shuffle operation.

Tensor

### make_divisible¶

mmcls.models.utils.make_divisible(value, divisor, min_value=None, min_ratio=0.9)[源代码]

Make divisible function.

This function rounds the channel number down to the nearest value that can be divisible by the divisor.

• value (int) – The original channel number.

• divisor (int) – The divisor to fully divide the channel number.

• min_value (int, optional) – The minimum value of the output channel. Default: None, means that the minimum value equal to the divisor.

• min_ratio (float) – The minimum ratio of the rounded channel number to the original channel number. Default: 0.9.

The modified output channel number

int

### to_ntuple¶

mmcls.models.utils.to_ntuple(n)

A to_tuple function generator.

It returns a function, this function will repeat the input to a tuple of length n if the input is not an Iterable object, otherwise, return the input directly.

n (int) – The number of the target length.

mmcls.models.utils.to_2tuple(x)
mmcls.models.utils.to_3tuple(x)
mmcls.models.utils.to_4tuple(x)

### is_tracing¶

mmcls.models.utils.is_tracing() bool[源代码]

Determine whether the model is called during the tracing of code with torch.jit.trace.