A two-block inverted-residual net — end-to-end VJP (flattened Vec space) #
Defines mobilenetv2Forward — stem conv → bn → relu6, one inverted-residual block with a skip,
one without (channel change), global average pool, dense head — and proves its vector–Jacobian
product correct at a smooth point (mobilenetv2HasVJPAt, mobilenetv2HasVJPAt_correct), as
cnnHasVJPAt does for the two-residual-block CNN. Every "bn" in this file is bnForward: one
normalisation over the whole flattened tensor with scalar γ β : ℝ, not per-channel BatchNorm.
Every conv is stride 1. The seventeen-block, batch-BatchNorm net the MobileNetV2 artifacts
train is mobilenetv2ForwardBFull (MobileNetV2FullB).
Everything lives in flattened Vec space and reuses the foundation rules from CNN.lean,
Depthwise.lean, BatchNorm.lean, MLP.lean, and Residual.lean through vjpCompAt
chaining.
What's new here #
relu6(defined inMLP.lean, besiderelu) — the clamped activationmin (max x 0) 6. Unlikerelu, the saturated branch is the constant 6 (not linear-through-origin), so the local-linearization trick matchesrelu6against an affine surrogateg(proj on the active region, constant 0 below, constant 6 above) whose fderiv is the diagonal indicator1_{0<x<6}. Smoothness is the two-sidedx k ≠ 0 ∧ x k ≠ 6.Inverted-residual body —
project ∘ depthwise ∘ expand:- expand : 1×1 conv → bn → relu6 (
ic → mid, mid = t·ic) - depthwise: depthwise conv → bn → relu6 (
mid → mid) - project : 1×1 conv → bn (linear bottleneck, no activation;
mid → oc) With a stride-1 /ic = ocskip it becomesresidual body(no final activation — MobileNetV2's linear-bottleneck design).
- expand : 1×1 conv → bn → relu6 (
End-to-end — stem (conv-bn-relu6) → skip inverted-residual → no-skip inverted-residual (channel change) → global average pool → dense head. Two blocks; channel counts and kernel sizes are binders; spatial
h wpreserved throughout (SAME convs).
Padding convention #
The strided pieces of the batched chain (MobileNetV2BackB0.lean on) read flatConvStride2Xla /
depthwiseStride2FlatXla, the XLA-SAME (odd) phase every MobileNetV2 artifact emits. The 2-block generic mobilenetv2Forward
here has a stride-1 stem.
All new defs/theorems certify to exactly [propext, Classical.choice, Quot.sound].
References #
- Sandler et al. 2018, MobileNetV2: Inverted Residuals and Linear Bottlenecks. https://arxiv.org/abs/1801.04381
The expand stage as a flat map.
Equations
- Proofs.ivExpand We be εe γe βe = Proofs.relu6 (mid * h * w) ∘ Proofs.bnForward (mid * h * w) εe γe βe ∘ Proofs.flatConv We be
Instances For
The depthwise stage as a flat map.
Equations
- Proofs.ivDepthwise Wd bd εd γd βd = Proofs.relu6 (mid * h * w) ∘ Proofs.bnForward (mid * h * w) εd γd βd ∘ Proofs.depthwiseFlat Wd bd
Instances For
The project (linear bottleneck) stage as a flat map.
Equations
- Proofs.ivProject Wp bp εp γp βp = Proofs.bnForward (oc * h * w) εp γp βp ∘ Proofs.flatConv Wp bp
Instances For
Inverted-residual body = project ∘ depthwise ∘ expand. Flat
Vec (ic*h*w) → Vec (oc*h*w).
Equations
- Proofs.invresBody We be εe γe βe Wd bd εd γd βd Wp bp εp γp βp = Proofs.ivProject Wp bp εp γp βp ∘ Proofs.ivDepthwise Wd bd εd γd βd ∘ Proofs.ivExpand We be εe γe βe
Instances For
The forward MobileNetV2.
Equations
- One or more equations did not get rendered due to their size.
Instances For
MobileNetV2 end-to-end VJP at a smooth point. Chains the stem,
a skip inverted-residual, a no-skip inverted-residual, global avg
pool, and dense head with vjpCompAt under one bundled smoothness
family (one ≠0∧≠6 hypothesis per relu6 site, evaluated at the
running activation).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Public correctness theorem for mobilenetv2HasVJPAt — exposes
the witness's .correct field: at a point where all five relu6 sites (stem, and the
expand and depthwise stages of both blocks: h_stem, h_b1e, h_b1d, h_b2e, h_b2d)
are away from 0 and 6, the backward of the two-block mobilenetv2Forward equals the
pdiv-contracted Jacobian (Jacobian-transpose applied to the cotangent). Analogue of
cnnHasVJPAt_correct.