| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>7 - 卷积神经网络</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
- <style>
- body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; background: #1a1a2e; color: #eaeaea; }
- h1 { color: #e94560; border-bottom: 2px solid #e94560; padding-bottom: 10px; }
- h2 { color: #0f3460; background: #16213e; padding: 10px; border-left: 4px solid #e94560; margin-top: 30px; }
- .module { background: #0f3460; padding: 15px; margin: 20px 0; border-radius: 5px; }
- .module-title { color: #e94560; font-weight: bold; margin-bottom: 10px; }
- code { background: #1a1a2e; padding: 2px 6px; border-radius: 3px; color: #f0f6f6; }
- pre { background: #1a1a2e; padding: 15px; border-radius: 5px; overflow-x: auto; }
- .symbol-map { background: #16213e; padding: 10px; margin: 5px 0; border-left: 3px solid #0f3460; }
- .warning { background: #e94560; color: #fff; padding: 10px; border-radius: 5px; margin: 10px 0; }
- .youtube { background: #ff0000; color: #fff; padding: 10px; border-radius: 5px; display: inline-block; margin: 10px 0; }
- </style>
- </head>
- <body>
- <h1>👾 Day 7: 卷积神经网络</h1>
-
- <div class="module">
- <div class="module-title">1️⃣【技术债与演进动机】The Technical Debt & Evolution</div>
- 全连接网络处理图像时参数爆炸,无法捕捉空间局部性。CNN 通过卷积核共享参数,提取局部特征。
- </div>
- <div class="module">
- <div class="module-title">2️⃣【直觉建立】Visual Intuition</div>
- 想象一个滤波器在图像上滑动,每个位置计算局部区域的加权和,提取边缘、纹理等特征。
- <div class="youtube">🎬 B 站搜索:<code>卷积神经网络 CNN 直观解释</code></div>
- </div>
- <div class="module">
- <div class="module-title">3️⃣【符号解码字典】The Symbol Decoder</div>
-
- <div class="symbol-map"><strong>$X$</strong> → <code>input_tensor</code> (输入特征图,shape: [C, H, W])</div>
- <div class="symbol-map"><strong>$W$</strong> → <code>self.weight</code> (卷积核,shape: [C_out, C_in, k, k])</div>
- <div class="symbol-map"><strong>$b$</strong> → <code>self.bias</code> (偏置,shape: [C_out])</div>
- <div class="symbol-map"><strong>$Y$</strong> → <code>output_tensor</code> (输出特征图)</div>
- <div class="symbol-map"><strong>$s$</strong> → <code>stride</code> (步长)</div>
- <div class="symbol-map"><strong>$p$</strong> → <code>padding</code> (填充)</div>
-
- </div>
- <div class="module">
- <div class="module-title">4️⃣【核心推导】The Math</div>
-
- ### 卷积运算
- $$(X * W)_{i,j} = \sum_{m=0}^{k-1} \sum_{n=0}^{k-1} W_{m,n} \cdot X_{i+m, j+n}$$
- ### 输出尺寸计算
- $$H_{out} = \left\lfloor \frac{H_{in} + 2p - k}{s} \right\rfloor + 1$$
- $$W_{out} = \left\lfloor \frac{W_{in} + 2p - k}{s} \right\rfloor + 1$$
- 其中 $k$ 是卷积核尺寸,$p$ 是填充,$s$ 是步长。
- ### 梯度反向传播
- $$\frac{\partial L}{\partial W} = X_{rotated} * \frac{\partial L}{\partial Y}$$
- $$\frac{\partial L}{\partial X} = \frac{\partial L}{\partial Y} * W_{rotated}$$
- 其中 $rotated$ 表示 180 度旋转。
- </div>
- <div class="module">
- <div class="module-title">5️⃣【工程优化点】The Optimization Bottleneck</div>
- 卷积运算复杂度 $O(C_{in} \cdot C_{out} \cdot k^2 \cdot H \cdot W)$。使用深度可分离卷积(Depthwise Separable)加速。
- </div>
- <div class="module">
- <div class="module-title">6️⃣【今日靶机】The OJ Mission</div>
- <div class="warning">🎯 任务:<code>cd exercises/ && python3 day7_task.py</code></div>
- 实现 2D 卷积层的 forward 和 backward,在 MNIST 数据集上验证卷积特征提取效果。
- </div>
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
- <script>
- renderMathInElement(document.body, {
- delimiters: [
- {left: '$$', right: '$$', display: true},
- {left: '$', right: '$', display: false}
- ],
- throwOnError: false
- });
- </script>
- </body>
- </html>
|