mmcls.models.utils¶
This package includes some helper functions and common components used in various networks.
mmcls.models.utils
Common Components¶
Inverted Residual Block. |
|
Squeeze-and-Excitation Module. |
|
Shift Window Multihead Self-Attention Module. |
|
Multi-head Attention Module. |
|
The Conditional Position Encoding (CPE) module. |
Helper Functions¶
channel_shuffle¶
- mmcls.models.utils.channel_shuffle(x, groups)[source]¶
Channel Shuffle operation.
This function enables cross-group information flow for multiple groups convolution layers.
- Parameters
x (Tensor) – The input tensor.
groups (int) – The number of groups to divide the input tensor in the channel dimension.
- Returns
The output tensor after channel shuffle operation.
- Return type
Tensor
make_divisible¶
- mmcls.models.utils.make_divisible(value, divisor, min_value=None, min_ratio=0.9)[source]¶
Make divisible function.
This function rounds the channel number down to the nearest value that can be divisible by the divisor.
- Parameters
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.
- Returns
The modified output channel number
- Return type
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
nif the input is not an Iterable object, otherwise, return the input directly.- Parameters
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)¶