定义:通过多层非线性变换,自动学习数据层次化表征的机器学习方法
核心突破:
z = ∑ i = 1 n w i x i + b , a = σ ( z ) z=\sum_{i=1}^{n}w_ix_i+b,a=σ(z) z=∑i=1nwixi+b,a=σ(z)
激活函数类型:
函数 | 公式 | 特性 |
---|---|---|
Sigmoid | 1 1 + e − x \frac{1}{1+e^{-x}} 1+e−x1 | 输出(0,1),易梯度消失 |
ReLU | max(0,x) | 缓解梯度消失,计算高效 |
Swish | x⋅sigmoid(βx) | 平滑非单调,Google提出 |
Xavier初始化: W ∼ u ( − 6 / ( n i n + n o u t ) , 6 / ( n i n + n o u t ) ) W\sim u(-\sqrt{6/(n_{in}+n_{out})},\sqrt{6/(n_{in}+n_{out})}) W∼u(−6/(nin+nout),6/(nin+nout))
He初始化:适配ReLU的初始化方法,方差保持为 2 n i n \frac{2}{n_{in}} nin2
计算图示例:
输入x → 卷积层 → ReLU → 池化 → 全连接 → 损失计算
↑梯度反向传播←←←←←←←←←←←←←←
链式法则应用:
∂ L ∂ W ( l ) = ∂ L ∂ a ( L ) ∏ K = l L − 1 ∂ a ( k + 1 ) ∂ a ( k ) ∂ a ( l ) ∂ W ( l ) \frac{∂{L}}{∂{W^{(l)}}} =\frac {∂L} {∂a^{(L)}}\prod_{K=l}^{L-1}\frac {∂a^{(k+1)}} {∂a^{(k)}}\frac {∂a^{(l)}} {∂W^{(l)}} ∂W(l)∂L=∂a(L)∂L∏K=lL−1∂a(k)∂a(k+1)∂W(l)∂a(l)
算法 | 更新 | 特点 |
---|---|---|
SGD | W t + 1 = W t − η ∇ W L W_{t+1}=W_{t}-η\nabla_{W}L Wt+1=Wt−η∇WL | 基础版本,易震荡 |
Momentum | v t + 1 = γ v t − η ∇ L v_{t+1}=γv_{t}-η\nabla L vt+1=γvt−η∇L | 增加惯性项 |
Adam | m t = β 1 m t − 1 + ( 1 − β 1 ) g t m_{t}=\beta_{1}m_{t-1}+(1-\beta_{1})g_t mt=β1mt−1+(1−β1)gt v t = β 2 v t − 1 + ( 1 − β 2 ) g t 2 v_{t}=\beta_{2}v_{t-1}+(1-\beta_{2})g_t^2 vt=β2vt−1+(1−β2)gt2 | 自适应学习率 |
核心组件:
ResNet残差块:
class ResidualBlock(nn.Module):
def __init__(self, in_channels):
super().__init__()
self.conv1 = nn.Conv2d(in_channels, in_channels, 3, padding=1)
self.conv2 = nn.Conv2d(in_channels, in_channels, 3, padding=1)
def forward(self, x):
identity = x
x = F.relu(self.conv1(x))
x = self.conv2(x)
return F.relu(x + identity)
自注意力机制: A t t e n t i o n ( Q , K , V ) = s o f t m a x ( Q K T d k ) V Attention(Q,K,V)=softmax(\frac{QK_T}{\sqrt{d_k}})V Attention(Q,K,V)=softmax(dkQKT)V
位置编码:
P E ( p o s , 2 i ) = s i n ( p o s 1000 0 2 i d ) PE_{(pos,2i)}=sin(\frac{pos}{10000^{\frac{2i}{d}}}) PE(pos,2i)=sin(10000d2ipos)
P E ( p o s , 2 i + 1 ) = c o s ( p o s 1000 0 2 i d ) PE_{(pos,2i+1)}=cos(\frac{pos}{10000^{\frac{2i}{d}}}) PE(pos,2i+1)=cos(10000d2ipos)
博弈目标:
m i n G m a x D V ( D , G ) = E x ∼ p d a t a [ l o g ( D ( x ) ) ] + E z ∼ p z [ l o g ( 1 − D ( G ( z ) ) ) ] min_Gmax_DV(D,G)=\mathbb{E}_{x\sim p_{data}}[log(D(x))]+\mathbb{E}_{z\sim p_{z}}[log(1-D(G(z)))] minGmaxDV(D,G)=Ex∼pdata[log(D(x))]+Ez∼pz[log(1−D(G(z)))]
训练技巧:
解决方案:残差连接、梯度裁剪、BatchNorm
BatchNorm公式:
x ^ = x − μ B μ B 2 + ϵ \hat{x}=\frac{x-μ_B}{\sqrt{μ^2_B+\epsilon}} x^=μB2+ϵx−μB
y = γ x ^ + β y=\gamma\hat{x}+\beta y=γx^+β
transform = transforms.Compose([
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(0.2,0.2,0.2),
transforms.RandomAffine(15)
])
目标检测:YOLO系列(v5推理速度45FPS)
图像分割:U-Net医学图像分割(Dice系数>0.9)
超分辨率:ESRGAN恢复4K图像
机器翻译:Transformer-Big配置(层数6→24)
文本生成:GPT-3(1750亿参数)
情感分析:BERT微调(准确率92.3% on SST-2)
图文检索:CLIP模型(Zero-shot CIFAR10准确率88%)
语音合成:Tacotron 2生成自然语音(MOS 4.53)
蛋白质折叠:AlphaFold 2(CASP14 0.16Å RMSD)
深度思考:深度学习为何成功?
通过这个系统化的知识框架,可以理解深度学习不仅是算法创新,更是数据、算力、算法、工程的协同进化结果。建议通过PyTorch实践MNIST→CIFAR→ImageNet的渐进式项目实践,配合理论理解,逐步掌握深度学习的精髓。