Shortcuts

Note

You are reading the documentation for MMClassification 0.x, which will soon be deprecated at the end of 2022. We recommend you upgrade to MMClassification 1.0 to enjoy fruitful new features and better performance brought by OpenMMLab 2.0. Check the installation tutorial, migration tutorial and changelog for more details.

mmcls.models.utils

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

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)[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

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.

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)

is_tracing

mmcls.models.utils.is_tracing() bool[source]

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

Read the Docs v: latest
Versions
master
latest
1.x
dev-1.x
Downloads
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.