course_day7.html 4.6 KB

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