MobileNet_V3¶
ConvNet
- class lucid.models.MobileNet_V3(config: MobileNetV3Config)¶
Overview¶
The MobileNetV3 class implements the MobileNet-v3 architecture, building upon the innovations of MobileNet-v2 with further optimizations. It introduces squeeze-and-excitation modules, efficient head designs, and two variants—Small and Large—tailored for different resource constraints.
This architecture is designed for high performance in mobile and embedded applications with minimal computational overhead. Model structure is defined through MobileNetV3Config, while mobilenet_v3_small and mobilenet_v3_large provide the standard presets.
%%{init: {"flowchart":{"curve":"monotoneX","nodeSpacing":50,"rankSpacing":50}} }%%
flowchart LR
linkStyle default stroke-width:2.0px
subgraph sg_m0["<span style='font-size:20px;font-weight:700'>mobilenet_v3_small</span>"]
style sg_m0 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
subgraph sg_m1["conv_first"]
direction TB;
style sg_m1 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
m2["Conv2d<br/><span style='font-size:11px;color:#c53030;font-weight:400'>(1,3,224,224) → (1,16,112,112)</span>"];
m3["BatchNorm2d"];
m4["HardSwish"];
end
subgraph sg_m5["bottlenecks"]
direction TB;
style sg_m5 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
subgraph sg_m6["_InvertedBottleneck_V3 x 11"]
direction TB;
style sg_m6 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
m6_in(["Input"]);
m6_out(["Output"]);
style m6_in fill:#e2e8f0,stroke:#64748b,stroke-width:1px;
style m6_out fill:#e2e8f0,stroke:#64748b,stroke-width:1px;
m7["Sequential<br/><span style='font-size:11px;font-weight:400'>(1,16,112,112) → (1,16,56,56)</span>"];
end
end
subgraph sg_m8["conv_last"]
direction TB;
style sg_m8 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
m9["Conv2d<br/><span style='font-size:11px;color:#c53030;font-weight:400'>(1,96,7,7) → (1,576,7,7)</span>"];
m10["BatchNorm2d"];
m11["HardSwish"];
end
m12["AdaptiveAvgPool2d<br/><span style='font-size:11px;color:#b7791f;font-weight:400'>(1,576,7,7) → (1,576,1,1)</span>"];
subgraph sg_m13["fc1"]
direction TB;
style sg_m13 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
m14["Linear<br/><span style='font-size:11px;color:#2b6cb0;font-weight:400'>(1,576) → (1,1024)</span>"];
m15["HardSwish"];
end
subgraph sg_m16["fc2"]
direction TB;
style sg_m16 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
m17["Dropout"];
m18["Linear<br/><span style='font-size:11px;color:#2b6cb0;font-weight:400'>(1,1024) → (1,1000)</span>"];
end
end
input["Input<br/><span style='font-size:11px;color:#a67c00;font-weight:400'>(1,3,224,224)</span>"];
output["Output<br/><span style='font-size:11px;color:#a67c00;font-weight:400'>(1,1000)</span>"];
style input fill:#fff3cd,stroke:#a67c00,stroke-width:1px;
style output fill:#fff3cd,stroke:#a67c00,stroke-width:1px;
style m2 fill:#ffe8e8,stroke:#c53030,stroke-width:1px;
style m3 fill:#e6fffa,stroke:#2c7a7b,stroke-width:1px;
style m4 fill:#faf5ff,stroke:#6b46c1,stroke-width:1px;
style m9 fill:#ffe8e8,stroke:#c53030,stroke-width:1px;
style m10 fill:#e6fffa,stroke:#2c7a7b,stroke-width:1px;
style m11 fill:#faf5ff,stroke:#6b46c1,stroke-width:1px;
style m12 fill:#fefcbf,stroke:#b7791f,stroke-width:1px;
style m14 fill:#ebf8ff,stroke:#2b6cb0,stroke-width:1px;
style m15 fill:#faf5ff,stroke:#6b46c1,stroke-width:1px;
style m17 fill:#edf2f7,stroke:#4a5568,stroke-width:1px;
style m18 fill:#ebf8ff,stroke:#2b6cb0,stroke-width:1px;
input --> m2;
m10 --> m11;
m11 --> m12;
m12 --> m14;
m14 --> m15;
m15 --> m17;
m17 --> m18;
m18 --> output;
m2 --> m3;
m3 --> m4;
m4 -.-> m7;
m6_in -.-> m7;
m6_out -.-> m6_in;
m6_out --> m9;
m7 -.-> m6_in;
m7 --> m6_out;
m9 --> m10;
Class Signature¶
class MobileNet_V3(nn.Module):
def __init__(self, config: MobileNetV3Config) -> None
Parameters¶
config (MobileNetV3Config): Configuration object describing the MobileNet-v3 bottleneck sequence, classifier width, stem width, classifier size, and input channel count.
Examples¶
Creating a MobileNet-v3 model with a custom config:
>>> import lucid.models as models
>>> config = models.MobileNetV3Config(
... bottleneck_cfg=[
... (3, 16, 16, True, False, 2, 2),
... (3, 72, 24, False, False, 2, 4),
... ],
... last_channels=1024,
... num_classes=10,
... in_channels=1,
... )
>>> model = models.MobileNet_V3(config)
>>> print(model)
Forward pass with MobileNetV3:
>>> import lucid
>>> input_tensor = lucid.zeros(1, 1, 224, 224)
>>> output = model(input_tensor)
>>> print(output)
Note
MobileNet-v3 balances resource efficiency and accuracy with squeeze-and-excitation blocks and hard-swish activations.