影片狀態:僅附相關補充影片;原講次錄影未確認。 影片來源與說明
教材版本:基於 MIT 6.7960 Fall 2024 OCW。影片、投影片、作業全公開於 MIT OCW。
TL;R
ResNet 殘差連接解決退化問題;EfficientNet 複合縮放;ConvNeXt 吸收 Transformer 設計重奪 CV 王座。
背景 / 課程定位
這篇主題單元接在第 4 堂(CNN 架構)之後;早期曾標為 L06,但與 OCW Lec 06 無關,OCW Lec 06 是 Generalization Theory。第 4 堂建立基礎 CNN;本篇進入現代架構,探討「如何把網路堆深、堆高效、堆準」—— 這直接影響你訓練自己的模型時選什麼骨幹。
影片:OCW 沒有「Modern CNN」這一講。嵌入的 Lec 04 Architectures: Grids 只在後段(約 60–70 分)談 ResNet 殘差連接,沒有 MobileNet、EfficientNet 或 ConvNeXt。 投影片:OCW 沒有名為「Lecture 6: Modern CNN」的投影片,原連結已移除。
核心概念對比
| 架構 | 年份 | 核心創新 | 解決什麼問題 |
|---|---|---|---|
| VGG(第 4 堂) | 2014 | 3×3 堆疊 | 證明深度有益,但梯度消失 |
| ResNet | 2015 | 殘差連接 | 退化問題(深網反而更差) |
| MobileNet | 2017 | 深度可分離卷積 | 行動端輕量化 |
| EfficientNet | 2019 | 複合縮放 | 系統化平衡深度/寬度/解析度 |
| ConvNeXt | 2022 | 吸收 Transformer 設計 | 證明 CNN 仍可打贏 ViT |
系統 / 方法架構
1. ResNet 殘差連接
x → [Conv-BN-ReLU] → [Conv-BN] → + (skip x) → ReLU
↑
identity shortcut
- 學習殘差 $F(x) = H(x) - x$,優化目標從「絕對映射」變「增量」
- 退化問題:plain 網路加深後訓練誤差反而上升;ResNet 讓最壞情況退化成 identity(拷貝上一層)
2. 深度可分離卷積 (Depthwise Separable)
標準卷積: C_in × C_out × k × k 參數
可分離: (C_in × k × k) + (C_in × C_out × 1 × 1) 參數
計算量減少 ~ k² × C_out / (1 + k²)
- MobileNet: 3×3 depthwise + 1×1 pointwise
- 例:輸入 64 通道、輸出 128、核 3×3
- 標準:$64 \times 128 \times 9 = 73728$
- 可分離:$64 \times 9 + 64 \times 128 = 8768$(省 8.4×)
3. EfficientNet 複合縮放
$$\text{depth}: d=\alpha^\phi, \quad \text{width}: w=\beta^\phi, \quad \text{resolution}: r=\gamma^\phi$$ 約束 $\alpha \cdot \beta^2 \cdot \gamma^2 \approx 2$(固定總計算量)
- B0→B7:$\phi$ 從 0 到 7,系統化放大
- 關鍵:單獨縮放任一度都次優;複合縮放最優
4. ConvNeXt 設計選擇
| 設計元素 | 來源 | 效果 |
|---|---|---|
| 7×7 大核 (depthwise) | Swin Transformer | 增大感受野 |
| 反轉瓶頸 (inverted bottleneck) | MobileNetV2 | 類 Transformer FFN |
| 無偏置、LayerNorm | Transformer | 訓練更穩定 |
| GELU 激活 | Transformer | 略優於 ReLU |
實作啟發
PyTorch 實作:ResNet 殘差塊
import torch
import torch.nn as nn
import torch.nn.functional as F
class ResidualBlock(nn.Module):
def __init__(self, in_ch, out_ch, stride=1):
super().__init__()
self.conv1 = nn.Conv2d(in_ch, out_ch, 3, stride, 1, bias=False)
self.bn1 = nn.BatchNorm2d(out_ch)
self.conv2 = nn.Conv2d(out_ch, out_ch, 3, 1, 1, bias=False)
self.bn2 = nn.BatchNorm2d(out_ch)
# shortcut: 1×1 卷積對齊維度(當 in_ch ≠ out_ch 或 stride>1)
self.shortcut = nn.Sequential()
if in_ch != out_ch or stride != 1:
self.shortcut = nn.Sequential(
nn.Conv2d(in_ch, out_ch, 1, stride, bias=False),
nn.BatchNorm2d(out_ch)
)
def forward(self, x):
out = F.relu(self.bn1(self.conv1(x)))
out = self.bn2(self.conv2(out))
out += self.shortcut(x) # 殘差連接
return F.relu(out)
# 堆疊 ResNet-18 風格
class ResNet18(nn.Module):
def __init__(self, num_classes=10):
super().__init__()
self.conv1 = nn.Conv2d(3, 64, 7, 2, 3, bias=False)
self.bn1 = nn.BatchNorm2d(64)
self.pool = nn.MaxPool2d(3, 2, 1)
self.layer1 = self._make_layer(64, 64, 2)
self.layer2 = self._make_layer(64, 128, 2, stride=2)
self.layer3 = self._make_layer(128, 256, 2, stride=2)
self.layer4 = self._make_layer(256, 512, 2, stride=2)
self.gap = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Linear(512, num_classes)
def _make_layer(self, in_ch, out_ch, blocks, stride=1):
layers = [ResidualBlock(in_ch, out_ch, stride)]
for _ in range(1, blocks):
layers.append(ResidualBlock(out_ch, out_ch))
return nn.Sequential(*layers)
def forward(self, x):
x = self.pool(F.relu(self.bn1(self.conv1(x))))
x = self.layer1(x); x = self.layer2(x)
x = self.layer3(x); x = self.layer4(x)
x = self.gap(x).flatten(1)
return self.fc(x)
深度可分離卷積實作
class DepthwiseSeparableConv(nn.Module):
def __init__(self, in_ch, out_ch, kernel=3):
super().__init__()
self.depthwise = nn.Conv2d(in_ch, in_ch, kernel, padding=kernel//2, groups=in_ch, bias=False)
self.pointwise = nn.Conv2d(in_ch, out_ch, 1, bias=False)
self.bn = nn.BatchNorm2d(out_ch)
def forward(self, x):
return F.relu(self.bn(self.pointwise(self.depthwise(x))))
直接調用預訓練模型(實務推薦)
import torchvision.models as models
# ResNet-50 預訓練(ImageNet 權重)
resnet = models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V2)
# EfficientNet-B0
effnet = models.efficientnet_b0(weights=models.EfficientNet_B0_Weights.IMAGENET1K_V1)
# ConvNeXt-Tiny
convnext = models.convnext_tiny(weights=models.ConvNeXt_Tiny_Weights.IMAGENET1K_V1)
批判性反思
| 架構 | 優點 | 局限 / 注意 |
|---|---|---|
| ResNet | 解決退化、易訓練、成為骨幹標準 | 仍受感受野限制;超大模型不如後續架構 |
| MobileNet/EfficientNet | 輕量、移動端友好 | 小模型準確率天花板低;需仔細調複合縮放 |
| ConvNeXt | 證明 CNN 仍具競爭力、設計清晰 | 仍不如 ViT 在超大數據表現;推理成本較高 |
| Transformer (ViT) | 大數據 SOTA、可擴展 | 需海量數據/預訓練;小數據不如 CNN |
課程強調:選骨幹看三件事——(1) 數據量(小數據選 CNN/ConvNeXt,大數據可試 ViT);(2) 部署限制(行動端選 MobileNet/EfficientNet);(3) 準確率需求(追求極致選 EfficientNetV2/ConvNeXt-XXL)。不要盲目追新,要看約束條件。
課程影片來源
來源更正:官方 Fall 2024 第 6 講是 Generalization Theory,並不存在本文所稱的「L06 Modern CNN」。下方補充影片是第 4 講 Architectures: Grids,官方內容涵蓋 CNN、架構與 ResNet;它是相關主題補充,不能證明本文的 EfficientNet/ConvNeXt 內容來自第 6 講。原影片 vidCX_dMCu0 是第 2 講,也不提供原來未核實的 2:30:00 跳轉。
原始影片:MIT 6.7960 Fall 2024 Lec 04: Architectures: Grids — related CNN/ResNet lecture
官方來源:
查核日期:2026-10-10。
編號說明:本站 L03–L06 這四篇的編號,是本站早期依一般深度學習教學順序(優化、正則化、CNN、現代 CNN)自行規劃的,沒有逐一對照 OCW 講次表;OCW Fall 2024 的 Lec 03–06 實際是 Approximation Theory、Architectures: Grids、Architectures: Graphs、Generalization Theory,所以這四篇的 L 編號與 OCW 講次不同。2026-10-13 起標題改依 OCW 講次:CNN 架構篇對應 Lec 04,標為第 4 堂;優化、正則化、現代 CNN 三篇沒有對應的單一講次,改標主題單元。網址維持不變,所以現代 CNN 篇的網址仍帶 l06;從 Lec 07 起各篇本來就與 OCW 講次一致。
內容核對:已依字幕核對(2026-10-10):讀了嵌入的 Lec 04 Architectures: Grids 字幕(Sara Beery 主講):只有約 60–70 分處講 ResNet 殘差連接(與本文 ResNet 一節相近),字幕中沒有 MobileNet、深度可分離卷積、EfficientNet、ConvNeXt;因此本文這些內容完全是本站補充。原參考資料中「0:00–15:00 ResNet;15:00–30:00 MobileNet/EfficientNet;30:00–45:00 ConvNeXt」的段落與指向不存在投影片的連結已刪除。
更新紀錄
- 2026-10-10:標註影片狀態,核對錄影來源與取得方式。
- 2026-10-10:重查影片狀態。OCW 第 6 講仍為 Generalization Theory,沒有「Modern CNN」講次;補充影片維持第 4 講,狀態不變。
- 2026-10-10:依字幕核對影片內容。刪除對不上影片的段落時間表與不存在的投影片連結,並註明本文 MobileNet/EfficientNet/ConvNeXt 不在嵌入影片中。
參考資料
- Lec 04 Architectures: Grids (MIT OCW 6.7960 Fall 2024) — 嵌入的補充影片,後段談 ResNet 殘差連接;MobileNet/EfficientNet/ConvNeXt 不在其中
- He et al., "Deep Residual Learning for Image Recognition" (CVPR 2016) — ResNet
- Howard et al., "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" (2017)
- Tan & Le, "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" (ICML 2019)
- Liu et al., "A ConvNet for the 2020s" (CVPR 2022) — ConvNeXt
- PyTorch 官方文檔:torchvision.models
Loading...