MobileNet_V2

ConvNet

class lucid.models.MobileNet_V2(config: MobileNetV2Config)

Overview

The MobileNetV2 class implements the MobileNet-v2 architecture, an advancement over MobileNet-v1. It introduces the concept of inverted residual blocks and linear bottlenecks, which significantly enhance efficiency and accuracy for mobile and embedded vision applications. This architecture is particularly optimized for lightweight and low-power tasks, making it suitable for real-time applications on mobile devices. Model structure is defined through MobileNetV2Config.

        %%{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_v2</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,32,112,112)</span>"];
    m3["BatchNorm2d"];
    m4["ReLU6"];
    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["Sequential x 7"]
        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["_InvertedBottleneck<br/><span style='font-size:11px;font-weight:400'>(1,32,112,112) → (1,16,112,112)</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,320,7,7) → (1,1280,7,7)</span>"];
    m10["BatchNorm2d"];
    m11["ReLU6"];
    end
    m12["AdaptiveAvgPool2d<br/><span style='font-size:11px;color:#b7791f;font-weight:400'>(1,1280,7,7) → (1,1280,1,1)</span>"];
    subgraph sg_m13["fc"]
    direction TB;
    style sg_m13 fill:#000000,fill-opacity:0.05,stroke:#000000,stroke-opacity:0.75,stroke-width:1px
    m14["Dropout"];
    m15["Linear<br/><span style='font-size:11px;color:#2b6cb0;font-weight:400'>(1,1280) → (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:#edf2f7,stroke:#4a5568,stroke-width:1px;
style m15 fill:#ebf8ff,stroke:#2b6cb0,stroke-width:1px;
input --> m2;
m10 --> m11;
m11 --> m12;
m12 --> m14;
m14 --> m15;
m15 --> 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_V2(nn.Module):
    def __init__(self, config: MobileNetV2Config) -> None

Parameters

  • config (MobileNetV2Config): Configuration object describing the MobileNet-v2 stage layout, stem width, final projection width, classifier size, and input channel count.