MobileOne¶
- class mmpretrain.models.backbones.MobileOne(arch, in_channels=3, out_indices=(3,), frozen_stages=-1, conv_cfg=None, norm_cfg={'type': 'BN'}, act_cfg={'type': 'ReLU'}, se_cfg={'ratio': 16}, deploy=False, norm_eval=False, init_cfg=[{'type': 'Kaiming', 'layer': ['Conv2d']}, {'type': 'Constant', 'val': 1, 'layer': ['_BatchNorm']}])[source]¶
MobileOne backbone.
A PyTorch impl of : An Improved One millisecond Mobile Backbone
- Parameters:
MobileOne architecture. If use string, choose from ‘s0’, ‘s1’, ‘s2’, ‘s3’ and ‘s4’. If use dict, it should have below keys:
num_blocks (Sequence[int]): Number of blocks in each stage.
width_factor (Sequence[float]): Width factor in each stage.
num_conv_branches (Sequence[int]): Number of conv branches in each stage.
num_se_blocks (Sequence[int]): Number of SE layers in each stage, all the SE layers are placed in the subsequent order in each stage.
Defaults to ‘s0’.
in_channels (int) – Number of input image channels. Default: 3.
out_indices (Sequence[int] | int) – Output from which stages. Defaults to
(3, )
.frozen_stages (int) – Stages to be frozen (all param fixed). -1 means not freezing any parameters. Defaults to -1.
conv_cfg (dict | None) – The config dict for conv layers. Defaults to None.
norm_cfg (dict) – The config dict for norm layers. Defaults to
dict(type='BN')
.act_cfg (dict) – Config dict for activation layer. Defaults to
dict(type='ReLU')
.deploy (bool) – Whether to switch the model structure to deployment mode. Defaults to False.
norm_eval (bool) – Whether to set norm layers to eval mode, namely, freeze running stats (mean and var). Note: Effect on Batch Norm and its variants only. Defaults to False.
init_cfg (dict or list[dict], optional) – Initialization config dict.
Example
>>> from mmpretrain.models import MobileOne >>> import torch >>> x = torch.rand(1, 3, 224, 224) >>> model = MobileOne("s0", out_indices=(0, 1, 2, 3)) >>> model.eval() >>> outputs = model(x) >>> for out in outputs: ... print(tuple(out.shape)) (1, 48, 56, 56) (1, 128, 28, 28) (1, 256, 14, 14) (1, 1024, 7, 7)