欢迎光临
我们一直在努力

机器学习与深度学习:从基础概念到YOLOv8全解析

你是否被这些概念搞得头晕眼花?

  • 机器学习、深度学习、神经网络是什么关系?
  • CNN、RNN、LSTM、Transformer有什么区别?
  • YOLOv8用的是什么技术?

别担心!这篇文章带你理清这些概念的关系,从基础到前沿一网打尽!


📚 目录

  • 一、概念层级关系总览
  • 二、机器学习:AI的基石
  • 三、神经网络:模拟人脑的计算模型
  • 四、深度学习:多层神经网络的力量
  • 五、CNN:图像处理的王者
  • 六、RNN与LSTM:序列数据的利器
  • 七、Transformer:自然语言处理的革命
  • 八、YOLOv8:目标检测的SOTA
  • 九、技术选型指南

一、概念层级关系总览

1.1 核心概念关系图

#mermaid-svg-4LgOn8s5KDFihuu4{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-4LgOn8s5KDFihuu4 .error-icon{fill:#552222;}#mermaid-svg-4LgOn8s5KDFihuu4 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-4LgOn8s5KDFihuu4 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-4LgOn8s5KDFihuu4 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-4LgOn8s5KDFihuu4 .marker.cross{stroke:#333333;}#mermaid-svg-4LgOn8s5KDFihuu4 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-4LgOn8s5KDFihuu4 p{margin:0;}#mermaid-svg-4LgOn8s5KDFihuu4 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster-label text{fill:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster-label span{color:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster-label span p{background-color:transparent;}#mermaid-svg-4LgOn8s5KDFihuu4 .label text,#mermaid-svg-4LgOn8s5KDFihuu4 span{fill:#333;color:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 .node rect,#mermaid-svg-4LgOn8s5KDFihuu4 .node circle,#mermaid-svg-4LgOn8s5KDFihuu4 .node ellipse,#mermaid-svg-4LgOn8s5KDFihuu4 .node polygon,#mermaid-svg-4LgOn8s5KDFihuu4 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-4LgOn8s5KDFihuu4 .rough-node .label text,#mermaid-svg-4LgOn8s5KDFihuu4 .node .label text,#mermaid-svg-4LgOn8s5KDFihuu4 .image-shape .label,#mermaid-svg-4LgOn8s5KDFihuu4 .icon-shape .label{text-anchor:middle;}#mermaid-svg-4LgOn8s5KDFihuu4 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-4LgOn8s5KDFihuu4 .rough-node .label,#mermaid-svg-4LgOn8s5KDFihuu4 .node .label,#mermaid-svg-4LgOn8s5KDFihuu4 .image-shape .label,#mermaid-svg-4LgOn8s5KDFihuu4 .icon-shape .label{text-align:center;}#mermaid-svg-4LgOn8s5KDFihuu4 .node.clickable{cursor:pointer;}#mermaid-svg-4LgOn8s5KDFihuu4 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-4LgOn8s5KDFihuu4 .arrowheadPath{fill:#333333;}#mermaid-svg-4LgOn8s5KDFihuu4 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-4LgOn8s5KDFihuu4 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-4LgOn8s5KDFihuu4 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-4LgOn8s5KDFihuu4 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-4LgOn8s5KDFihuu4 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-4LgOn8s5KDFihuu4 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster text{fill:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 .cluster span{color:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-4LgOn8s5KDFihuu4 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-4LgOn8s5KDFihuu4 rect.text{fill:none;stroke-width:0;}#mermaid-svg-4LgOn8s5KDFihuu4 .icon-shape,#mermaid-svg-4LgOn8s5KDFihuu4 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-4LgOn8s5KDFihuu4 .icon-shape p,#mermaid-svg-4LgOn8s5KDFihuu4 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-4LgOn8s5KDFihuu4 .icon-shape rect,#mermaid-svg-4LgOn8s5KDFihuu4 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-4LgOn8s5KDFihuu4 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-4LgOn8s5KDFihuu4 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-4LgOn8s5KDFihuu4 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

人工智能 AI

机器学习 ML

深度学习 DL

神经网络 NN

CNN卷积神经网络

RNN循环神经网络

Transformer注意力机制

LSTM长短期记忆网络

YOLOv8目标检测

GPT/BERT大语言模型

1.2 层级关系详解

#mermaid-svg-AH8cIzchbzFROF3Y{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-AH8cIzchbzFROF3Y .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-AH8cIzchbzFROF3Y .error-icon{fill:#552222;}#mermaid-svg-AH8cIzchbzFROF3Y .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-AH8cIzchbzFROF3Y .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-AH8cIzchbzFROF3Y .marker{fill:#333333;stroke:#333333;}#mermaid-svg-AH8cIzchbzFROF3Y .marker.cross{stroke:#333333;}#mermaid-svg-AH8cIzchbzFROF3Y svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-AH8cIzchbzFROF3Y p{margin:0;}#mermaid-svg-AH8cIzchbzFROF3Y .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-AH8cIzchbzFROF3Y .cluster-label text{fill:#333;}#mermaid-svg-AH8cIzchbzFROF3Y .cluster-label span{color:#333;}#mermaid-svg-AH8cIzchbzFROF3Y .cluster-label span p{background-color:transparent;}#mermaid-svg-AH8cIzchbzFROF3Y .label text,#mermaid-svg-AH8cIzchbzFROF3Y span{fill:#333;color:#333;}#mermaid-svg-AH8cIzchbzFROF3Y .node rect,#mermaid-svg-AH8cIzchbzFROF3Y .node circle,#mermaid-svg-AH8cIzchbzFROF3Y .node ellipse,#mermaid-svg-AH8cIzchbzFROF3Y .node polygon,#mermaid-svg-AH8cIzchbzFROF3Y .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-AH8cIzchbzFROF3Y .rough-node .label text,#mermaid-svg-AH8cIzchbzFROF3Y .node .label text,#mermaid-svg-AH8cIzchbzFROF3Y .image-shape .label,#mermaid-svg-AH8cIzchbzFROF3Y .icon-shape .label{text-anchor:middle;}#mermaid-svg-AH8cIzchbzFROF3Y .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-AH8cIzchbzFROF3Y .rough-node .label,#mermaid-svg-AH8cIzchbzFROF3Y .node .label,#mermaid-svg-AH8cIzchbzFROF3Y .image-shape .label,#mermaid-svg-AH8cIzchbzFROF3Y .icon-shape .label{text-align:center;}#mermaid-svg-AH8cIzchbzFROF3Y .node.clickable{cursor:pointer;}#mermaid-svg-AH8cIzchbzFROF3Y .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-AH8cIzchbzFROF3Y .arrowheadPath{fill:#333333;}#mermaid-svg-AH8cIzchbzFROF3Y .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-AH8cIzchbzFROF3Y .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-AH8cIzchbzFROF3Y .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-AH8cIzchbzFROF3Y .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-AH8cIzchbzFROF3Y .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-AH8cIzchbzFROF3Y .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-AH8cIzchbzFROF3Y .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-AH8cIzchbzFROF3Y .cluster text{fill:#333;}#mermaid-svg-AH8cIzchbzFROF3Y .cluster span{color:#333;}#mermaid-svg-AH8cIzchbzFROF3Y div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-AH8cIzchbzFROF3Y .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-AH8cIzchbzFROF3Y rect.text{fill:none;stroke-width:0;}#mermaid-svg-AH8cIzchbzFROF3Y .icon-shape,#mermaid-svg-AH8cIzchbzFROF3Y .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-AH8cIzchbzFROF3Y .icon-shape p,#mermaid-svg-AH8cIzchbzFROF3Y .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-AH8cIzchbzFROF3Y .icon-shape rect,#mermaid-svg-AH8cIzchbzFROF3Y .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-AH8cIzchbzFROF3Y .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-AH8cIzchbzFROF3Y .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-AH8cIzchbzFROF3Y :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

第五层:应用模型

YOLOv8

GPT

BERT

第四层:具体架构

CNN

RNN

Transformer

第三层:深度学习

DL = 多层神经网络学习

第二层:机器学习

ML = 从数据中学习规律

第一层:人工智能

AI = 机器模拟人类智能

1.3 核心概念对比

概念定义核心思想典型应用
人工智能 机器模拟人类智能 让机器像人一样思考 智能助手、自动驾驶
机器学习 从数据中学习规律 数据驱动决策 推荐系统、预测分析
深度学习 多层神经网络学习 自动特征提取 图像识别、NLP
神经网络 模拟人脑的计算模型 神经元连接计算 各种AI任务

二、机器学习:AI的基石

2.1 什么是机器学习?

#mermaid-svg-anMawhBAZRSQqlUv{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-anMawhBAZRSQqlUv .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-anMawhBAZRSQqlUv .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-anMawhBAZRSQqlUv .error-icon{fill:#552222;}#mermaid-svg-anMawhBAZRSQqlUv .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-anMawhBAZRSQqlUv .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-anMawhBAZRSQqlUv .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-anMawhBAZRSQqlUv .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-anMawhBAZRSQqlUv .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-anMawhBAZRSQqlUv .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-anMawhBAZRSQqlUv .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-anMawhBAZRSQqlUv .marker{fill:#333333;stroke:#333333;}#mermaid-svg-anMawhBAZRSQqlUv .marker.cross{stroke:#333333;}#mermaid-svg-anMawhBAZRSQqlUv svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-anMawhBAZRSQqlUv p{margin:0;}#mermaid-svg-anMawhBAZRSQqlUv .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-anMawhBAZRSQqlUv .cluster-label text{fill:#333;}#mermaid-svg-anMawhBAZRSQqlUv .cluster-label span{color:#333;}#mermaid-svg-anMawhBAZRSQqlUv .cluster-label span p{background-color:transparent;}#mermaid-svg-anMawhBAZRSQqlUv .label text,#mermaid-svg-anMawhBAZRSQqlUv span{fill:#333;color:#333;}#mermaid-svg-anMawhBAZRSQqlUv .node rect,#mermaid-svg-anMawhBAZRSQqlUv .node circle,#mermaid-svg-anMawhBAZRSQqlUv .node ellipse,#mermaid-svg-anMawhBAZRSQqlUv .node polygon,#mermaid-svg-anMawhBAZRSQqlUv .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-anMawhBAZRSQqlUv .rough-node .label text,#mermaid-svg-anMawhBAZRSQqlUv .node .label text,#mermaid-svg-anMawhBAZRSQqlUv .image-shape .label,#mermaid-svg-anMawhBAZRSQqlUv .icon-shape .label{text-anchor:middle;}#mermaid-svg-anMawhBAZRSQqlUv .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-anMawhBAZRSQqlUv .rough-node .label,#mermaid-svg-anMawhBAZRSQqlUv .node .label,#mermaid-svg-anMawhBAZRSQqlUv .image-shape .label,#mermaid-svg-anMawhBAZRSQqlUv .icon-shape .label{text-align:center;}#mermaid-svg-anMawhBAZRSQqlUv .node.clickable{cursor:pointer;}#mermaid-svg-anMawhBAZRSQqlUv .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-anMawhBAZRSQqlUv .arrowheadPath{fill:#333333;}#mermaid-svg-anMawhBAZRSQqlUv .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-anMawhBAZRSQqlUv .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-anMawhBAZRSQqlUv .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-anMawhBAZRSQqlUv .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-anMawhBAZRSQqlUv .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-anMawhBAZRSQqlUv .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-anMawhBAZRSQqlUv .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-anMawhBAZRSQqlUv .cluster text{fill:#333;}#mermaid-svg-anMawhBAZRSQqlUv .cluster span{color:#333;}#mermaid-svg-anMawhBAZRSQqlUv div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-anMawhBAZRSQqlUv .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-anMawhBAZRSQqlUv rect.text{fill:none;stroke-width:0;}#mermaid-svg-anMawhBAZRSQqlUv .icon-shape,#mermaid-svg-anMawhBAZRSQqlUv .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-anMawhBAZRSQqlUv .icon-shape p,#mermaid-svg-anMawhBAZRSQqlUv .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-anMawhBAZRSQqlUv .icon-shape rect,#mermaid-svg-anMawhBAZRSQqlUv .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-anMawhBAZRSQqlUv .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-anMawhBAZRSQqlUv .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-anMawhBAZRSQqlUv :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

数据

机器学习算法

模型

预测/决策

传统编程

规则 + 数据 = 结果

机器学习

数据 + 结果 = 规则

核心定义:

机器学习(Machine Learning) 是人工智能的一个子领域,它让计算机能够从数据中自动学习规律,而无需显式编程。

2.2 机器学习的三大类型

#mermaid-svg-N9esFcaxfmjILTBT{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-N9esFcaxfmjILTBT .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-N9esFcaxfmjILTBT .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-N9esFcaxfmjILTBT .error-icon{fill:#552222;}#mermaid-svg-N9esFcaxfmjILTBT .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-N9esFcaxfmjILTBT .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-N9esFcaxfmjILTBT .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-N9esFcaxfmjILTBT .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-N9esFcaxfmjILTBT .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-N9esFcaxfmjILTBT .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-N9esFcaxfmjILTBT .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-N9esFcaxfmjILTBT .marker{fill:#333333;stroke:#333333;}#mermaid-svg-N9esFcaxfmjILTBT .marker.cross{stroke:#333333;}#mermaid-svg-N9esFcaxfmjILTBT svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-N9esFcaxfmjILTBT p{margin:0;}#mermaid-svg-N9esFcaxfmjILTBT .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-N9esFcaxfmjILTBT .cluster-label text{fill:#333;}#mermaid-svg-N9esFcaxfmjILTBT .cluster-label span{color:#333;}#mermaid-svg-N9esFcaxfmjILTBT .cluster-label span p{background-color:transparent;}#mermaid-svg-N9esFcaxfmjILTBT .label text,#mermaid-svg-N9esFcaxfmjILTBT span{fill:#333;color:#333;}#mermaid-svg-N9esFcaxfmjILTBT .node rect,#mermaid-svg-N9esFcaxfmjILTBT .node circle,#mermaid-svg-N9esFcaxfmjILTBT .node ellipse,#mermaid-svg-N9esFcaxfmjILTBT .node polygon,#mermaid-svg-N9esFcaxfmjILTBT .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-N9esFcaxfmjILTBT .rough-node .label text,#mermaid-svg-N9esFcaxfmjILTBT .node .label text,#mermaid-svg-N9esFcaxfmjILTBT .image-shape .label,#mermaid-svg-N9esFcaxfmjILTBT .icon-shape .label{text-anchor:middle;}#mermaid-svg-N9esFcaxfmjILTBT .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-N9esFcaxfmjILTBT .rough-node .label,#mermaid-svg-N9esFcaxfmjILTBT .node .label,#mermaid-svg-N9esFcaxfmjILTBT .image-shape .label,#mermaid-svg-N9esFcaxfmjILTBT .icon-shape .label{text-align:center;}#mermaid-svg-N9esFcaxfmjILTBT .node.clickable{cursor:pointer;}#mermaid-svg-N9esFcaxfmjILTBT .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-N9esFcaxfmjILTBT .arrowheadPath{fill:#333333;}#mermaid-svg-N9esFcaxfmjILTBT .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-N9esFcaxfmjILTBT .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-N9esFcaxfmjILTBT .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-N9esFcaxfmjILTBT .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-N9esFcaxfmjILTBT .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-N9esFcaxfmjILTBT .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-N9esFcaxfmjILTBT .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-N9esFcaxfmjILTBT .cluster text{fill:#333;}#mermaid-svg-N9esFcaxfmjILTBT .cluster span{color:#333;}#mermaid-svg-N9esFcaxfmjILTBT div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-N9esFcaxfmjILTBT .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-N9esFcaxfmjILTBT rect.text{fill:none;stroke-width:0;}#mermaid-svg-N9esFcaxfmjILTBT .icon-shape,#mermaid-svg-N9esFcaxfmjILTBT .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-N9esFcaxfmjILTBT .icon-shape p,#mermaid-svg-N9esFcaxfmjILTBT .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-N9esFcaxfmjILTBT .icon-shape rect,#mermaid-svg-N9esFcaxfmjILTBT .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-N9esFcaxfmjILTBT .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-N9esFcaxfmjILTBT .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-N9esFcaxfmjILTBT :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

机器学习

监督学习

无监督学习

强化学习

分类

回归

聚类

降维

游戏AI

机器人控制

三大类型详解:

类型特点数据要求典型算法
监督学习 有标签数据 输入+输出 线性回归、决策树、SVM
无监督学习 无标签数据 仅输入 K-Means、PCA
强化学习 奖励机制 环境+动作 Q-Learning、DQN

2.3 经典机器学习算法

# 监督学习示例:线性回归
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

# 1. 准备数据
X, y = load_data() # 特征和标签
X_train, X_test, y_train, y_test = train_test_split(X, y)

# 2. 训练模型
model = LinearRegression()
model.fit(X_train, y_train)

# 3. 预测
predictions = model.predict(X_test)

# 4. 评估
score = model.score(X_test, y_test)

# 无监督学习示例:K-Means聚类
from sklearn.cluster import KMeans

# 1. 准备数据
X = load_data() # 仅特征,无标签

# 2. 训练模型
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)

# 3. 获取聚类结果
labels = kmeans.labels_
centroids = kmeans.cluster_centers_

2.4 机器学习 vs 深度学习

#mermaid-svg-6cxkzEMY06LY8k1o{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-6cxkzEMY06LY8k1o .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-6cxkzEMY06LY8k1o .error-icon{fill:#552222;}#mermaid-svg-6cxkzEMY06LY8k1o .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-6cxkzEMY06LY8k1o .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-6cxkzEMY06LY8k1o .marker{fill:#333333;stroke:#333333;}#mermaid-svg-6cxkzEMY06LY8k1o .marker.cross{stroke:#333333;}#mermaid-svg-6cxkzEMY06LY8k1o svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-6cxkzEMY06LY8k1o p{margin:0;}#mermaid-svg-6cxkzEMY06LY8k1o .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-6cxkzEMY06LY8k1o .cluster-label text{fill:#333;}#mermaid-svg-6cxkzEMY06LY8k1o .cluster-label span{color:#333;}#mermaid-svg-6cxkzEMY06LY8k1o .cluster-label span p{background-color:transparent;}#mermaid-svg-6cxkzEMY06LY8k1o .label text,#mermaid-svg-6cxkzEMY06LY8k1o span{fill:#333;color:#333;}#mermaid-svg-6cxkzEMY06LY8k1o .node rect,#mermaid-svg-6cxkzEMY06LY8k1o .node circle,#mermaid-svg-6cxkzEMY06LY8k1o .node ellipse,#mermaid-svg-6cxkzEMY06LY8k1o .node polygon,#mermaid-svg-6cxkzEMY06LY8k1o .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-6cxkzEMY06LY8k1o .rough-node .label text,#mermaid-svg-6cxkzEMY06LY8k1o .node .label text,#mermaid-svg-6cxkzEMY06LY8k1o .image-shape .label,#mermaid-svg-6cxkzEMY06LY8k1o .icon-shape .label{text-anchor:middle;}#mermaid-svg-6cxkzEMY06LY8k1o .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-6cxkzEMY06LY8k1o .rough-node .label,#mermaid-svg-6cxkzEMY06LY8k1o .node .label,#mermaid-svg-6cxkzEMY06LY8k1o .image-shape .label,#mermaid-svg-6cxkzEMY06LY8k1o .icon-shape .label{text-align:center;}#mermaid-svg-6cxkzEMY06LY8k1o .node.clickable{cursor:pointer;}#mermaid-svg-6cxkzEMY06LY8k1o .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-6cxkzEMY06LY8k1o .arrowheadPath{fill:#333333;}#mermaid-svg-6cxkzEMY06LY8k1o .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-6cxkzEMY06LY8k1o .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-6cxkzEMY06LY8k1o .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6cxkzEMY06LY8k1o .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-6cxkzEMY06LY8k1o .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6cxkzEMY06LY8k1o .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-6cxkzEMY06LY8k1o .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-6cxkzEMY06LY8k1o .cluster text{fill:#333;}#mermaid-svg-6cxkzEMY06LY8k1o .cluster span{color:#333;}#mermaid-svg-6cxkzEMY06LY8k1o div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-6cxkzEMY06LY8k1o .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-6cxkzEMY06LY8k1o rect.text{fill:none;stroke-width:0;}#mermaid-svg-6cxkzEMY06LY8k1o .icon-shape,#mermaid-svg-6cxkzEMY06LY8k1o .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6cxkzEMY06LY8k1o .icon-shape p,#mermaid-svg-6cxkzEMY06LY8k1o .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-6cxkzEMY06LY8k1o .icon-shape rect,#mermaid-svg-6cxkzEMY06LY8k1o .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6cxkzEMY06LY8k1o .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-6cxkzEMY06LY8k1o .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-6cxkzEMY06LY8k1o :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

深度学习

原始数据

自动特征提取神经网络

端到端学习

预测结果

机器学习

原始数据

人工特征提取

传统算法

预测结果

核心区别:

维度机器学习深度学习
特征提取 人工设计 自动学习
数据需求 较少 大量
计算资源 CPU即可 需要GPU
可解释性
适用场景 结构化数据 非结构化数据

三、神经网络:模拟人脑的计算模型

3.1 神经网络的灵感来源

#mermaid-svg-hFwfHZS7beGRxBTd{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-hFwfHZS7beGRxBTd .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-hFwfHZS7beGRxBTd .error-icon{fill:#552222;}#mermaid-svg-hFwfHZS7beGRxBTd .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-hFwfHZS7beGRxBTd .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-hFwfHZS7beGRxBTd .marker{fill:#333333;stroke:#333333;}#mermaid-svg-hFwfHZS7beGRxBTd .marker.cross{stroke:#333333;}#mermaid-svg-hFwfHZS7beGRxBTd svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-hFwfHZS7beGRxBTd p{margin:0;}#mermaid-svg-hFwfHZS7beGRxBTd .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-hFwfHZS7beGRxBTd .cluster-label text{fill:#333;}#mermaid-svg-hFwfHZS7beGRxBTd .cluster-label span{color:#333;}#mermaid-svg-hFwfHZS7beGRxBTd .cluster-label span p{background-color:transparent;}#mermaid-svg-hFwfHZS7beGRxBTd .label text,#mermaid-svg-hFwfHZS7beGRxBTd span{fill:#333;color:#333;}#mermaid-svg-hFwfHZS7beGRxBTd .node rect,#mermaid-svg-hFwfHZS7beGRxBTd .node circle,#mermaid-svg-hFwfHZS7beGRxBTd .node ellipse,#mermaid-svg-hFwfHZS7beGRxBTd .node polygon,#mermaid-svg-hFwfHZS7beGRxBTd .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-hFwfHZS7beGRxBTd .rough-node .label text,#mermaid-svg-hFwfHZS7beGRxBTd .node .label text,#mermaid-svg-hFwfHZS7beGRxBTd .image-shape .label,#mermaid-svg-hFwfHZS7beGRxBTd .icon-shape .label{text-anchor:middle;}#mermaid-svg-hFwfHZS7beGRxBTd .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-hFwfHZS7beGRxBTd .rough-node .label,#mermaid-svg-hFwfHZS7beGRxBTd .node .label,#mermaid-svg-hFwfHZS7beGRxBTd .image-shape .label,#mermaid-svg-hFwfHZS7beGRxBTd .icon-shape .label{text-align:center;}#mermaid-svg-hFwfHZS7beGRxBTd .node.clickable{cursor:pointer;}#mermaid-svg-hFwfHZS7beGRxBTd .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-hFwfHZS7beGRxBTd .arrowheadPath{fill:#333333;}#mermaid-svg-hFwfHZS7beGRxBTd .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-hFwfHZS7beGRxBTd .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-hFwfHZS7beGRxBTd .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-hFwfHZS7beGRxBTd .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-hFwfHZS7beGRxBTd .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-hFwfHZS7beGRxBTd .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-hFwfHZS7beGRxBTd .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-hFwfHZS7beGRxBTd .cluster text{fill:#333;}#mermaid-svg-hFwfHZS7beGRxBTd .cluster span{color:#333;}#mermaid-svg-hFwfHZS7beGRxBTd div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-hFwfHZS7beGRxBTd .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-hFwfHZS7beGRxBTd rect.text{fill:none;stroke-width:0;}#mermaid-svg-hFwfHZS7beGRxBTd .icon-shape,#mermaid-svg-hFwfHZS7beGRxBTd .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-hFwfHZS7beGRxBTd .icon-shape p,#mermaid-svg-hFwfHZS7beGRxBTd .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-hFwfHZS7beGRxBTd .icon-shape rect,#mermaid-svg-hFwfHZS7beGRxBTd .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-hFwfHZS7beGRxBTd .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-hFwfHZS7beGRxBTd .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-hFwfHZS7beGRxBTd :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

人工神经元

输入x1, x2, …

加权求和Σw·x + b

激活函数σ

输出y

生物神经元

树突接收信号

细胞体处理信号

轴突传递信号

突触连接其他神经元

3.2 单个神经元的计算

#mermaid-svg-5jnn49bIaWbUEOIt{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-5jnn49bIaWbUEOIt .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-5jnn49bIaWbUEOIt .error-icon{fill:#552222;}#mermaid-svg-5jnn49bIaWbUEOIt .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-5jnn49bIaWbUEOIt .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-5jnn49bIaWbUEOIt .marker{fill:#333333;stroke:#333333;}#mermaid-svg-5jnn49bIaWbUEOIt .marker.cross{stroke:#333333;}#mermaid-svg-5jnn49bIaWbUEOIt svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-5jnn49bIaWbUEOIt p{margin:0;}#mermaid-svg-5jnn49bIaWbUEOIt .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-5jnn49bIaWbUEOIt .cluster-label text{fill:#333;}#mermaid-svg-5jnn49bIaWbUEOIt .cluster-label span{color:#333;}#mermaid-svg-5jnn49bIaWbUEOIt .cluster-label span p{background-color:transparent;}#mermaid-svg-5jnn49bIaWbUEOIt .label text,#mermaid-svg-5jnn49bIaWbUEOIt span{fill:#333;color:#333;}#mermaid-svg-5jnn49bIaWbUEOIt .node rect,#mermaid-svg-5jnn49bIaWbUEOIt .node circle,#mermaid-svg-5jnn49bIaWbUEOIt .node ellipse,#mermaid-svg-5jnn49bIaWbUEOIt .node polygon,#mermaid-svg-5jnn49bIaWbUEOIt .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-5jnn49bIaWbUEOIt .rough-node .label text,#mermaid-svg-5jnn49bIaWbUEOIt .node .label text,#mermaid-svg-5jnn49bIaWbUEOIt .image-shape .label,#mermaid-svg-5jnn49bIaWbUEOIt .icon-shape .label{text-anchor:middle;}#mermaid-svg-5jnn49bIaWbUEOIt .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-5jnn49bIaWbUEOIt .rough-node .label,#mermaid-svg-5jnn49bIaWbUEOIt .node .label,#mermaid-svg-5jnn49bIaWbUEOIt .image-shape .label,#mermaid-svg-5jnn49bIaWbUEOIt .icon-shape .label{text-align:center;}#mermaid-svg-5jnn49bIaWbUEOIt .node.clickable{cursor:pointer;}#mermaid-svg-5jnn49bIaWbUEOIt .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-5jnn49bIaWbUEOIt .arrowheadPath{fill:#333333;}#mermaid-svg-5jnn49bIaWbUEOIt .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-5jnn49bIaWbUEOIt .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-5jnn49bIaWbUEOIt .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5jnn49bIaWbUEOIt .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-5jnn49bIaWbUEOIt .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5jnn49bIaWbUEOIt .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-5jnn49bIaWbUEOIt .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-5jnn49bIaWbUEOIt .cluster text{fill:#333;}#mermaid-svg-5jnn49bIaWbUEOIt .cluster span{color:#333;}#mermaid-svg-5jnn49bIaWbUEOIt div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-5jnn49bIaWbUEOIt .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-5jnn49bIaWbUEOIt rect.text{fill:none;stroke-width:0;}#mermaid-svg-5jnn49bIaWbUEOIt .icon-shape,#mermaid-svg-5jnn49bIaWbUEOIt .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5jnn49bIaWbUEOIt .icon-shape p,#mermaid-svg-5jnn49bIaWbUEOIt .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-5jnn49bIaWbUEOIt .icon-shape rect,#mermaid-svg-5jnn49bIaWbUEOIt .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5jnn49bIaWbUEOIt .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-5jnn49bIaWbUEOIt .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-5jnn49bIaWbUEOIt :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

输出层

激活层

计算层

输入层

x1

x2

x3

w1

w2

w3

bias

激活函数ReLU/Sigmoid

y

Σ w·x + b

数学公式:

y = f(Σ(wi × xi) + b)

其中:
– xi: 输入特征
– wi: 权重
– b: 偏置
– f: 激活函数

3.3 常见激活函数

#mermaid-svg-39cqE7TaWY40mrqV{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-39cqE7TaWY40mrqV .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-39cqE7TaWY40mrqV .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-39cqE7TaWY40mrqV .error-icon{fill:#552222;}#mermaid-svg-39cqE7TaWY40mrqV .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-39cqE7TaWY40mrqV .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-39cqE7TaWY40mrqV .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-39cqE7TaWY40mrqV .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-39cqE7TaWY40mrqV .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-39cqE7TaWY40mrqV .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-39cqE7TaWY40mrqV .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-39cqE7TaWY40mrqV .marker{fill:#333333;stroke:#333333;}#mermaid-svg-39cqE7TaWY40mrqV .marker.cross{stroke:#333333;}#mermaid-svg-39cqE7TaWY40mrqV svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-39cqE7TaWY40mrqV p{margin:0;}#mermaid-svg-39cqE7TaWY40mrqV .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-39cqE7TaWY40mrqV .cluster-label text{fill:#333;}#mermaid-svg-39cqE7TaWY40mrqV .cluster-label span{color:#333;}#mermaid-svg-39cqE7TaWY40mrqV .cluster-label span p{background-color:transparent;}#mermaid-svg-39cqE7TaWY40mrqV .label text,#mermaid-svg-39cqE7TaWY40mrqV span{fill:#333;color:#333;}#mermaid-svg-39cqE7TaWY40mrqV .node rect,#mermaid-svg-39cqE7TaWY40mrqV .node circle,#mermaid-svg-39cqE7TaWY40mrqV .node ellipse,#mermaid-svg-39cqE7TaWY40mrqV .node polygon,#mermaid-svg-39cqE7TaWY40mrqV .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-39cqE7TaWY40mrqV .rough-node .label text,#mermaid-svg-39cqE7TaWY40mrqV .node .label text,#mermaid-svg-39cqE7TaWY40mrqV .image-shape .label,#mermaid-svg-39cqE7TaWY40mrqV .icon-shape .label{text-anchor:middle;}#mermaid-svg-39cqE7TaWY40mrqV .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-39cqE7TaWY40mrqV .rough-node .label,#mermaid-svg-39cqE7TaWY40mrqV .node .label,#mermaid-svg-39cqE7TaWY40mrqV .image-shape .label,#mermaid-svg-39cqE7TaWY40mrqV .icon-shape .label{text-align:center;}#mermaid-svg-39cqE7TaWY40mrqV .node.clickable{cursor:pointer;}#mermaid-svg-39cqE7TaWY40mrqV .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-39cqE7TaWY40mrqV .arrowheadPath{fill:#333333;}#mermaid-svg-39cqE7TaWY40mrqV .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-39cqE7TaWY40mrqV .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-39cqE7TaWY40mrqV .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-39cqE7TaWY40mrqV .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-39cqE7TaWY40mrqV .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-39cqE7TaWY40mrqV .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-39cqE7TaWY40mrqV .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-39cqE7TaWY40mrqV .cluster text{fill:#333;}#mermaid-svg-39cqE7TaWY40mrqV .cluster span{color:#333;}#mermaid-svg-39cqE7TaWY40mrqV div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-39cqE7TaWY40mrqV .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-39cqE7TaWY40mrqV rect.text{fill:none;stroke-width:0;}#mermaid-svg-39cqE7TaWY40mrqV .icon-shape,#mermaid-svg-39cqE7TaWY40mrqV .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-39cqE7TaWY40mrqV .icon-shape p,#mermaid-svg-39cqE7TaWY40mrqV .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-39cqE7TaWY40mrqV .icon-shape rect,#mermaid-svg-39cqE7TaWY40mrqV .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-39cqE7TaWY40mrqV .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-39cqE7TaWY40mrqV .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-39cqE7TaWY40mrqV :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

激活函数

Sigmoid

Tanh

ReLU

Leaky ReLU

Softmax

输出范围: 0-1用于二分类

输出范围: -1到1用于隐藏层

输出范围: 0到∞最常用

解决ReLU死神经元问题

输出概率分布用于多分类

激活函数代码示例:

import numpy as np

def sigmoid(x):
"""Sigmoid激活函数"""
return 1 / (1 + np.exp(x))

def relu(x):
"""ReLU激活函数"""
return np.maximum(0, x)

def softmax(x):
"""Softmax激活函数"""
exp_x = np.exp(x np.max(x)) # 防止溢出
return exp_x / np.sum(exp_x)

# 使用示例
x = np.array([2, 1, 0, 1, 2])

print("Sigmoid:", sigmoid(x))
print("ReLU:", relu(x))
print("Softmax:", softmax(x))

3.4 多层神经网络(MLP)

#mermaid-svg-MKND5rfMZzcnf0nI{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-MKND5rfMZzcnf0nI .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-MKND5rfMZzcnf0nI .error-icon{fill:#552222;}#mermaid-svg-MKND5rfMZzcnf0nI .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MKND5rfMZzcnf0nI .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MKND5rfMZzcnf0nI .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MKND5rfMZzcnf0nI .marker.cross{stroke:#333333;}#mermaid-svg-MKND5rfMZzcnf0nI svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MKND5rfMZzcnf0nI p{margin:0;}#mermaid-svg-MKND5rfMZzcnf0nI .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-MKND5rfMZzcnf0nI .cluster-label text{fill:#333;}#mermaid-svg-MKND5rfMZzcnf0nI .cluster-label span{color:#333;}#mermaid-svg-MKND5rfMZzcnf0nI .cluster-label span p{background-color:transparent;}#mermaid-svg-MKND5rfMZzcnf0nI .label text,#mermaid-svg-MKND5rfMZzcnf0nI span{fill:#333;color:#333;}#mermaid-svg-MKND5rfMZzcnf0nI .node rect,#mermaid-svg-MKND5rfMZzcnf0nI .node circle,#mermaid-svg-MKND5rfMZzcnf0nI .node ellipse,#mermaid-svg-MKND5rfMZzcnf0nI .node polygon,#mermaid-svg-MKND5rfMZzcnf0nI .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MKND5rfMZzcnf0nI .rough-node .label text,#mermaid-svg-MKND5rfMZzcnf0nI .node .label text,#mermaid-svg-MKND5rfMZzcnf0nI .image-shape .label,#mermaid-svg-MKND5rfMZzcnf0nI .icon-shape .label{text-anchor:middle;}#mermaid-svg-MKND5rfMZzcnf0nI .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-MKND5rfMZzcnf0nI .rough-node .label,#mermaid-svg-MKND5rfMZzcnf0nI .node .label,#mermaid-svg-MKND5rfMZzcnf0nI .image-shape .label,#mermaid-svg-MKND5rfMZzcnf0nI .icon-shape .label{text-align:center;}#mermaid-svg-MKND5rfMZzcnf0nI .node.clickable{cursor:pointer;}#mermaid-svg-MKND5rfMZzcnf0nI .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-MKND5rfMZzcnf0nI .arrowheadPath{fill:#333333;}#mermaid-svg-MKND5rfMZzcnf0nI .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MKND5rfMZzcnf0nI .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MKND5rfMZzcnf0nI .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MKND5rfMZzcnf0nI .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-MKND5rfMZzcnf0nI .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MKND5rfMZzcnf0nI .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-MKND5rfMZzcnf0nI .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MKND5rfMZzcnf0nI .cluster text{fill:#333;}#mermaid-svg-MKND5rfMZzcnf0nI .cluster span{color:#333;}#mermaid-svg-MKND5rfMZzcnf0nI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MKND5rfMZzcnf0nI .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-MKND5rfMZzcnf0nI rect.text{fill:none;stroke-width:0;}#mermaid-svg-MKND5rfMZzcnf0nI .icon-shape,#mermaid-svg-MKND5rfMZzcnf0nI .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MKND5rfMZzcnf0nI .icon-shape p,#mermaid-svg-MKND5rfMZzcnf0nI .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-MKND5rfMZzcnf0nI .icon-shape rect,#mermaid-svg-MKND5rfMZzcnf0nI .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MKND5rfMZzcnf0nI .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-MKND5rfMZzcnf0nI .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-MKND5rfMZzcnf0nI :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

输出层

隐藏层2

隐藏层1

输入层

x1

x2

x3

h1

h2

h3

h4

h5

h6

h7

y1

y2

MLP代码示例:

import torch
import torch.nn as nn

class MLP(nn.Module):
"""
多层感知机(Multi-Layer Perceptron)

结构:输入层 -> 隐藏层1 -> 隐藏层2 -> 输出层
"""
def __init__(self, input_size, hidden_size, output_size):
super(MLP, self).__init__()

self.layer1 = nn.Linear(input_size, hidden_size)
self.layer2 = nn.Linear(hidden_size, hidden_size)
self.layer3 = nn.Linear(hidden_size, output_size)

self.relu = nn.ReLU()
self.softmax = nn.Softmax(dim=1)

def forward(self, x):
x = self.relu(self.layer1(x))
x = self.relu(self.layer2(x))
x = self.softmax(self.layer3(x))
return x

# 使用示例
model = MLP(input_size=784, hidden_size=256, output_size=10)
x = torch.randn(32, 784) # batch_size=32
output = model(x)
print(output.shape) # torch.Size([32, 10])


四、深度学习:多层神经网络的力量

4.1 什么是深度学习?

#mermaid-svg-KL3qhqKZT1kjFHGk{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-KL3qhqKZT1kjFHGk .error-icon{fill:#552222;}#mermaid-svg-KL3qhqKZT1kjFHGk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-KL3qhqKZT1kjFHGk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-KL3qhqKZT1kjFHGk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-KL3qhqKZT1kjFHGk .marker.cross{stroke:#333333;}#mermaid-svg-KL3qhqKZT1kjFHGk svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-KL3qhqKZT1kjFHGk p{margin:0;}#mermaid-svg-KL3qhqKZT1kjFHGk .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster-label text{fill:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster-label span{color:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster-label span p{background-color:transparent;}#mermaid-svg-KL3qhqKZT1kjFHGk .label text,#mermaid-svg-KL3qhqKZT1kjFHGk span{fill:#333;color:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk .node rect,#mermaid-svg-KL3qhqKZT1kjFHGk .node circle,#mermaid-svg-KL3qhqKZT1kjFHGk .node ellipse,#mermaid-svg-KL3qhqKZT1kjFHGk .node polygon,#mermaid-svg-KL3qhqKZT1kjFHGk .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-KL3qhqKZT1kjFHGk .rough-node .label text,#mermaid-svg-KL3qhqKZT1kjFHGk .node .label text,#mermaid-svg-KL3qhqKZT1kjFHGk .image-shape .label,#mermaid-svg-KL3qhqKZT1kjFHGk .icon-shape .label{text-anchor:middle;}#mermaid-svg-KL3qhqKZT1kjFHGk .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-KL3qhqKZT1kjFHGk .rough-node .label,#mermaid-svg-KL3qhqKZT1kjFHGk .node .label,#mermaid-svg-KL3qhqKZT1kjFHGk .image-shape .label,#mermaid-svg-KL3qhqKZT1kjFHGk .icon-shape .label{text-align:center;}#mermaid-svg-KL3qhqKZT1kjFHGk .node.clickable{cursor:pointer;}#mermaid-svg-KL3qhqKZT1kjFHGk .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-KL3qhqKZT1kjFHGk .arrowheadPath{fill:#333333;}#mermaid-svg-KL3qhqKZT1kjFHGk .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-KL3qhqKZT1kjFHGk .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-KL3qhqKZT1kjFHGk .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-KL3qhqKZT1kjFHGk .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-KL3qhqKZT1kjFHGk .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-KL3qhqKZT1kjFHGk .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster text{fill:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk .cluster span{color:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-KL3qhqKZT1kjFHGk .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-KL3qhqKZT1kjFHGk rect.text{fill:none;stroke-width:0;}#mermaid-svg-KL3qhqKZT1kjFHGk .icon-shape,#mermaid-svg-KL3qhqKZT1kjFHGk .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-KL3qhqKZT1kjFHGk .icon-shape p,#mermaid-svg-KL3qhqKZT1kjFHGk .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-KL3qhqKZT1kjFHGk .icon-shape rect,#mermaid-svg-KL3qhqKZT1kjFHGk .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-KL3qhqKZT1kjFHGk .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-KL3qhqKZT1kjFHGk .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-KL3qhqKZT1kjFHGk :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

深度学习

核心特点

多层神经网络

自动特征提取

端到端学习

大数据驱动

深度 = 多个隐藏层

无需人工设计特征

输入到输出一体化

数据越多效果越好

核心定义:

深度学习(Deep Learning) 是机器学习的一个子领域,使用多层神经网络自动学习数据的层次化表示。

4.2 深度学习的"深"体现在哪里?

#mermaid-svg-6TzznyAWtEnyu6xs{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-6TzznyAWtEnyu6xs .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-6TzznyAWtEnyu6xs .error-icon{fill:#552222;}#mermaid-svg-6TzznyAWtEnyu6xs .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-6TzznyAWtEnyu6xs .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-6TzznyAWtEnyu6xs .marker{fill:#333333;stroke:#333333;}#mermaid-svg-6TzznyAWtEnyu6xs .marker.cross{stroke:#333333;}#mermaid-svg-6TzznyAWtEnyu6xs svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-6TzznyAWtEnyu6xs p{margin:0;}#mermaid-svg-6TzznyAWtEnyu6xs .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-6TzznyAWtEnyu6xs .cluster-label text{fill:#333;}#mermaid-svg-6TzznyAWtEnyu6xs .cluster-label span{color:#333;}#mermaid-svg-6TzznyAWtEnyu6xs .cluster-label span p{background-color:transparent;}#mermaid-svg-6TzznyAWtEnyu6xs .label text,#mermaid-svg-6TzznyAWtEnyu6xs span{fill:#333;color:#333;}#mermaid-svg-6TzznyAWtEnyu6xs .node rect,#mermaid-svg-6TzznyAWtEnyu6xs .node circle,#mermaid-svg-6TzznyAWtEnyu6xs .node ellipse,#mermaid-svg-6TzznyAWtEnyu6xs .node polygon,#mermaid-svg-6TzznyAWtEnyu6xs .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-6TzznyAWtEnyu6xs .rough-node .label text,#mermaid-svg-6TzznyAWtEnyu6xs .node .label text,#mermaid-svg-6TzznyAWtEnyu6xs .image-shape .label,#mermaid-svg-6TzznyAWtEnyu6xs .icon-shape .label{text-anchor:middle;}#mermaid-svg-6TzznyAWtEnyu6xs .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-6TzznyAWtEnyu6xs .rough-node .label,#mermaid-svg-6TzznyAWtEnyu6xs .node .label,#mermaid-svg-6TzznyAWtEnyu6xs .image-shape .label,#mermaid-svg-6TzznyAWtEnyu6xs .icon-shape .label{text-align:center;}#mermaid-svg-6TzznyAWtEnyu6xs .node.clickable{cursor:pointer;}#mermaid-svg-6TzznyAWtEnyu6xs .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-6TzznyAWtEnyu6xs .arrowheadPath{fill:#333333;}#mermaid-svg-6TzznyAWtEnyu6xs .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-6TzznyAWtEnyu6xs .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-6TzznyAWtEnyu6xs .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6TzznyAWtEnyu6xs .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-6TzznyAWtEnyu6xs .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6TzznyAWtEnyu6xs .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-6TzznyAWtEnyu6xs .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-6TzznyAWtEnyu6xs .cluster text{fill:#333;}#mermaid-svg-6TzznyAWtEnyu6xs .cluster span{color:#333;}#mermaid-svg-6TzznyAWtEnyu6xs div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-6TzznyAWtEnyu6xs .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-6TzznyAWtEnyu6xs rect.text{fill:none;stroke-width:0;}#mermaid-svg-6TzznyAWtEnyu6xs .icon-shape,#mermaid-svg-6TzznyAWtEnyu6xs .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6TzznyAWtEnyu6xs .icon-shape p,#mermaid-svg-6TzznyAWtEnyu6xs .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-6TzznyAWtEnyu6xs .icon-shape rect,#mermaid-svg-6TzznyAWtEnyu6xs .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6TzznyAWtEnyu6xs .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-6TzznyAWtEnyu6xs .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-6TzznyAWtEnyu6xs :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

深度网络

输入

隐藏层1

隐藏层2

隐藏层3

输出

浅层网络

输入

隐藏层

输出

层次化特征学习:

图像识别的层次化特征:
┌─────────────────────────────────────────┐
│ 第1层:边缘、线条 │
├─────────────────────────────────────────┤
│ 第2层:简单形状(圆、方、三角) │
├─────────────────────────────────────────┤
│ 第3层:复杂形状(眼睛、耳朵、轮子) │
├─────────────────────────────────────────┤
│ 第4层:物体部件 │
├─────────────────────────────────────────┤
│ 第5层:完整物体 │
└─────────────────────────────────────────┘

4.3 深度学习的三大支柱

#mermaid-svg-flQgS7aG53iupyoM{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-flQgS7aG53iupyoM .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-flQgS7aG53iupyoM .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-flQgS7aG53iupyoM .error-icon{fill:#552222;}#mermaid-svg-flQgS7aG53iupyoM .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-flQgS7aG53iupyoM .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-flQgS7aG53iupyoM .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-flQgS7aG53iupyoM .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-flQgS7aG53iupyoM .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-flQgS7aG53iupyoM .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-flQgS7aG53iupyoM .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-flQgS7aG53iupyoM .marker{fill:#333333;stroke:#333333;}#mermaid-svg-flQgS7aG53iupyoM .marker.cross{stroke:#333333;}#mermaid-svg-flQgS7aG53iupyoM svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-flQgS7aG53iupyoM p{margin:0;}#mermaid-svg-flQgS7aG53iupyoM .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-flQgS7aG53iupyoM .cluster-label text{fill:#333;}#mermaid-svg-flQgS7aG53iupyoM .cluster-label span{color:#333;}#mermaid-svg-flQgS7aG53iupyoM .cluster-label span p{background-color:transparent;}#mermaid-svg-flQgS7aG53iupyoM .label text,#mermaid-svg-flQgS7aG53iupyoM span{fill:#333;color:#333;}#mermaid-svg-flQgS7aG53iupyoM .node rect,#mermaid-svg-flQgS7aG53iupyoM .node circle,#mermaid-svg-flQgS7aG53iupyoM .node ellipse,#mermaid-svg-flQgS7aG53iupyoM .node polygon,#mermaid-svg-flQgS7aG53iupyoM .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-flQgS7aG53iupyoM .rough-node .label text,#mermaid-svg-flQgS7aG53iupyoM .node .label text,#mermaid-svg-flQgS7aG53iupyoM .image-shape .label,#mermaid-svg-flQgS7aG53iupyoM .icon-shape .label{text-anchor:middle;}#mermaid-svg-flQgS7aG53iupyoM .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-flQgS7aG53iupyoM .rough-node .label,#mermaid-svg-flQgS7aG53iupyoM .node .label,#mermaid-svg-flQgS7aG53iupyoM .image-shape .label,#mermaid-svg-flQgS7aG53iupyoM .icon-shape .label{text-align:center;}#mermaid-svg-flQgS7aG53iupyoM .node.clickable{cursor:pointer;}#mermaid-svg-flQgS7aG53iupyoM .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-flQgS7aG53iupyoM .arrowheadPath{fill:#333333;}#mermaid-svg-flQgS7aG53iupyoM .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-flQgS7aG53iupyoM .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-flQgS7aG53iupyoM .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-flQgS7aG53iupyoM .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-flQgS7aG53iupyoM .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-flQgS7aG53iupyoM .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-flQgS7aG53iupyoM .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-flQgS7aG53iupyoM .cluster text{fill:#333;}#mermaid-svg-flQgS7aG53iupyoM .cluster span{color:#333;}#mermaid-svg-flQgS7aG53iupyoM div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-flQgS7aG53iupyoM .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-flQgS7aG53iupyoM rect.text{fill:none;stroke-width:0;}#mermaid-svg-flQgS7aG53iupyoM .icon-shape,#mermaid-svg-flQgS7aG53iupyoM .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-flQgS7aG53iupyoM .icon-shape p,#mermaid-svg-flQgS7aG53iupyoM .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-flQgS7aG53iupyoM .icon-shape rect,#mermaid-svg-flQgS7aG53iupyoM .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-flQgS7aG53iupyoM .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-flQgS7aG53iupyoM .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-flQgS7aG53iupyoM :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

深度学习成功要素

大数据

算力

算法

ImageNet千万级标注数据

互联网数据海量文本/图像

GPU并行计算

TPU专用芯片

CNN架构

Transformer架构

优化算法Adam/SGD

4.4 深度学习训练流程

#mermaid-svg-5ijF8kYEbrcdnMbk{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-5ijF8kYEbrcdnMbk .error-icon{fill:#552222;}#mermaid-svg-5ijF8kYEbrcdnMbk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-5ijF8kYEbrcdnMbk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-5ijF8kYEbrcdnMbk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-5ijF8kYEbrcdnMbk .marker.cross{stroke:#333333;}#mermaid-svg-5ijF8kYEbrcdnMbk svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-5ijF8kYEbrcdnMbk p{margin:0;}#mermaid-svg-5ijF8kYEbrcdnMbk .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster-label text{fill:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster-label span{color:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster-label span p{background-color:transparent;}#mermaid-svg-5ijF8kYEbrcdnMbk .label text,#mermaid-svg-5ijF8kYEbrcdnMbk span{fill:#333;color:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk .node rect,#mermaid-svg-5ijF8kYEbrcdnMbk .node circle,#mermaid-svg-5ijF8kYEbrcdnMbk .node ellipse,#mermaid-svg-5ijF8kYEbrcdnMbk .node polygon,#mermaid-svg-5ijF8kYEbrcdnMbk .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-5ijF8kYEbrcdnMbk .rough-node .label text,#mermaid-svg-5ijF8kYEbrcdnMbk .node .label text,#mermaid-svg-5ijF8kYEbrcdnMbk .image-shape .label,#mermaid-svg-5ijF8kYEbrcdnMbk .icon-shape .label{text-anchor:middle;}#mermaid-svg-5ijF8kYEbrcdnMbk .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-5ijF8kYEbrcdnMbk .rough-node .label,#mermaid-svg-5ijF8kYEbrcdnMbk .node .label,#mermaid-svg-5ijF8kYEbrcdnMbk .image-shape .label,#mermaid-svg-5ijF8kYEbrcdnMbk .icon-shape .label{text-align:center;}#mermaid-svg-5ijF8kYEbrcdnMbk .node.clickable{cursor:pointer;}#mermaid-svg-5ijF8kYEbrcdnMbk .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-5ijF8kYEbrcdnMbk .arrowheadPath{fill:#333333;}#mermaid-svg-5ijF8kYEbrcdnMbk .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-5ijF8kYEbrcdnMbk .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-5ijF8kYEbrcdnMbk .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5ijF8kYEbrcdnMbk .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-5ijF8kYEbrcdnMbk .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5ijF8kYEbrcdnMbk .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster text{fill:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk .cluster span{color:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-5ijF8kYEbrcdnMbk .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-5ijF8kYEbrcdnMbk rect.text{fill:none;stroke-width:0;}#mermaid-svg-5ijF8kYEbrcdnMbk .icon-shape,#mermaid-svg-5ijF8kYEbrcdnMbk .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5ijF8kYEbrcdnMbk .icon-shape p,#mermaid-svg-5ijF8kYEbrcdnMbk .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-5ijF8kYEbrcdnMbk .icon-shape rect,#mermaid-svg-5ijF8kYEbrcdnMbk .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5ijF8kYEbrcdnMbk .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-5ijF8kYEbrcdnMbk .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-5ijF8kYEbrcdnMbk :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

准备数据

构建模型

定义损失函数

选择优化器

训练循环

前向传播

计算损失

反向传播

更新参数

收敛?

模型评估

部署应用

训练代码示例:

import torch
import torch.nn as nn
import torch.optim as optim

# 1. 准备数据
train_loader = get_data_loader()

# 2. 构建模型
model = MLP(input_size=784, hidden_size=256, output_size=10)

# 3. 定义损失函数和优化器
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

# 4. 训练循环
for epoch in range(100):
for batch_x, batch_y in train_loader:
# 前向传播
outputs = model(batch_x)

# 计算损失
loss = criterion(outputs, batch_y)

# 反向传播
optimizer.zero_grad()
loss.backward()

# 更新参数
optimizer.step()

print(f"Epoch {epoch}, Loss: {loss.item():.4f}")


五、CNN:图像处理的王者

5.1 CNN的核心思想

#mermaid-svg-CasQEUCgHra80M5u{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-CasQEUCgHra80M5u .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-CasQEUCgHra80M5u .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-CasQEUCgHra80M5u .error-icon{fill:#552222;}#mermaid-svg-CasQEUCgHra80M5u .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-CasQEUCgHra80M5u .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-CasQEUCgHra80M5u .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-CasQEUCgHra80M5u .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-CasQEUCgHra80M5u .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-CasQEUCgHra80M5u .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-CasQEUCgHra80M5u .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-CasQEUCgHra80M5u .marker{fill:#333333;stroke:#333333;}#mermaid-svg-CasQEUCgHra80M5u .marker.cross{stroke:#333333;}#mermaid-svg-CasQEUCgHra80M5u svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-CasQEUCgHra80M5u p{margin:0;}#mermaid-svg-CasQEUCgHra80M5u .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-CasQEUCgHra80M5u .cluster-label text{fill:#333;}#mermaid-svg-CasQEUCgHra80M5u .cluster-label span{color:#333;}#mermaid-svg-CasQEUCgHra80M5u .cluster-label span p{background-color:transparent;}#mermaid-svg-CasQEUCgHra80M5u .label text,#mermaid-svg-CasQEUCgHra80M5u span{fill:#333;color:#333;}#mermaid-svg-CasQEUCgHra80M5u .node rect,#mermaid-svg-CasQEUCgHra80M5u .node circle,#mermaid-svg-CasQEUCgHra80M5u .node ellipse,#mermaid-svg-CasQEUCgHra80M5u .node polygon,#mermaid-svg-CasQEUCgHra80M5u .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-CasQEUCgHra80M5u .rough-node .label text,#mermaid-svg-CasQEUCgHra80M5u .node .label text,#mermaid-svg-CasQEUCgHra80M5u .image-shape .label,#mermaid-svg-CasQEUCgHra80M5u .icon-shape .label{text-anchor:middle;}#mermaid-svg-CasQEUCgHra80M5u .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-CasQEUCgHra80M5u .rough-node .label,#mermaid-svg-CasQEUCgHra80M5u .node .label,#mermaid-svg-CasQEUCgHra80M5u .image-shape .label,#mermaid-svg-CasQEUCgHra80M5u .icon-shape .label{text-align:center;}#mermaid-svg-CasQEUCgHra80M5u .node.clickable{cursor:pointer;}#mermaid-svg-CasQEUCgHra80M5u .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-CasQEUCgHra80M5u .arrowheadPath{fill:#333333;}#mermaid-svg-CasQEUCgHra80M5u .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-CasQEUCgHra80M5u .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-CasQEUCgHra80M5u .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-CasQEUCgHra80M5u .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-CasQEUCgHra80M5u .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-CasQEUCgHra80M5u .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-CasQEUCgHra80M5u .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-CasQEUCgHra80M5u .cluster text{fill:#333;}#mermaid-svg-CasQEUCgHra80M5u .cluster span{color:#333;}#mermaid-svg-CasQEUCgHra80M5u div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-CasQEUCgHra80M5u .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-CasQEUCgHra80M5u rect.text{fill:none;stroke-width:0;}#mermaid-svg-CasQEUCgHra80M5u .icon-shape,#mermaid-svg-CasQEUCgHra80M5u .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-CasQEUCgHra80M5u .icon-shape p,#mermaid-svg-CasQEUCgHra80M5u .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-CasQEUCgHra80M5u .icon-shape rect,#mermaid-svg-CasQEUCgHra80M5u .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-CasQEUCgHra80M5u .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-CasQEUCgHra80M5u .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-CasQEUCgHra80M5u :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

CNN核心思想

局部感受野

权重共享

池化降维

只关注局部区域模拟人眼视觉

同一卷积核扫描全图减少参数量

保留重要特征减少计算量

5.2 CNN架构详解

#mermaid-svg-jw2GGdWy7enDlRPO{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-jw2GGdWy7enDlRPO .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-jw2GGdWy7enDlRPO .error-icon{fill:#552222;}#mermaid-svg-jw2GGdWy7enDlRPO .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-jw2GGdWy7enDlRPO .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-jw2GGdWy7enDlRPO .marker{fill:#333333;stroke:#333333;}#mermaid-svg-jw2GGdWy7enDlRPO .marker.cross{stroke:#333333;}#mermaid-svg-jw2GGdWy7enDlRPO svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-jw2GGdWy7enDlRPO p{margin:0;}#mermaid-svg-jw2GGdWy7enDlRPO .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-jw2GGdWy7enDlRPO .cluster-label text{fill:#333;}#mermaid-svg-jw2GGdWy7enDlRPO .cluster-label span{color:#333;}#mermaid-svg-jw2GGdWy7enDlRPO .cluster-label span p{background-color:transparent;}#mermaid-svg-jw2GGdWy7enDlRPO .label text,#mermaid-svg-jw2GGdWy7enDlRPO span{fill:#333;color:#333;}#mermaid-svg-jw2GGdWy7enDlRPO .node rect,#mermaid-svg-jw2GGdWy7enDlRPO .node circle,#mermaid-svg-jw2GGdWy7enDlRPO .node ellipse,#mermaid-svg-jw2GGdWy7enDlRPO .node polygon,#mermaid-svg-jw2GGdWy7enDlRPO .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-jw2GGdWy7enDlRPO .rough-node .label text,#mermaid-svg-jw2GGdWy7enDlRPO .node .label text,#mermaid-svg-jw2GGdWy7enDlRPO .image-shape .label,#mermaid-svg-jw2GGdWy7enDlRPO .icon-shape .label{text-anchor:middle;}#mermaid-svg-jw2GGdWy7enDlRPO .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-jw2GGdWy7enDlRPO .rough-node .label,#mermaid-svg-jw2GGdWy7enDlRPO .node .label,#mermaid-svg-jw2GGdWy7enDlRPO .image-shape .label,#mermaid-svg-jw2GGdWy7enDlRPO .icon-shape .label{text-align:center;}#mermaid-svg-jw2GGdWy7enDlRPO .node.clickable{cursor:pointer;}#mermaid-svg-jw2GGdWy7enDlRPO .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-jw2GGdWy7enDlRPO .arrowheadPath{fill:#333333;}#mermaid-svg-jw2GGdWy7enDlRPO .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-jw2GGdWy7enDlRPO .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-jw2GGdWy7enDlRPO .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jw2GGdWy7enDlRPO .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-jw2GGdWy7enDlRPO .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jw2GGdWy7enDlRPO .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-jw2GGdWy7enDlRPO .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-jw2GGdWy7enDlRPO .cluster text{fill:#333;}#mermaid-svg-jw2GGdWy7enDlRPO .cluster span{color:#333;}#mermaid-svg-jw2GGdWy7enDlRPO div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-jw2GGdWy7enDlRPO .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-jw2GGdWy7enDlRPO rect.text{fill:none;stroke-width:0;}#mermaid-svg-jw2GGdWy7enDlRPO .icon-shape,#mermaid-svg-jw2GGdWy7enDlRPO .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jw2GGdWy7enDlRPO .icon-shape p,#mermaid-svg-jw2GGdWy7enDlRPO .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-jw2GGdWy7enDlRPO .icon-shape rect,#mermaid-svg-jw2GGdWy7enDlRPO .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jw2GGdWy7enDlRPO .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-jw2GGdWy7enDlRPO .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-jw2GGdWy7enDlRPO :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

输出

全连接层

池化层

卷积层

输入

图像224×224×3

Conv1提取边缘

Conv2提取形状

Conv3提取纹理

MaxPool降维

MaxPool降维

FC1

FC2

分类结果

5.3 卷积操作详解

#mermaid-svg-mLGc4Iq1vu6xegFX{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-mLGc4Iq1vu6xegFX .error-icon{fill:#552222;}#mermaid-svg-mLGc4Iq1vu6xegFX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-mLGc4Iq1vu6xegFX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-mLGc4Iq1vu6xegFX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-mLGc4Iq1vu6xegFX .marker.cross{stroke:#333333;}#mermaid-svg-mLGc4Iq1vu6xegFX svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-mLGc4Iq1vu6xegFX p{margin:0;}#mermaid-svg-mLGc4Iq1vu6xegFX .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster-label text{fill:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster-label span{color:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster-label span p{background-color:transparent;}#mermaid-svg-mLGc4Iq1vu6xegFX .label text,#mermaid-svg-mLGc4Iq1vu6xegFX span{fill:#333;color:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX .node rect,#mermaid-svg-mLGc4Iq1vu6xegFX .node circle,#mermaid-svg-mLGc4Iq1vu6xegFX .node ellipse,#mermaid-svg-mLGc4Iq1vu6xegFX .node polygon,#mermaid-svg-mLGc4Iq1vu6xegFX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-mLGc4Iq1vu6xegFX .rough-node .label text,#mermaid-svg-mLGc4Iq1vu6xegFX .node .label text,#mermaid-svg-mLGc4Iq1vu6xegFX .image-shape .label,#mermaid-svg-mLGc4Iq1vu6xegFX .icon-shape .label{text-anchor:middle;}#mermaid-svg-mLGc4Iq1vu6xegFX .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-mLGc4Iq1vu6xegFX .rough-node .label,#mermaid-svg-mLGc4Iq1vu6xegFX .node .label,#mermaid-svg-mLGc4Iq1vu6xegFX .image-shape .label,#mermaid-svg-mLGc4Iq1vu6xegFX .icon-shape .label{text-align:center;}#mermaid-svg-mLGc4Iq1vu6xegFX .node.clickable{cursor:pointer;}#mermaid-svg-mLGc4Iq1vu6xegFX .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-mLGc4Iq1vu6xegFX .arrowheadPath{fill:#333333;}#mermaid-svg-mLGc4Iq1vu6xegFX .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-mLGc4Iq1vu6xegFX .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-mLGc4Iq1vu6xegFX .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-mLGc4Iq1vu6xegFX .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-mLGc4Iq1vu6xegFX .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-mLGc4Iq1vu6xegFX .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster text{fill:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX .cluster span{color:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-mLGc4Iq1vu6xegFX .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-mLGc4Iq1vu6xegFX rect.text{fill:none;stroke-width:0;}#mermaid-svg-mLGc4Iq1vu6xegFX .icon-shape,#mermaid-svg-mLGc4Iq1vu6xegFX .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-mLGc4Iq1vu6xegFX .icon-shape p,#mermaid-svg-mLGc4Iq1vu6xegFX .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-mLGc4Iq1vu6xegFX .icon-shape rect,#mermaid-svg-mLGc4Iq1vu6xegFX .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-mLGc4Iq1vu6xegFX .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-mLGc4Iq1vu6xegFX .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-mLGc4Iq1vu6xegFX :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

计算过程

卷积核在图像上滑动逐元素相乘后求和

卷积操作

输入图像5×5

卷积核3×3

特征图3×3

卷积计算示例:

输入图像(5×5): 卷积核(3×3):
┌───┬───┬───┬───┬───┐ ┌───┬───┬───┐
│ 1 │ 2 │ 3 │ 4 │ 5 │ │ 1 │ 0 │-1 │
├───┼───┼───┼───┼───┤ ├───┼───┼───┤
│ 6 │ 7 │ 8 │ 9 │10 │ │ 1 │ 0 │-1 │
├───┼───┼───┼───┼───┤ ├───┼───┼───┤
│11 │12 │13 │14 │15 │ │ 1 │ 0 │-1 │
├───┼───┼───┼───┼───┤ └───┴───┴───┘
│16 │17 │18 │19 │20 │
├───┼───┼───┼───┼───┤
│21 │22 │23 │24 │25 │
└───┴───┴───┴───┴───┘

第一个位置的卷积结果:
1×1 + 2×0 + 3×(-1) +
6×1 + 7×0 + 8×(-1) +
11×1 + 12×0 + 13×(-1)
= 1 – 3 + 6 – 8 + 11 – 13 = -6

5.4 池化操作详解

#mermaid-svg-8IeiIJPfqrYJSygY{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-8IeiIJPfqrYJSygY .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-8IeiIJPfqrYJSygY .error-icon{fill:#552222;}#mermaid-svg-8IeiIJPfqrYJSygY .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-8IeiIJPfqrYJSygY .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-8IeiIJPfqrYJSygY .marker{fill:#333333;stroke:#333333;}#mermaid-svg-8IeiIJPfqrYJSygY .marker.cross{stroke:#333333;}#mermaid-svg-8IeiIJPfqrYJSygY svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-8IeiIJPfqrYJSygY p{margin:0;}#mermaid-svg-8IeiIJPfqrYJSygY .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-8IeiIJPfqrYJSygY .cluster-label text{fill:#333;}#mermaid-svg-8IeiIJPfqrYJSygY .cluster-label span{color:#333;}#mermaid-svg-8IeiIJPfqrYJSygY .cluster-label span p{background-color:transparent;}#mermaid-svg-8IeiIJPfqrYJSygY .label text,#mermaid-svg-8IeiIJPfqrYJSygY span{fill:#333;color:#333;}#mermaid-svg-8IeiIJPfqrYJSygY .node rect,#mermaid-svg-8IeiIJPfqrYJSygY .node circle,#mermaid-svg-8IeiIJPfqrYJSygY .node ellipse,#mermaid-svg-8IeiIJPfqrYJSygY .node polygon,#mermaid-svg-8IeiIJPfqrYJSygY .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-8IeiIJPfqrYJSygY .rough-node .label text,#mermaid-svg-8IeiIJPfqrYJSygY .node .label text,#mermaid-svg-8IeiIJPfqrYJSygY .image-shape .label,#mermaid-svg-8IeiIJPfqrYJSygY .icon-shape .label{text-anchor:middle;}#mermaid-svg-8IeiIJPfqrYJSygY .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-8IeiIJPfqrYJSygY .rough-node .label,#mermaid-svg-8IeiIJPfqrYJSygY .node .label,#mermaid-svg-8IeiIJPfqrYJSygY .image-shape .label,#mermaid-svg-8IeiIJPfqrYJSygY .icon-shape .label{text-align:center;}#mermaid-svg-8IeiIJPfqrYJSygY .node.clickable{cursor:pointer;}#mermaid-svg-8IeiIJPfqrYJSygY .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-8IeiIJPfqrYJSygY .arrowheadPath{fill:#333333;}#mermaid-svg-8IeiIJPfqrYJSygY .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-8IeiIJPfqrYJSygY .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-8IeiIJPfqrYJSygY .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-8IeiIJPfqrYJSygY .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-8IeiIJPfqrYJSygY .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-8IeiIJPfqrYJSygY .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-8IeiIJPfqrYJSygY .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-8IeiIJPfqrYJSygY .cluster text{fill:#333;}#mermaid-svg-8IeiIJPfqrYJSygY .cluster span{color:#333;}#mermaid-svg-8IeiIJPfqrYJSygY div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-8IeiIJPfqrYJSygY .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-8IeiIJPfqrYJSygY rect.text{fill:none;stroke-width:0;}#mermaid-svg-8IeiIJPfqrYJSygY .icon-shape,#mermaid-svg-8IeiIJPfqrYJSygY .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-8IeiIJPfqrYJSygY .icon-shape p,#mermaid-svg-8IeiIJPfqrYJSygY .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-8IeiIJPfqrYJSygY .icon-shape rect,#mermaid-svg-8IeiIJPfqrYJSygY .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-8IeiIJPfqrYJSygY .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-8IeiIJPfqrYJSygY .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-8IeiIJPfqrYJSygY :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

示例

┌───┬───┬───┬───┐│ 1 │ 3 │ 2 │ 4 │├───┼───┼───┼───┤│ 5 │ 6 │ 7 │ 8 │├───┼───┼───┼───┤│ 9 │10 │11 │12 │├───┼───┼───┼───┤│13 │14 │15 │16 │└───┴───┴───┴───┘

┌───┬───┐│ 6 │ 8 │├───┼───┤│14 │16 │└───┴───┘

最大池化

输入4×4

2×2窗口步长2

输出2×2

5.5 CNN代码实现

import torch
import torch.nn as nn

class SimpleCNN(nn.Module):
"""
简单的CNN网络

结构:
Conv -> ReLU -> Pool -> Conv -> ReLU -> Pool -> FC
"""
def __init__(self, num_classes=10):
super(SimpleCNN, self).__init__()

# 卷积层1
self.conv1 = nn.Conv2d(
in_channels=3, # 输入通道数(RGB图像)
out_channels=32, # 输出通道数(卷积核数量)
kernel_size=3, # 卷积核大小
stride=1, # 步长
padding=1 # 填充
)
self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)

# 卷积层2
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)

# 全连接层
self.fc1 = nn.Linear(64 * 56 * 56, 512) # 假设输入图像为224×224
self.fc2 = nn.Linear(512, num_classes)

self.relu = nn.ReLU()
self.dropout = nn.Dropout(0.5)

def forward(self, x):
# 卷积块1
x = self.conv1(x)
x = self.relu(x)
x = self.pool1(x)

# 卷积块2
x = self.conv2(x)
x = self.relu(x)
x = self.pool2(x)

# 展平
x = x.view(x.size(0), 1)

# 全连接层
x = self.fc1(x)
x = self.relu(x)
x = self.dropout(x)
x = self.fc2(x)

return x

# 使用示例
model = SimpleCNN(num_classes=10)
x = torch.randn(32, 3, 224, 224) # batch=32, channels=3, height=224, width=224
output = model(x)
print(output.shape) # torch.Size([32, 10])

5.6 经典CNN架构演进

#mermaid-svg-kH38DO1m7EWo35ms{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-kH38DO1m7EWo35ms .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-kH38DO1m7EWo35ms .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-kH38DO1m7EWo35ms .error-icon{fill:#552222;}#mermaid-svg-kH38DO1m7EWo35ms .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-kH38DO1m7EWo35ms .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-kH38DO1m7EWo35ms .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-kH38DO1m7EWo35ms .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-kH38DO1m7EWo35ms .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-kH38DO1m7EWo35ms .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-kH38DO1m7EWo35ms .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-kH38DO1m7EWo35ms .marker{fill:#333333;stroke:#333333;}#mermaid-svg-kH38DO1m7EWo35ms .marker.cross{stroke:#333333;}#mermaid-svg-kH38DO1m7EWo35ms svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-kH38DO1m7EWo35ms p{margin:0;}#mermaid-svg-kH38DO1m7EWo35ms .edge{stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .section–1 rect,#mermaid-svg-kH38DO1m7EWo35ms .section–1 path,#mermaid-svg-kH38DO1m7EWo35ms .section–1 circle,#mermaid-svg-kH38DO1m7EWo35ms .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section–1 text{fill:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth–1{stroke-width:17;}#mermaid-svg-kH38DO1m7EWo35ms .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-0 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-0 path,#mermaid-svg-kH38DO1m7EWo35ms .section-0 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-kH38DO1m7EWo35ms .section-0 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-0{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-0{stroke-width:14;}#mermaid-svg-kH38DO1m7EWo35ms .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-1 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-1 path,#mermaid-svg-kH38DO1m7EWo35ms .section-1 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-1 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-1{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-1{stroke-width:11;}#mermaid-svg-kH38DO1m7EWo35ms .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-2 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-2 path,#mermaid-svg-kH38DO1m7EWo35ms .section-2 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-2 text{fill:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-2{stroke-width:8;}#mermaid-svg-kH38DO1m7EWo35ms .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-3 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-3 path,#mermaid-svg-kH38DO1m7EWo35ms .section-3 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-3 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-3{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-3{stroke-width:5;}#mermaid-svg-kH38DO1m7EWo35ms .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-4 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-4 path,#mermaid-svg-kH38DO1m7EWo35ms .section-4 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-4 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-4{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-4{stroke-width:2;}#mermaid-svg-kH38DO1m7EWo35ms .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-5 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-5 path,#mermaid-svg-kH38DO1m7EWo35ms .section-5 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-5 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-5{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-5{stroke-width:-1;}#mermaid-svg-kH38DO1m7EWo35ms .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-6 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-6 path,#mermaid-svg-kH38DO1m7EWo35ms .section-6 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-6 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-6{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-6{stroke-width:-4;}#mermaid-svg-kH38DO1m7EWo35ms .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-7 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-7 path,#mermaid-svg-kH38DO1m7EWo35ms .section-7 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-7 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-7{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-7{stroke-width:-7;}#mermaid-svg-kH38DO1m7EWo35ms .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-8 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-8 path,#mermaid-svg-kH38DO1m7EWo35ms .section-8 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-8 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-8{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-8{stroke-width:-10;}#mermaid-svg-kH38DO1m7EWo35ms .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-9 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-9 path,#mermaid-svg-kH38DO1m7EWo35ms .section-9 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-9 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-9{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-9{stroke-width:-13;}#mermaid-svg-kH38DO1m7EWo35ms .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-10 rect,#mermaid-svg-kH38DO1m7EWo35ms .section-10 path,#mermaid-svg-kH38DO1m7EWo35ms .section-10 circle,#mermaid-svg-kH38DO1m7EWo35ms .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-10 text{fill:black;}#mermaid-svg-kH38DO1m7EWo35ms .node-icon-10{font-size:40px;color:black;}#mermaid-svg-kH38DO1m7EWo35ms .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .edge-depth-10{stroke-width:-16;}#mermaid-svg-kH38DO1m7EWo35ms .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-kH38DO1m7EWo35ms .lineWrapper line{stroke:black;}#mermaid-svg-kH38DO1m7EWo35ms .disabled,#mermaid-svg-kH38DO1m7EWo35ms .disabled circle,#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:lightgray;}#mermaid-svg-kH38DO1m7EWo35ms .disabled text{fill:#efefef;}#mermaid-svg-kH38DO1m7EWo35ms .section-root rect,#mermaid-svg-kH38DO1m7EWo35ms .section-root path,#mermaid-svg-kH38DO1m7EWo35ms .section-root circle{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-kH38DO1m7EWo35ms .section-root text{fill:#ffffff;}#mermaid-svg-kH38DO1m7EWo35ms .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-kH38DO1m7EWo35ms .edge{fill:none;}#mermaid-svg-kH38DO1m7EWo35ms .eventWrapper{filter:brightness(120%);}#mermaid-svg-kH38DO1m7EWo35ms :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

1998

LeNet-5

手写数字识别

5层网络

2012

AlexNet

ImageNet冠军

8层网络,ReLU

2014

VGGNet

小卷积核堆叠

16-19层

2014

GoogLeNet

Inception模块

22层

2015

ResNet

残差连接

152层

2017

DenseNet

密集连接

特征复用

2020

EfficientNet

复合缩放

效率最优

CNN架构演进史


六、RNN与LSTM:序列数据的利器

6.1 为什么需要RNN?

#mermaid-svg-BL4lM8I4inYIx6aX{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-BL4lM8I4inYIx6aX .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-BL4lM8I4inYIx6aX .error-icon{fill:#552222;}#mermaid-svg-BL4lM8I4inYIx6aX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-BL4lM8I4inYIx6aX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-BL4lM8I4inYIx6aX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-BL4lM8I4inYIx6aX .marker.cross{stroke:#333333;}#mermaid-svg-BL4lM8I4inYIx6aX svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-BL4lM8I4inYIx6aX p{margin:0;}#mermaid-svg-BL4lM8I4inYIx6aX .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-BL4lM8I4inYIx6aX .cluster-label text{fill:#333;}#mermaid-svg-BL4lM8I4inYIx6aX .cluster-label span{color:#333;}#mermaid-svg-BL4lM8I4inYIx6aX .cluster-label span p{background-color:transparent;}#mermaid-svg-BL4lM8I4inYIx6aX .label text,#mermaid-svg-BL4lM8I4inYIx6aX span{fill:#333;color:#333;}#mermaid-svg-BL4lM8I4inYIx6aX .node rect,#mermaid-svg-BL4lM8I4inYIx6aX .node circle,#mermaid-svg-BL4lM8I4inYIx6aX .node ellipse,#mermaid-svg-BL4lM8I4inYIx6aX .node polygon,#mermaid-svg-BL4lM8I4inYIx6aX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-BL4lM8I4inYIx6aX .rough-node .label text,#mermaid-svg-BL4lM8I4inYIx6aX .node .label text,#mermaid-svg-BL4lM8I4inYIx6aX .image-shape .label,#mermaid-svg-BL4lM8I4inYIx6aX .icon-shape .label{text-anchor:middle;}#mermaid-svg-BL4lM8I4inYIx6aX .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-BL4lM8I4inYIx6aX .rough-node .label,#mermaid-svg-BL4lM8I4inYIx6aX .node .label,#mermaid-svg-BL4lM8I4inYIx6aX .image-shape .label,#mermaid-svg-BL4lM8I4inYIx6aX .icon-shape .label{text-align:center;}#mermaid-svg-BL4lM8I4inYIx6aX .node.clickable{cursor:pointer;}#mermaid-svg-BL4lM8I4inYIx6aX .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-BL4lM8I4inYIx6aX .arrowheadPath{fill:#333333;}#mermaid-svg-BL4lM8I4inYIx6aX .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-BL4lM8I4inYIx6aX .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-BL4lM8I4inYIx6aX .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-BL4lM8I4inYIx6aX .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-BL4lM8I4inYIx6aX .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-BL4lM8I4inYIx6aX .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-BL4lM8I4inYIx6aX .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-BL4lM8I4inYIx6aX .cluster text{fill:#333;}#mermaid-svg-BL4lM8I4inYIx6aX .cluster span{color:#333;}#mermaid-svg-BL4lM8I4inYIx6aX div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-BL4lM8I4inYIx6aX .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-BL4lM8I4inYIx6aX rect.text{fill:none;stroke-width:0;}#mermaid-svg-BL4lM8I4inYIx6aX .icon-shape,#mermaid-svg-BL4lM8I4inYIx6aX .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-BL4lM8I4inYIx6aX .icon-shape p,#mermaid-svg-BL4lM8I4inYIx6aX .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-BL4lM8I4inYIx6aX .icon-shape rect,#mermaid-svg-BL4lM8I4inYIx6aX .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-BL4lM8I4inYIx6aX .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-BL4lM8I4inYIx6aX .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-BL4lM8I4inYIx6aX :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

传统神经网络的问题

输入固定长度

无法处理序列

忽略时序信息

RNN的优势

处理变长序列

记忆历史信息

捕捉时序依赖

RNN的典型应用:

应用场景输入输出
机器翻译 源语言句子 目标语言句子
语音识别 音频序列 文字序列
文本生成 前文 后续文字
股票预测 历史价格 未来价格

6.2 RNN架构详解

#mermaid-svg-lMWIqci51ytja9Ai{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-lMWIqci51ytja9Ai .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-lMWIqci51ytja9Ai .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-lMWIqci51ytja9Ai .error-icon{fill:#552222;}#mermaid-svg-lMWIqci51ytja9Ai .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-lMWIqci51ytja9Ai .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-lMWIqci51ytja9Ai .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-lMWIqci51ytja9Ai .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-lMWIqci51ytja9Ai .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-lMWIqci51ytja9Ai .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-lMWIqci51ytja9Ai .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-lMWIqci51ytja9Ai .marker{fill:#333333;stroke:#333333;}#mermaid-svg-lMWIqci51ytja9Ai .marker.cross{stroke:#333333;}#mermaid-svg-lMWIqci51ytja9Ai svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-lMWIqci51ytja9Ai p{margin:0;}#mermaid-svg-lMWIqci51ytja9Ai .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-lMWIqci51ytja9Ai .cluster-label text{fill:#333;}#mermaid-svg-lMWIqci51ytja9Ai .cluster-label span{color:#333;}#mermaid-svg-lMWIqci51ytja9Ai .cluster-label span p{background-color:transparent;}#mermaid-svg-lMWIqci51ytja9Ai .label text,#mermaid-svg-lMWIqci51ytja9Ai span{fill:#333;color:#333;}#mermaid-svg-lMWIqci51ytja9Ai .node rect,#mermaid-svg-lMWIqci51ytja9Ai .node circle,#mermaid-svg-lMWIqci51ytja9Ai .node ellipse,#mermaid-svg-lMWIqci51ytja9Ai .node polygon,#mermaid-svg-lMWIqci51ytja9Ai .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-lMWIqci51ytja9Ai .rough-node .label text,#mermaid-svg-lMWIqci51ytja9Ai .node .label text,#mermaid-svg-lMWIqci51ytja9Ai .image-shape .label,#mermaid-svg-lMWIqci51ytja9Ai .icon-shape .label{text-anchor:middle;}#mermaid-svg-lMWIqci51ytja9Ai .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-lMWIqci51ytja9Ai .rough-node .label,#mermaid-svg-lMWIqci51ytja9Ai .node .label,#mermaid-svg-lMWIqci51ytja9Ai .image-shape .label,#mermaid-svg-lMWIqci51ytja9Ai .icon-shape .label{text-align:center;}#mermaid-svg-lMWIqci51ytja9Ai .node.clickable{cursor:pointer;}#mermaid-svg-lMWIqci51ytja9Ai .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-lMWIqci51ytja9Ai .arrowheadPath{fill:#333333;}#mermaid-svg-lMWIqci51ytja9Ai .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-lMWIqci51ytja9Ai .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-lMWIqci51ytja9Ai .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-lMWIqci51ytja9Ai .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-lMWIqci51ytja9Ai .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-lMWIqci51ytja9Ai .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-lMWIqci51ytja9Ai .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-lMWIqci51ytja9Ai .cluster text{fill:#333;}#mermaid-svg-lMWIqci51ytja9Ai .cluster span{color:#333;}#mermaid-svg-lMWIqci51ytja9Ai div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-lMWIqci51ytja9Ai .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-lMWIqci51ytja9Ai rect.text{fill:none;stroke-width:0;}#mermaid-svg-lMWIqci51ytja9Ai .icon-shape,#mermaid-svg-lMWIqci51ytja9Ai .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-lMWIqci51ytja9Ai .icon-shape p,#mermaid-svg-lMWIqci51ytja9Ai .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-lMWIqci51ytja9Ai .icon-shape rect,#mermaid-svg-lMWIqci51ytja9Ai .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-lMWIqci51ytja9Ai .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-lMWIqci51ytja9Ai .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-lMWIqci51ytja9Ai :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

展开形式

x1

h1

x2

h2

x3

h3

y1

y2

y3

RNN核心公式:

ht = tanh(Wxh × xt + Whh × ht-1 + bh)
yt = Why × ht + by

其中:
– xt: t时刻的输入
– ht: t时刻的隐藏状态(记忆)
– yt: t时刻的输出
– W: 权重矩阵

6.3 RNN的问题:梯度消失

#mermaid-svg-WobB604hXdC7jBH6{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-WobB604hXdC7jBH6 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-WobB604hXdC7jBH6 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-WobB604hXdC7jBH6 .error-icon{fill:#552222;}#mermaid-svg-WobB604hXdC7jBH6 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-WobB604hXdC7jBH6 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-WobB604hXdC7jBH6 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-WobB604hXdC7jBH6 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-WobB604hXdC7jBH6 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-WobB604hXdC7jBH6 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-WobB604hXdC7jBH6 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-WobB604hXdC7jBH6 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-WobB604hXdC7jBH6 .marker.cross{stroke:#333333;}#mermaid-svg-WobB604hXdC7jBH6 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-WobB604hXdC7jBH6 p{margin:0;}#mermaid-svg-WobB604hXdC7jBH6 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-WobB604hXdC7jBH6 .cluster-label text{fill:#333;}#mermaid-svg-WobB604hXdC7jBH6 .cluster-label span{color:#333;}#mermaid-svg-WobB604hXdC7jBH6 .cluster-label span p{background-color:transparent;}#mermaid-svg-WobB604hXdC7jBH6 .label text,#mermaid-svg-WobB604hXdC7jBH6 span{fill:#333;color:#333;}#mermaid-svg-WobB604hXdC7jBH6 .node rect,#mermaid-svg-WobB604hXdC7jBH6 .node circle,#mermaid-svg-WobB604hXdC7jBH6 .node ellipse,#mermaid-svg-WobB604hXdC7jBH6 .node polygon,#mermaid-svg-WobB604hXdC7jBH6 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-WobB604hXdC7jBH6 .rough-node .label text,#mermaid-svg-WobB604hXdC7jBH6 .node .label text,#mermaid-svg-WobB604hXdC7jBH6 .image-shape .label,#mermaid-svg-WobB604hXdC7jBH6 .icon-shape .label{text-anchor:middle;}#mermaid-svg-WobB604hXdC7jBH6 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-WobB604hXdC7jBH6 .rough-node .label,#mermaid-svg-WobB604hXdC7jBH6 .node .label,#mermaid-svg-WobB604hXdC7jBH6 .image-shape .label,#mermaid-svg-WobB604hXdC7jBH6 .icon-shape .label{text-align:center;}#mermaid-svg-WobB604hXdC7jBH6 .node.clickable{cursor:pointer;}#mermaid-svg-WobB604hXdC7jBH6 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-WobB604hXdC7jBH6 .arrowheadPath{fill:#333333;}#mermaid-svg-WobB604hXdC7jBH6 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-WobB604hXdC7jBH6 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-WobB604hXdC7jBH6 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-WobB604hXdC7jBH6 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-WobB604hXdC7jBH6 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-WobB604hXdC7jBH6 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-WobB604hXdC7jBH6 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-WobB604hXdC7jBH6 .cluster text{fill:#333;}#mermaid-svg-WobB604hXdC7jBH6 .cluster span{color:#333;}#mermaid-svg-WobB604hXdC7jBH6 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-WobB604hXdC7jBH6 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-WobB604hXdC7jBH6 rect.text{fill:none;stroke-width:0;}#mermaid-svg-WobB604hXdC7jBH6 .icon-shape,#mermaid-svg-WobB604hXdC7jBH6 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-WobB604hXdC7jBH6 .icon-shape p,#mermaid-svg-WobB604hXdC7jBH6 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-WobB604hXdC7jBH6 .icon-shape rect,#mermaid-svg-WobB604hXdC7jBH6 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-WobB604hXdC7jBH6 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-WobB604hXdC7jBH6 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-WobB604hXdC7jBH6 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

小于1

大于1

梯度反向传播

链式法则

连续相乘

梯度大小

梯度消失长距离依赖丢失

梯度爆炸参数更新过大

6.4 LSTM:解决长距离依赖

#mermaid-svg-C8YCK1vRT7RFkENB{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-C8YCK1vRT7RFkENB .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-C8YCK1vRT7RFkENB .error-icon{fill:#552222;}#mermaid-svg-C8YCK1vRT7RFkENB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-C8YCK1vRT7RFkENB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-C8YCK1vRT7RFkENB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-C8YCK1vRT7RFkENB .marker.cross{stroke:#333333;}#mermaid-svg-C8YCK1vRT7RFkENB svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-C8YCK1vRT7RFkENB p{margin:0;}#mermaid-svg-C8YCK1vRT7RFkENB .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-C8YCK1vRT7RFkENB .cluster-label text{fill:#333;}#mermaid-svg-C8YCK1vRT7RFkENB .cluster-label span{color:#333;}#mermaid-svg-C8YCK1vRT7RFkENB .cluster-label span p{background-color:transparent;}#mermaid-svg-C8YCK1vRT7RFkENB .label text,#mermaid-svg-C8YCK1vRT7RFkENB span{fill:#333;color:#333;}#mermaid-svg-C8YCK1vRT7RFkENB .node rect,#mermaid-svg-C8YCK1vRT7RFkENB .node circle,#mermaid-svg-C8YCK1vRT7RFkENB .node ellipse,#mermaid-svg-C8YCK1vRT7RFkENB .node polygon,#mermaid-svg-C8YCK1vRT7RFkENB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-C8YCK1vRT7RFkENB .rough-node .label text,#mermaid-svg-C8YCK1vRT7RFkENB .node .label text,#mermaid-svg-C8YCK1vRT7RFkENB .image-shape .label,#mermaid-svg-C8YCK1vRT7RFkENB .icon-shape .label{text-anchor:middle;}#mermaid-svg-C8YCK1vRT7RFkENB .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-C8YCK1vRT7RFkENB .rough-node .label,#mermaid-svg-C8YCK1vRT7RFkENB .node .label,#mermaid-svg-C8YCK1vRT7RFkENB .image-shape .label,#mermaid-svg-C8YCK1vRT7RFkENB .icon-shape .label{text-align:center;}#mermaid-svg-C8YCK1vRT7RFkENB .node.clickable{cursor:pointer;}#mermaid-svg-C8YCK1vRT7RFkENB .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-C8YCK1vRT7RFkENB .arrowheadPath{fill:#333333;}#mermaid-svg-C8YCK1vRT7RFkENB .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-C8YCK1vRT7RFkENB .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-C8YCK1vRT7RFkENB .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-C8YCK1vRT7RFkENB .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-C8YCK1vRT7RFkENB .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-C8YCK1vRT7RFkENB .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-C8YCK1vRT7RFkENB .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-C8YCK1vRT7RFkENB .cluster text{fill:#333;}#mermaid-svg-C8YCK1vRT7RFkENB .cluster span{color:#333;}#mermaid-svg-C8YCK1vRT7RFkENB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-C8YCK1vRT7RFkENB .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-C8YCK1vRT7RFkENB rect.text{fill:none;stroke-width:0;}#mermaid-svg-C8YCK1vRT7RFkENB .icon-shape,#mermaid-svg-C8YCK1vRT7RFkENB .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-C8YCK1vRT7RFkENB .icon-shape p,#mermaid-svg-C8YCK1vRT7RFkENB .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-C8YCK1vRT7RFkENB .icon-shape rect,#mermaid-svg-C8YCK1vRT7RFkENB .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-C8YCK1vRT7RFkENB .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-C8YCK1vRT7RFkENB .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-C8YCK1vRT7RFkENB :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

信息流

上一时刻状态

LSTM单元

当前时刻状态

下一时刻

LSTM单元

输入门决定哪些信息存入细胞

遗忘门决定丢弃哪些信息

细胞状态长期记忆

输出门决定输出哪些信息

LSTM三大门控:

门控作用取值范围
遗忘门 决定丢弃哪些旧信息 0-1
输入门 决定存入哪些新信息 0-1
输出门 决定输出哪些信息 0-1

6.5 LSTM代码实现

import torch
import torch.nn as nn

class SimpleLSTM(nn.Module):
"""
LSTM网络

用于序列数据处理
"""
def __init__(
self,
input_size, # 输入特征维度
hidden_size, # 隐藏层维度
num_layers=2, # LSTM层数
num_classes=10 # 分类数
):
super(SimpleLSTM, self).__init__()

self.hidden_size = hidden_size
self.num_layers = num_layers

# LSTM层
self.lstm = nn.LSTM(
input_size=input_size,
hidden_size=hidden_size,
num_layers=num_layers,
batch_first=True,
dropout=0.5
)

# 全连接层
self.fc = nn.Linear(hidden_size, num_classes)

def forward(self, x):
# x shape: (batch_size, seq_len, input_size)

# 初始化隐藏状态
h0 = torch.zeros(
self.num_layers,
x.size(0),
self.hidden_size
).to(x.device)

c0 = torch.zeros(
self.num_layers,
x.size(0),
self.hidden_size
).to(x.device)

# LSTM前向传播
# out shape: (batch_size, seq_len, hidden_size)
out, (hn, cn) = self.lstm(x, (h0, c0))

# 取最后一个时间步的输出
out = out[:, 1, :]

# 分类
out = self.fc(out)

return out

# 使用示例
model = SimpleLSTM(input_size=128, hidden_size=256, num_classes=10)
x = torch.randn(32, 50, 128) # batch=32, seq_len=50, input_size=128
output = model(x)
print(output.shape) # torch.Size([32, 10])

6.6 RNN vs LSTM vs GRU

#mermaid-svg-F5XecwUJEB14qw5t{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-F5XecwUJEB14qw5t .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-F5XecwUJEB14qw5t .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-F5XecwUJEB14qw5t .error-icon{fill:#552222;}#mermaid-svg-F5XecwUJEB14qw5t .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-F5XecwUJEB14qw5t .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-F5XecwUJEB14qw5t .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-F5XecwUJEB14qw5t .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-F5XecwUJEB14qw5t .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-F5XecwUJEB14qw5t .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-F5XecwUJEB14qw5t .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-F5XecwUJEB14qw5t .marker{fill:#333333;stroke:#333333;}#mermaid-svg-F5XecwUJEB14qw5t .marker.cross{stroke:#333333;}#mermaid-svg-F5XecwUJEB14qw5t svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-F5XecwUJEB14qw5t p{margin:0;}#mermaid-svg-F5XecwUJEB14qw5t .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-F5XecwUJEB14qw5t .cluster-label text{fill:#333;}#mermaid-svg-F5XecwUJEB14qw5t .cluster-label span{color:#333;}#mermaid-svg-F5XecwUJEB14qw5t .cluster-label span p{background-color:transparent;}#mermaid-svg-F5XecwUJEB14qw5t .label text,#mermaid-svg-F5XecwUJEB14qw5t span{fill:#333;color:#333;}#mermaid-svg-F5XecwUJEB14qw5t .node rect,#mermaid-svg-F5XecwUJEB14qw5t .node circle,#mermaid-svg-F5XecwUJEB14qw5t .node ellipse,#mermaid-svg-F5XecwUJEB14qw5t .node polygon,#mermaid-svg-F5XecwUJEB14qw5t .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-F5XecwUJEB14qw5t .rough-node .label text,#mermaid-svg-F5XecwUJEB14qw5t .node .label text,#mermaid-svg-F5XecwUJEB14qw5t .image-shape .label,#mermaid-svg-F5XecwUJEB14qw5t .icon-shape .label{text-anchor:middle;}#mermaid-svg-F5XecwUJEB14qw5t .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-F5XecwUJEB14qw5t .rough-node .label,#mermaid-svg-F5XecwUJEB14qw5t .node .label,#mermaid-svg-F5XecwUJEB14qw5t .image-shape .label,#mermaid-svg-F5XecwUJEB14qw5t .icon-shape .label{text-align:center;}#mermaid-svg-F5XecwUJEB14qw5t .node.clickable{cursor:pointer;}#mermaid-svg-F5XecwUJEB14qw5t .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-F5XecwUJEB14qw5t .arrowheadPath{fill:#333333;}#mermaid-svg-F5XecwUJEB14qw5t .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-F5XecwUJEB14qw5t .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-F5XecwUJEB14qw5t .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-F5XecwUJEB14qw5t .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-F5XecwUJEB14qw5t .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-F5XecwUJEB14qw5t .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-F5XecwUJEB14qw5t .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-F5XecwUJEB14qw5t .cluster text{fill:#333;}#mermaid-svg-F5XecwUJEB14qw5t .cluster span{color:#333;}#mermaid-svg-F5XecwUJEB14qw5t div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-F5XecwUJEB14qw5t .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-F5XecwUJEB14qw5t rect.text{fill:none;stroke-width:0;}#mermaid-svg-F5XecwUJEB14qw5t .icon-shape,#mermaid-svg-F5XecwUJEB14qw5t .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-F5XecwUJEB14qw5t .icon-shape p,#mermaid-svg-F5XecwUJEB14qw5t .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-F5XecwUJEB14qw5t .icon-shape rect,#mermaid-svg-F5XecwUJEB14qw5t .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-F5XecwUJEB14qw5t .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-F5XecwUJEB14qw5t .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-F5XecwUJEB14qw5t :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

序列模型对比

RNN

LSTM

GRU

简单快速

长距离依赖差

长距离依赖好

参数多,计算慢

简化版LSTM

参数少,速度快

对比总结:

模型参数量训练速度长距离依赖适用场景
RNN 短序列
LSTM 长序列
GRU 长序列(效率优先)

七、Transformer:自然语言处理的革命

7.1 Transformer的诞生

#mermaid-svg-xv3K6SPJ5usfiHZk{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-xv3K6SPJ5usfiHZk .error-icon{fill:#552222;}#mermaid-svg-xv3K6SPJ5usfiHZk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-xv3K6SPJ5usfiHZk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-xv3K6SPJ5usfiHZk .marker.cross{stroke:#333333;}#mermaid-svg-xv3K6SPJ5usfiHZk svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-xv3K6SPJ5usfiHZk p{margin:0;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge{stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 text{fill:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth–1{stroke-width:17;}#mermaid-svg-xv3K6SPJ5usfiHZk .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-0{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-0{stroke-width:14;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-1{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-1{stroke-width:11;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 text{fill:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-2{stroke-width:8;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-3{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-3{stroke-width:5;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-4{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-4{stroke-width:2;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-5{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-5{stroke-width:-1;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-6{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-6{stroke-width:-4;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-7{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-7{stroke-width:-7;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-8{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-8{stroke-width:-10;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-9{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-9{stroke-width:-13;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 circle,#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 text{fill:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .node-icon-10{font-size:40px;color:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .edge-depth-10{stroke-width:-16;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-xv3K6SPJ5usfiHZk .lineWrapper line{stroke:black;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled circle,#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:lightgray;}#mermaid-svg-xv3K6SPJ5usfiHZk .disabled text{fill:#efefef;}#mermaid-svg-xv3K6SPJ5usfiHZk .section-root rect,#mermaid-svg-xv3K6SPJ5usfiHZk .section-root path,#mermaid-svg-xv3K6SPJ5usfiHZk .section-root circle{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-xv3K6SPJ5usfiHZk .section-root text{fill:#ffffff;}#mermaid-svg-xv3K6SPJ5usfiHZk .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-xv3K6SPJ5usfiHZk .edge{fill:none;}#mermaid-svg-xv3K6SPJ5usfiHZk .eventWrapper{filter:brightness(120%);}#mermaid-svg-xv3K6SPJ5usfiHZk :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

2014

Seq2Seq

编码器-解码器

2015

Attention机制

Bahdanau注意力

2017

Transformer

《Attention Is All

You Need》

2018

BERT

双向编码器

2018

GPT

单向解码器

2020

GPT-3

1750亿参数

2022

ChatGPT

RLHF对齐

2023

GPT-4

多模态

NLP架构演进

7.2 Transformer核心架构

#mermaid-svg-ijwoV7GN2nwyT2dV{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ijwoV7GN2nwyT2dV .error-icon{fill:#552222;}#mermaid-svg-ijwoV7GN2nwyT2dV .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ijwoV7GN2nwyT2dV .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ijwoV7GN2nwyT2dV .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ijwoV7GN2nwyT2dV .marker.cross{stroke:#333333;}#mermaid-svg-ijwoV7GN2nwyT2dV svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ijwoV7GN2nwyT2dV p{margin:0;}#mermaid-svg-ijwoV7GN2nwyT2dV .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster-label text{fill:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster-label span{color:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster-label span p{background-color:transparent;}#mermaid-svg-ijwoV7GN2nwyT2dV .label text,#mermaid-svg-ijwoV7GN2nwyT2dV span{fill:#333;color:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV .node rect,#mermaid-svg-ijwoV7GN2nwyT2dV .node circle,#mermaid-svg-ijwoV7GN2nwyT2dV .node ellipse,#mermaid-svg-ijwoV7GN2nwyT2dV .node polygon,#mermaid-svg-ijwoV7GN2nwyT2dV .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ijwoV7GN2nwyT2dV .rough-node .label text,#mermaid-svg-ijwoV7GN2nwyT2dV .node .label text,#mermaid-svg-ijwoV7GN2nwyT2dV .image-shape .label,#mermaid-svg-ijwoV7GN2nwyT2dV .icon-shape .label{text-anchor:middle;}#mermaid-svg-ijwoV7GN2nwyT2dV .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ijwoV7GN2nwyT2dV .rough-node .label,#mermaid-svg-ijwoV7GN2nwyT2dV .node .label,#mermaid-svg-ijwoV7GN2nwyT2dV .image-shape .label,#mermaid-svg-ijwoV7GN2nwyT2dV .icon-shape .label{text-align:center;}#mermaid-svg-ijwoV7GN2nwyT2dV .node.clickable{cursor:pointer;}#mermaid-svg-ijwoV7GN2nwyT2dV .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ijwoV7GN2nwyT2dV .arrowheadPath{fill:#333333;}#mermaid-svg-ijwoV7GN2nwyT2dV .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ijwoV7GN2nwyT2dV .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ijwoV7GN2nwyT2dV .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ijwoV7GN2nwyT2dV .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ijwoV7GN2nwyT2dV .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ijwoV7GN2nwyT2dV .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster text{fill:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV .cluster span{color:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ijwoV7GN2nwyT2dV .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ijwoV7GN2nwyT2dV rect.text{fill:none;stroke-width:0;}#mermaid-svg-ijwoV7GN2nwyT2dV .icon-shape,#mermaid-svg-ijwoV7GN2nwyT2dV .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ijwoV7GN2nwyT2dV .icon-shape p,#mermaid-svg-ijwoV7GN2nwyT2dV .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ijwoV7GN2nwyT2dV .icon-shape rect,#mermaid-svg-ijwoV7GN2nwyT2dV .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ijwoV7GN2nwyT2dV .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ijwoV7GN2nwyT2dV .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ijwoV7GN2nwyT2dV :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

解码器

编码器

输入嵌入

位置编码

多头注意力

前馈网络

输出嵌入

位置编码

掩码多头注意力

编码器-解码器注意力

前馈网络

输出

7.3 自注意力机制详解

#mermaid-svg-ANnBenGEZTc84M3S{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ANnBenGEZTc84M3S .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ANnBenGEZTc84M3S .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ANnBenGEZTc84M3S .error-icon{fill:#552222;}#mermaid-svg-ANnBenGEZTc84M3S .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ANnBenGEZTc84M3S .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ANnBenGEZTc84M3S .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ANnBenGEZTc84M3S .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ANnBenGEZTc84M3S .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ANnBenGEZTc84M3S .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ANnBenGEZTc84M3S .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ANnBenGEZTc84M3S .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ANnBenGEZTc84M3S .marker.cross{stroke:#333333;}#mermaid-svg-ANnBenGEZTc84M3S svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ANnBenGEZTc84M3S p{margin:0;}#mermaid-svg-ANnBenGEZTc84M3S .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-ANnBenGEZTc84M3S .cluster-label text{fill:#333;}#mermaid-svg-ANnBenGEZTc84M3S .cluster-label span{color:#333;}#mermaid-svg-ANnBenGEZTc84M3S .cluster-label span p{background-color:transparent;}#mermaid-svg-ANnBenGEZTc84M3S .label text,#mermaid-svg-ANnBenGEZTc84M3S span{fill:#333;color:#333;}#mermaid-svg-ANnBenGEZTc84M3S .node rect,#mermaid-svg-ANnBenGEZTc84M3S .node circle,#mermaid-svg-ANnBenGEZTc84M3S .node ellipse,#mermaid-svg-ANnBenGEZTc84M3S .node polygon,#mermaid-svg-ANnBenGEZTc84M3S .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ANnBenGEZTc84M3S .rough-node .label text,#mermaid-svg-ANnBenGEZTc84M3S .node .label text,#mermaid-svg-ANnBenGEZTc84M3S .image-shape .label,#mermaid-svg-ANnBenGEZTc84M3S .icon-shape .label{text-anchor:middle;}#mermaid-svg-ANnBenGEZTc84M3S .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ANnBenGEZTc84M3S .rough-node .label,#mermaid-svg-ANnBenGEZTc84M3S .node .label,#mermaid-svg-ANnBenGEZTc84M3S .image-shape .label,#mermaid-svg-ANnBenGEZTc84M3S .icon-shape .label{text-align:center;}#mermaid-svg-ANnBenGEZTc84M3S .node.clickable{cursor:pointer;}#mermaid-svg-ANnBenGEZTc84M3S .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ANnBenGEZTc84M3S .arrowheadPath{fill:#333333;}#mermaid-svg-ANnBenGEZTc84M3S .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ANnBenGEZTc84M3S .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ANnBenGEZTc84M3S .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ANnBenGEZTc84M3S .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ANnBenGEZTc84M3S .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ANnBenGEZTc84M3S .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ANnBenGEZTc84M3S .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ANnBenGEZTc84M3S .cluster text{fill:#333;}#mermaid-svg-ANnBenGEZTc84M3S .cluster span{color:#333;}#mermaid-svg-ANnBenGEZTc84M3S div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ANnBenGEZTc84M3S .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ANnBenGEZTc84M3S rect.text{fill:none;stroke-width:0;}#mermaid-svg-ANnBenGEZTc84M3S .icon-shape,#mermaid-svg-ANnBenGEZTc84M3S .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ANnBenGEZTc84M3S .icon-shape p,#mermaid-svg-ANnBenGEZTc84M3S .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ANnBenGEZTc84M3S .icon-shape rect,#mermaid-svg-ANnBenGEZTc84M3S .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ANnBenGEZTc84M3S .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ANnBenGEZTc84M3S .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ANnBenGEZTc84M3S :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

自注意力机制

Query Q

Key K

Value V

Q × K^T计算相似度

Softmax归一化

× V加权求和

输出

自注意力公式:

Attention(Q, K, V) = softmax(Q × K^T / √dk) × V

其中:
– Q: Query矩阵(查询)
– K: Key矩阵(键)
– V: Value矩阵(值)
– dk: Key的维度(用于缩放)

7.4 多头注意力

#mermaid-svg-t08scRjwLXQh4PDZ{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-t08scRjwLXQh4PDZ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-t08scRjwLXQh4PDZ .error-icon{fill:#552222;}#mermaid-svg-t08scRjwLXQh4PDZ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-t08scRjwLXQh4PDZ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-t08scRjwLXQh4PDZ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-t08scRjwLXQh4PDZ .marker.cross{stroke:#333333;}#mermaid-svg-t08scRjwLXQh4PDZ svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-t08scRjwLXQh4PDZ p{margin:0;}#mermaid-svg-t08scRjwLXQh4PDZ .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-t08scRjwLXQh4PDZ .cluster-label text{fill:#333;}#mermaid-svg-t08scRjwLXQh4PDZ .cluster-label span{color:#333;}#mermaid-svg-t08scRjwLXQh4PDZ .cluster-label span p{background-color:transparent;}#mermaid-svg-t08scRjwLXQh4PDZ .label text,#mermaid-svg-t08scRjwLXQh4PDZ span{fill:#333;color:#333;}#mermaid-svg-t08scRjwLXQh4PDZ .node rect,#mermaid-svg-t08scRjwLXQh4PDZ .node circle,#mermaid-svg-t08scRjwLXQh4PDZ .node ellipse,#mermaid-svg-t08scRjwLXQh4PDZ .node polygon,#mermaid-svg-t08scRjwLXQh4PDZ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-t08scRjwLXQh4PDZ .rough-node .label text,#mermaid-svg-t08scRjwLXQh4PDZ .node .label text,#mermaid-svg-t08scRjwLXQh4PDZ .image-shape .label,#mermaid-svg-t08scRjwLXQh4PDZ .icon-shape .label{text-anchor:middle;}#mermaid-svg-t08scRjwLXQh4PDZ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-t08scRjwLXQh4PDZ .rough-node .label,#mermaid-svg-t08scRjwLXQh4PDZ .node .label,#mermaid-svg-t08scRjwLXQh4PDZ .image-shape .label,#mermaid-svg-t08scRjwLXQh4PDZ .icon-shape .label{text-align:center;}#mermaid-svg-t08scRjwLXQh4PDZ .node.clickable{cursor:pointer;}#mermaid-svg-t08scRjwLXQh4PDZ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-t08scRjwLXQh4PDZ .arrowheadPath{fill:#333333;}#mermaid-svg-t08scRjwLXQh4PDZ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-t08scRjwLXQh4PDZ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-t08scRjwLXQh4PDZ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-t08scRjwLXQh4PDZ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-t08scRjwLXQh4PDZ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-t08scRjwLXQh4PDZ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-t08scRjwLXQh4PDZ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-t08scRjwLXQh4PDZ .cluster text{fill:#333;}#mermaid-svg-t08scRjwLXQh4PDZ .cluster span{color:#333;}#mermaid-svg-t08scRjwLXQh4PDZ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-t08scRjwLXQh4PDZ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-t08scRjwLXQh4PDZ rect.text{fill:none;stroke-width:0;}#mermaid-svg-t08scRjwLXQh4PDZ .icon-shape,#mermaid-svg-t08scRjwLXQh4PDZ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-t08scRjwLXQh4PDZ .icon-shape p,#mermaid-svg-t08scRjwLXQh4PDZ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-t08scRjwLXQh4PDZ .icon-shape rect,#mermaid-svg-t08scRjwLXQh4PDZ .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-t08scRjwLXQh4PDZ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-t08scRjwLXQh4PDZ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-t08scRjwLXQh4PDZ :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

输入

多头注意力

Head 1

Head 2

Head 3

Head 4

Concat

Linear

输出

多头注意力的优势:

  • 每个头关注不同的语义信息
  • 捕捉多种类型的依赖关系
  • 增强模型表达能力

7.5 Transformer代码实现

import torch
import torch.nn as nn
import math

class MultiHeadAttention(nn.Module):
"""
多头自注意力机制
"""

def __init__(self, d_model, num_heads):
super(MultiHeadAttention, self).__init__()

assert d_model % num_heads == 0

self.d_model = d_model
self.num_heads = num_heads
self.d_k = d_model // num_heads

# Q, K, V的线性变换
self.W_q = nn.Linear(d_model, d_model)
self.W_k = nn.Linear(d_model, d_model)
self.W_v = nn.Linear(d_model, d_model)

# 输出线性变换
self.W_o = nn.Linear(d_model, d_model)

def forward(self, x, mask=None):
batch_size = x.size(0)

# 线性变换
Q = self.W_q(x)
K = self.W_k(x)
V = self.W_v(x)

# 分割多头
Q = Q.view(batch_size, 1, self.num_heads, self.d_k).transpose(1, 2)
K = K.view(batch_size, 1, self.num_heads, self.d_k).transpose(1, 2)
V = V.view(batch_size, 1, self.num_heads, self.d_k).transpose(1, 2)

# 计算注意力分数
scores = torch.matmul(Q, K.transpose(2, 1)) / math.sqrt(self.d_k)

# 应用掩码(可选)
if mask is not None:
scores = scores.masked_fill(mask == 0, 1e9)

# Softmax归一化
attention = torch.softmax(scores, dim=1)

# 加权求和
output = torch.matmul(attention, V)

# 合并多头
output = output.transpose(1, 2).contiguous().view(batch_size, 1, self.d_model)

# 输出线性变换
output = self.W_o(output)

return output

class TransformerEncoderLayer(nn.Module):
"""
Transformer编码器层
"""

def __init__(self, d_model, num_heads, d_ff, dropout=0.1):
super(TransformerEncoderLayer, self).__init__()

self.attention = MultiHeadAttention(d_model, num_heads)
self.feed_forward = nn.Sequential(
nn.Linear(d_model, d_ff),
nn.ReLU(),
nn.Linear(d_ff, d_model)
)

self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)

self.dropout = nn.Dropout(dropout)

def forward(self, x, mask=None):
# 多头注意力 + 残差连接 + LayerNorm
attention_output = self.attention(x, mask)
x = self.norm1(x + self.dropout(attention_output))

# 前馈网络 + 残差连接 + LayerNorm
ff_output = self.feed_forward(x)
x = self.norm2(x + self.dropout(ff_output))

return x

class TransformerEncoder(nn.Module):
"""
Transformer编码器
"""

def __init__(
self,
vocab_size,
d_model,
num_heads,
num_layers,
d_ff,
max_seq_len,
dropout=0.1
):
super(TransformerEncoder, self).__init__()

# 词嵌入
self.embedding = nn.Embedding(vocab_size, d_model)

# 位置编码
self.positional_encoding = self._create_positional_encoding(
max_seq_len, d_model
)

# 编码器层
self.layers = nn.ModuleList([
TransformerEncoderLayer(d_model, num_heads, d_ff, dropout)
for _ in range(num_layers)
])

self.dropout = nn.Dropout(dropout)

def _create_positional_encoding(self, max_seq_len, d_model):
"""创建位置编码"""
pe = torch.zeros(max_seq_len, d_model)
position = torch.arange(0, max_seq_len, dtype=torch.float).unsqueeze(1)
div_term = torch.exp(
torch.arange(0, d_model, 2).float() * (math.log(10000.0) / d_model)
)

pe[:, 0::2] = torch.sin(position * div_term)
pe[:, 1::2] = torch.cos(position * div_term)

return pe.unsqueeze(0)

def forward(self, x, mask=None):
# 词嵌入 + 位置编码
x = self.embedding(x)
x = x + self.positional_encoding[:, :x.size(1), :].to(x.device)
x = self.dropout(x)

# 通过编码器层
for layer in self.layers:
x = layer(x, mask)

return x

# 使用示例
model = TransformerEncoder(
vocab_size=10000,
d_model=512,
num_heads=8,
num_layers=6,
d_ff=2048,
max_seq_len=512
)

x = torch.randint(0, 10000, (32, 100)) # batch=32, seq_len=100
output = model(x)
print(output.shape) # torch.Size([32, 100, 512])

7.6 Transformer vs RNN

#mermaid-svg-xP1n5aVw1LsoB6dt{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-xP1n5aVw1LsoB6dt .error-icon{fill:#552222;}#mermaid-svg-xP1n5aVw1LsoB6dt .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-xP1n5aVw1LsoB6dt .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-xP1n5aVw1LsoB6dt .marker{fill:#333333;stroke:#333333;}#mermaid-svg-xP1n5aVw1LsoB6dt .marker.cross{stroke:#333333;}#mermaid-svg-xP1n5aVw1LsoB6dt svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-xP1n5aVw1LsoB6dt p{margin:0;}#mermaid-svg-xP1n5aVw1LsoB6dt .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster-label text{fill:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster-label span{color:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster-label span p{background-color:transparent;}#mermaid-svg-xP1n5aVw1LsoB6dt .label text,#mermaid-svg-xP1n5aVw1LsoB6dt span{fill:#333;color:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt .node rect,#mermaid-svg-xP1n5aVw1LsoB6dt .node circle,#mermaid-svg-xP1n5aVw1LsoB6dt .node ellipse,#mermaid-svg-xP1n5aVw1LsoB6dt .node polygon,#mermaid-svg-xP1n5aVw1LsoB6dt .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-xP1n5aVw1LsoB6dt .rough-node .label text,#mermaid-svg-xP1n5aVw1LsoB6dt .node .label text,#mermaid-svg-xP1n5aVw1LsoB6dt .image-shape .label,#mermaid-svg-xP1n5aVw1LsoB6dt .icon-shape .label{text-anchor:middle;}#mermaid-svg-xP1n5aVw1LsoB6dt .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-xP1n5aVw1LsoB6dt .rough-node .label,#mermaid-svg-xP1n5aVw1LsoB6dt .node .label,#mermaid-svg-xP1n5aVw1LsoB6dt .image-shape .label,#mermaid-svg-xP1n5aVw1LsoB6dt .icon-shape .label{text-align:center;}#mermaid-svg-xP1n5aVw1LsoB6dt .node.clickable{cursor:pointer;}#mermaid-svg-xP1n5aVw1LsoB6dt .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-xP1n5aVw1LsoB6dt .arrowheadPath{fill:#333333;}#mermaid-svg-xP1n5aVw1LsoB6dt .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-xP1n5aVw1LsoB6dt .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-xP1n5aVw1LsoB6dt .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-xP1n5aVw1LsoB6dt .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-xP1n5aVw1LsoB6dt .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-xP1n5aVw1LsoB6dt .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster text{fill:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt .cluster span{color:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-xP1n5aVw1LsoB6dt .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-xP1n5aVw1LsoB6dt rect.text{fill:none;stroke-width:0;}#mermaid-svg-xP1n5aVw1LsoB6dt .icon-shape,#mermaid-svg-xP1n5aVw1LsoB6dt .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-xP1n5aVw1LsoB6dt .icon-shape p,#mermaid-svg-xP1n5aVw1LsoB6dt .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-xP1n5aVw1LsoB6dt .icon-shape rect,#mermaid-svg-xP1n5aVw1LsoB6dt .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-xP1n5aVw1LsoB6dt .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-xP1n5aVw1LsoB6dt .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-xP1n5aVw1LsoB6dt :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

Transformer

并行计算

训练快

全局注意力

长距离依赖好

RNN

串行计算

训练慢

长距离依赖差

梯度消失

核心优势对比:

维度RNN/LSTMTransformer
计算方式 串行 并行
训练速度
长距离依赖
参数量
内存占用

八、YOLOv8:目标检测的SOTA

8.1 目标检测任务

#mermaid-svg-HgejwS2yA0KLyAXC{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-HgejwS2yA0KLyAXC .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-HgejwS2yA0KLyAXC .error-icon{fill:#552222;}#mermaid-svg-HgejwS2yA0KLyAXC .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-HgejwS2yA0KLyAXC .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-HgejwS2yA0KLyAXC .marker{fill:#333333;stroke:#333333;}#mermaid-svg-HgejwS2yA0KLyAXC .marker.cross{stroke:#333333;}#mermaid-svg-HgejwS2yA0KLyAXC svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-HgejwS2yA0KLyAXC p{margin:0;}#mermaid-svg-HgejwS2yA0KLyAXC .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-HgejwS2yA0KLyAXC .cluster-label text{fill:#333;}#mermaid-svg-HgejwS2yA0KLyAXC .cluster-label span{color:#333;}#mermaid-svg-HgejwS2yA0KLyAXC .cluster-label span p{background-color:transparent;}#mermaid-svg-HgejwS2yA0KLyAXC .label text,#mermaid-svg-HgejwS2yA0KLyAXC span{fill:#333;color:#333;}#mermaid-svg-HgejwS2yA0KLyAXC .node rect,#mermaid-svg-HgejwS2yA0KLyAXC .node circle,#mermaid-svg-HgejwS2yA0KLyAXC .node ellipse,#mermaid-svg-HgejwS2yA0KLyAXC .node polygon,#mermaid-svg-HgejwS2yA0KLyAXC .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-HgejwS2yA0KLyAXC .rough-node .label text,#mermaid-svg-HgejwS2yA0KLyAXC .node .label text,#mermaid-svg-HgejwS2yA0KLyAXC .image-shape .label,#mermaid-svg-HgejwS2yA0KLyAXC .icon-shape .label{text-anchor:middle;}#mermaid-svg-HgejwS2yA0KLyAXC .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-HgejwS2yA0KLyAXC .rough-node .label,#mermaid-svg-HgejwS2yA0KLyAXC .node .label,#mermaid-svg-HgejwS2yA0KLyAXC .image-shape .label,#mermaid-svg-HgejwS2yA0KLyAXC .icon-shape .label{text-align:center;}#mermaid-svg-HgejwS2yA0KLyAXC .node.clickable{cursor:pointer;}#mermaid-svg-HgejwS2yA0KLyAXC .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-HgejwS2yA0KLyAXC .arrowheadPath{fill:#333333;}#mermaid-svg-HgejwS2yA0KLyAXC .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-HgejwS2yA0KLyAXC .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-HgejwS2yA0KLyAXC .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HgejwS2yA0KLyAXC .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-HgejwS2yA0KLyAXC .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HgejwS2yA0KLyAXC .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-HgejwS2yA0KLyAXC .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-HgejwS2yA0KLyAXC .cluster text{fill:#333;}#mermaid-svg-HgejwS2yA0KLyAXC .cluster span{color:#333;}#mermaid-svg-HgejwS2yA0KLyAXC div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-HgejwS2yA0KLyAXC .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-HgejwS2yA0KLyAXC rect.text{fill:none;stroke-width:0;}#mermaid-svg-HgejwS2yA0KLyAXC .icon-shape,#mermaid-svg-HgejwS2yA0KLyAXC .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HgejwS2yA0KLyAXC .icon-shape p,#mermaid-svg-HgejwS2yA0KLyAXC .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-HgejwS2yA0KLyAXC .icon-shape rect,#mermaid-svg-HgejwS2yA0KLyAXC .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HgejwS2yA0KLyAXC .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-HgejwS2yA0KLyAXC .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-HgejwS2yA0KLyAXC :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

目标检测任务

定位

分类

边界框Bounding Box

类别标签Class Label

输出: 物体位置 + 类别

8.2 YOLO系列演进

#mermaid-svg-4zM4dwi12SweVjkA{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-4zM4dwi12SweVjkA .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-4zM4dwi12SweVjkA .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-4zM4dwi12SweVjkA .error-icon{fill:#552222;}#mermaid-svg-4zM4dwi12SweVjkA .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-4zM4dwi12SweVjkA .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-4zM4dwi12SweVjkA .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-4zM4dwi12SweVjkA .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-4zM4dwi12SweVjkA .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-4zM4dwi12SweVjkA .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-4zM4dwi12SweVjkA .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-4zM4dwi12SweVjkA .marker{fill:#333333;stroke:#333333;}#mermaid-svg-4zM4dwi12SweVjkA .marker.cross{stroke:#333333;}#mermaid-svg-4zM4dwi12SweVjkA svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-4zM4dwi12SweVjkA p{margin:0;}#mermaid-svg-4zM4dwi12SweVjkA .edge{stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .section–1 rect,#mermaid-svg-4zM4dwi12SweVjkA .section–1 path,#mermaid-svg-4zM4dwi12SweVjkA .section–1 circle,#mermaid-svg-4zM4dwi12SweVjkA .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section–1 text{fill:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth–1{stroke-width:17;}#mermaid-svg-4zM4dwi12SweVjkA .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-0 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-0 path,#mermaid-svg-4zM4dwi12SweVjkA .section-0 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-4zM4dwi12SweVjkA .section-0 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-0{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-0{stroke-width:14;}#mermaid-svg-4zM4dwi12SweVjkA .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-1 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-1 path,#mermaid-svg-4zM4dwi12SweVjkA .section-1 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-1 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-1{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-1{stroke-width:11;}#mermaid-svg-4zM4dwi12SweVjkA .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-2 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-2 path,#mermaid-svg-4zM4dwi12SweVjkA .section-2 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-2 text{fill:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-2{stroke-width:8;}#mermaid-svg-4zM4dwi12SweVjkA .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-3 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-3 path,#mermaid-svg-4zM4dwi12SweVjkA .section-3 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-3 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-3{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-3{stroke-width:5;}#mermaid-svg-4zM4dwi12SweVjkA .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-4 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-4 path,#mermaid-svg-4zM4dwi12SweVjkA .section-4 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-4 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-4{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-4{stroke-width:2;}#mermaid-svg-4zM4dwi12SweVjkA .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-5 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-5 path,#mermaid-svg-4zM4dwi12SweVjkA .section-5 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-5 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-5{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-5{stroke-width:-1;}#mermaid-svg-4zM4dwi12SweVjkA .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-6 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-6 path,#mermaid-svg-4zM4dwi12SweVjkA .section-6 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-6 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-6{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-6{stroke-width:-4;}#mermaid-svg-4zM4dwi12SweVjkA .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-7 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-7 path,#mermaid-svg-4zM4dwi12SweVjkA .section-7 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-7 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-7{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-7{stroke-width:-7;}#mermaid-svg-4zM4dwi12SweVjkA .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-8 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-8 path,#mermaid-svg-4zM4dwi12SweVjkA .section-8 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-8 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-8{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-8{stroke-width:-10;}#mermaid-svg-4zM4dwi12SweVjkA .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-9 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-9 path,#mermaid-svg-4zM4dwi12SweVjkA .section-9 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-9 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-9{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-9{stroke-width:-13;}#mermaid-svg-4zM4dwi12SweVjkA .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-10 rect,#mermaid-svg-4zM4dwi12SweVjkA .section-10 path,#mermaid-svg-4zM4dwi12SweVjkA .section-10 circle,#mermaid-svg-4zM4dwi12SweVjkA .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-10 text{fill:black;}#mermaid-svg-4zM4dwi12SweVjkA .node-icon-10{font-size:40px;color:black;}#mermaid-svg-4zM4dwi12SweVjkA .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .edge-depth-10{stroke-width:-16;}#mermaid-svg-4zM4dwi12SweVjkA .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-4zM4dwi12SweVjkA .lineWrapper line{stroke:black;}#mermaid-svg-4zM4dwi12SweVjkA .disabled,#mermaid-svg-4zM4dwi12SweVjkA .disabled circle,#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:lightgray;}#mermaid-svg-4zM4dwi12SweVjkA .disabled text{fill:#efefef;}#mermaid-svg-4zM4dwi12SweVjkA .section-root rect,#mermaid-svg-4zM4dwi12SweVjkA .section-root path,#mermaid-svg-4zM4dwi12SweVjkA .section-root circle{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-4zM4dwi12SweVjkA .section-root text{fill:#ffffff;}#mermaid-svg-4zM4dwi12SweVjkA .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-4zM4dwi12SweVjkA .edge{fill:none;}#mermaid-svg-4zM4dwi12SweVjkA .eventWrapper{filter:brightness(120%);}#mermaid-svg-4zM4dwi12SweVjkA :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

2016

YOLOv1

开创性工作

单阶段检测

2017

YOLOv2/YOLO9000

Batch Normalization

Anchor Boxes

2018

YOLOv3

多尺度检测

Darknet-53

2020

YOLOv4

CSPDarknet

数据增强

2020

YOLOv5

PyTorch实现

易用性提升

2022

YOLOv6/YOLOv7

工业优化

速度提升

2023

YOLOv8

Anchor-Free

性能最优

YOLO系列演进史

8.3 YOLOv8架构详解

#mermaid-svg-5v2sZbtV4x4Cz5FW{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-5v2sZbtV4x4Cz5FW .error-icon{fill:#552222;}#mermaid-svg-5v2sZbtV4x4Cz5FW .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-5v2sZbtV4x4Cz5FW .marker{fill:#333333;stroke:#333333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .marker.cross{stroke:#333333;}#mermaid-svg-5v2sZbtV4x4Cz5FW svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-5v2sZbtV4x4Cz5FW p{margin:0;}#mermaid-svg-5v2sZbtV4x4Cz5FW .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster-label text{fill:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster-label span{color:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster-label span p{background-color:transparent;}#mermaid-svg-5v2sZbtV4x4Cz5FW .label text,#mermaid-svg-5v2sZbtV4x4Cz5FW span{fill:#333;color:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .node rect,#mermaid-svg-5v2sZbtV4x4Cz5FW .node circle,#mermaid-svg-5v2sZbtV4x4Cz5FW .node ellipse,#mermaid-svg-5v2sZbtV4x4Cz5FW .node polygon,#mermaid-svg-5v2sZbtV4x4Cz5FW .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .rough-node .label text,#mermaid-svg-5v2sZbtV4x4Cz5FW .node .label text,#mermaid-svg-5v2sZbtV4x4Cz5FW .image-shape .label,#mermaid-svg-5v2sZbtV4x4Cz5FW .icon-shape .label{text-anchor:middle;}#mermaid-svg-5v2sZbtV4x4Cz5FW .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .rough-node .label,#mermaid-svg-5v2sZbtV4x4Cz5FW .node .label,#mermaid-svg-5v2sZbtV4x4Cz5FW .image-shape .label,#mermaid-svg-5v2sZbtV4x4Cz5FW .icon-shape .label{text-align:center;}#mermaid-svg-5v2sZbtV4x4Cz5FW .node.clickable{cursor:pointer;}#mermaid-svg-5v2sZbtV4x4Cz5FW .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .arrowheadPath{fill:#333333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5v2sZbtV4x4Cz5FW .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-5v2sZbtV4x4Cz5FW .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5v2sZbtV4x4Cz5FW .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster text{fill:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW .cluster span{color:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-5v2sZbtV4x4Cz5FW .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-5v2sZbtV4x4Cz5FW rect.text{fill:none;stroke-width:0;}#mermaid-svg-5v2sZbtV4x4Cz5FW .icon-shape,#mermaid-svg-5v2sZbtV4x4Cz5FW .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5v2sZbtV4x4Cz5FW .icon-shape p,#mermaid-svg-5v2sZbtV4x4Cz5FW .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-5v2sZbtV4x4Cz5FW .icon-shape rect,#mermaid-svg-5v2sZbtV4x4Cz5FW .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5v2sZbtV4x4Cz5FW .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-5v2sZbtV4x4Cz5FW .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-5v2sZbtV4x4Cz5FW :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

检测头Head

颈部网络Neck

骨干网络Backbone

输入图像640×640×3

CSPDarknet特征提取

PANet特征融合

小目标检测80×80

中目标检测40×40

大目标检测20×20

检测结果边界框 + 类别

8.4 YOLOv8核心创新

#mermaid-svg-GFfvSmfUn5vtYXTe{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-GFfvSmfUn5vtYXTe .error-icon{fill:#552222;}#mermaid-svg-GFfvSmfUn5vtYXTe .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-GFfvSmfUn5vtYXTe .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-GFfvSmfUn5vtYXTe .marker{fill:#333333;stroke:#333333;}#mermaid-svg-GFfvSmfUn5vtYXTe .marker.cross{stroke:#333333;}#mermaid-svg-GFfvSmfUn5vtYXTe svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-GFfvSmfUn5vtYXTe p{margin:0;}#mermaid-svg-GFfvSmfUn5vtYXTe .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster-label text{fill:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster-label span{color:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster-label span p{background-color:transparent;}#mermaid-svg-GFfvSmfUn5vtYXTe .label text,#mermaid-svg-GFfvSmfUn5vtYXTe span{fill:#333;color:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe .node rect,#mermaid-svg-GFfvSmfUn5vtYXTe .node circle,#mermaid-svg-GFfvSmfUn5vtYXTe .node ellipse,#mermaid-svg-GFfvSmfUn5vtYXTe .node polygon,#mermaid-svg-GFfvSmfUn5vtYXTe .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-GFfvSmfUn5vtYXTe .rough-node .label text,#mermaid-svg-GFfvSmfUn5vtYXTe .node .label text,#mermaid-svg-GFfvSmfUn5vtYXTe .image-shape .label,#mermaid-svg-GFfvSmfUn5vtYXTe .icon-shape .label{text-anchor:middle;}#mermaid-svg-GFfvSmfUn5vtYXTe .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-GFfvSmfUn5vtYXTe .rough-node .label,#mermaid-svg-GFfvSmfUn5vtYXTe .node .label,#mermaid-svg-GFfvSmfUn5vtYXTe .image-shape .label,#mermaid-svg-GFfvSmfUn5vtYXTe .icon-shape .label{text-align:center;}#mermaid-svg-GFfvSmfUn5vtYXTe .node.clickable{cursor:pointer;}#mermaid-svg-GFfvSmfUn5vtYXTe .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-GFfvSmfUn5vtYXTe .arrowheadPath{fill:#333333;}#mermaid-svg-GFfvSmfUn5vtYXTe .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-GFfvSmfUn5vtYXTe .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-GFfvSmfUn5vtYXTe .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GFfvSmfUn5vtYXTe .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-GFfvSmfUn5vtYXTe .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GFfvSmfUn5vtYXTe .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster text{fill:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe .cluster span{color:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-GFfvSmfUn5vtYXTe .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-GFfvSmfUn5vtYXTe rect.text{fill:none;stroke-width:0;}#mermaid-svg-GFfvSmfUn5vtYXTe .icon-shape,#mermaid-svg-GFfvSmfUn5vtYXTe .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GFfvSmfUn5vtYXTe .icon-shape p,#mermaid-svg-GFfvSmfUn5vtYXTe .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-GFfvSmfUn5vtYXTe .icon-shape rect,#mermaid-svg-GFfvSmfUn5vtYXTe .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GFfvSmfUn5vtYXTe .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-GFfvSmfUn5vtYXTe .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-GFfvSmfUn5vtYXTe :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

YOLOv8创新点

Anchor-Free

解耦头

Mosaic增强

Task Aligned Assigner

无需预设锚框减少超参数

分类和回归分离提高精度

数据增强提高泛化能力

动态样本匹配提高正样本质量

8.5 YOLOv8代码实现

from ultralytics import YOLO
import cv2

# 1. 加载预训练模型
model = YOLO('yolov8n.pt') # nano版本,速度快

# 2. 训练模型
results = model.train(
data='coco.yaml', # 数据集配置
epochs=100, # 训练轮数
imgsz=640, # 图像大小
batch=16, # 批大小
name='yolov8_custom' # 实验名称
)

# 3. 验证模型
metrics = model.val()
print(f"mAP50: {metrics.box.map50}")
print(f"mAP50-95: {metrics.box.map}")

# 4. 推理
results = model('image.jpg')

# 5. 可视化结果
for result in results:
# 获取边界框
boxes = result.boxes
for box in boxes:
# 边界框坐标
x1, y1, x2, y2 = box.xyxy[0]

# 类别和置信度
cls = int(box.cls[0])
conf = float(box.conf[0])

print(f"类别: {cls}, 置信度: {conf:.2f}, 位置: ({x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f})")

# 6. 保存结果
result.save('result.jpg')

8.6 YOLOv8与其他检测器对比

#mermaid-svg-sfZusTkM3AnQRcGZ{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-sfZusTkM3AnQRcGZ .error-icon{fill:#552222;}#mermaid-svg-sfZusTkM3AnQRcGZ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-sfZusTkM3AnQRcGZ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-sfZusTkM3AnQRcGZ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-sfZusTkM3AnQRcGZ .marker.cross{stroke:#333333;}#mermaid-svg-sfZusTkM3AnQRcGZ svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-sfZusTkM3AnQRcGZ p{margin:0;}#mermaid-svg-sfZusTkM3AnQRcGZ .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster-label text{fill:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster-label span{color:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster-label span p{background-color:transparent;}#mermaid-svg-sfZusTkM3AnQRcGZ .label text,#mermaid-svg-sfZusTkM3AnQRcGZ span{fill:#333;color:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ .node rect,#mermaid-svg-sfZusTkM3AnQRcGZ .node circle,#mermaid-svg-sfZusTkM3AnQRcGZ .node ellipse,#mermaid-svg-sfZusTkM3AnQRcGZ .node polygon,#mermaid-svg-sfZusTkM3AnQRcGZ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-sfZusTkM3AnQRcGZ .rough-node .label text,#mermaid-svg-sfZusTkM3AnQRcGZ .node .label text,#mermaid-svg-sfZusTkM3AnQRcGZ .image-shape .label,#mermaid-svg-sfZusTkM3AnQRcGZ .icon-shape .label{text-anchor:middle;}#mermaid-svg-sfZusTkM3AnQRcGZ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-sfZusTkM3AnQRcGZ .rough-node .label,#mermaid-svg-sfZusTkM3AnQRcGZ .node .label,#mermaid-svg-sfZusTkM3AnQRcGZ .image-shape .label,#mermaid-svg-sfZusTkM3AnQRcGZ .icon-shape .label{text-align:center;}#mermaid-svg-sfZusTkM3AnQRcGZ .node.clickable{cursor:pointer;}#mermaid-svg-sfZusTkM3AnQRcGZ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-sfZusTkM3AnQRcGZ .arrowheadPath{fill:#333333;}#mermaid-svg-sfZusTkM3AnQRcGZ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-sfZusTkM3AnQRcGZ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-sfZusTkM3AnQRcGZ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-sfZusTkM3AnQRcGZ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-sfZusTkM3AnQRcGZ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-sfZusTkM3AnQRcGZ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster text{fill:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ .cluster span{color:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-sfZusTkM3AnQRcGZ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-sfZusTkM3AnQRcGZ rect.text{fill:none;stroke-width:0;}#mermaid-svg-sfZusTkM3AnQRcGZ .icon-shape,#mermaid-svg-sfZusTkM3AnQRcGZ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-sfZusTkM3AnQRcGZ .icon-shape p,#mermaid-svg-sfZusTkM3AnQRcGZ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-sfZusTkM3AnQRcGZ .icon-shape rect,#mermaid-svg-sfZusTkM3AnQRcGZ .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-sfZusTkM3AnQRcGZ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-sfZusTkM3AnQRcGZ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-sfZusTkM3AnQRcGZ :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

目标检测器

两阶段

单阶段

R-CNN系列

精度高速度慢

YOLO系列

SSD

RetinaNet

速度快精度高

性能对比:

模型mAP50-95FPS (V100)参数量
YOLOv8n 37.3% 330 3.2M
YOLOv8s 44.9% 170 11.2M
YOLOv8m 50.2% 90 25.9M
YOLOv8l 52.9% 60 43.7M
YOLOv8x 53.9% 40 68.2M

8.7 YOLOv8中的CNN架构

#mermaid-svg-AFopX8eeUCoSubdD{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-AFopX8eeUCoSubdD .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-AFopX8eeUCoSubdD .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-AFopX8eeUCoSubdD .error-icon{fill:#552222;}#mermaid-svg-AFopX8eeUCoSubdD .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-AFopX8eeUCoSubdD .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-AFopX8eeUCoSubdD .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-AFopX8eeUCoSubdD .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-AFopX8eeUCoSubdD .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-AFopX8eeUCoSubdD .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-AFopX8eeUCoSubdD .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-AFopX8eeUCoSubdD .marker{fill:#333333;stroke:#333333;}#mermaid-svg-AFopX8eeUCoSubdD .marker.cross{stroke:#333333;}#mermaid-svg-AFopX8eeUCoSubdD svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-AFopX8eeUCoSubdD p{margin:0;}#mermaid-svg-AFopX8eeUCoSubdD .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-AFopX8eeUCoSubdD .cluster-label text{fill:#333;}#mermaid-svg-AFopX8eeUCoSubdD .cluster-label span{color:#333;}#mermaid-svg-AFopX8eeUCoSubdD .cluster-label span p{background-color:transparent;}#mermaid-svg-AFopX8eeUCoSubdD .label text,#mermaid-svg-AFopX8eeUCoSubdD span{fill:#333;color:#333;}#mermaid-svg-AFopX8eeUCoSubdD .node rect,#mermaid-svg-AFopX8eeUCoSubdD .node circle,#mermaid-svg-AFopX8eeUCoSubdD .node ellipse,#mermaid-svg-AFopX8eeUCoSubdD .node polygon,#mermaid-svg-AFopX8eeUCoSubdD .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-AFopX8eeUCoSubdD .rough-node .label text,#mermaid-svg-AFopX8eeUCoSubdD .node .label text,#mermaid-svg-AFopX8eeUCoSubdD .image-shape .label,#mermaid-svg-AFopX8eeUCoSubdD .icon-shape .label{text-anchor:middle;}#mermaid-svg-AFopX8eeUCoSubdD .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-AFopX8eeUCoSubdD .rough-node .label,#mermaid-svg-AFopX8eeUCoSubdD .node .label,#mermaid-svg-AFopX8eeUCoSubdD .image-shape .label,#mermaid-svg-AFopX8eeUCoSubdD .icon-shape .label{text-align:center;}#mermaid-svg-AFopX8eeUCoSubdD .node.clickable{cursor:pointer;}#mermaid-svg-AFopX8eeUCoSubdD .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-AFopX8eeUCoSubdD .arrowheadPath{fill:#333333;}#mermaid-svg-AFopX8eeUCoSubdD .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-AFopX8eeUCoSubdD .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-AFopX8eeUCoSubdD .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-AFopX8eeUCoSubdD .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-AFopX8eeUCoSubdD .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-AFopX8eeUCoSubdD .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-AFopX8eeUCoSubdD .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-AFopX8eeUCoSubdD .cluster text{fill:#333;}#mermaid-svg-AFopX8eeUCoSubdD .cluster span{color:#333;}#mermaid-svg-AFopX8eeUCoSubdD div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-AFopX8eeUCoSubdD .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-AFopX8eeUCoSubdD rect.text{fill:none;stroke-width:0;}#mermaid-svg-AFopX8eeUCoSubdD .icon-shape,#mermaid-svg-AFopX8eeUCoSubdD .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-AFopX8eeUCoSubdD .icon-shape p,#mermaid-svg-AFopX8eeUCoSubdD .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-AFopX8eeUCoSubdD .icon-shape rect,#mermaid-svg-AFopX8eeUCoSubdD .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-AFopX8eeUCoSubdD .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-AFopX8eeUCoSubdD .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-AFopX8eeUCoSubdD :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

YOLOv8使用的技术

CNN骨干网络

特征金字塔FPN

注意力机制

CSPDarknet残差连接

PANet多尺度融合

SPPF空间金字塔池化


九、技术选型指南

9.1 架构选择决策树

#mermaid-svg-MXd4vpGP2wqmc4gF{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-MXd4vpGP2wqmc4gF .error-icon{fill:#552222;}#mermaid-svg-MXd4vpGP2wqmc4gF .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MXd4vpGP2wqmc4gF .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MXd4vpGP2wqmc4gF .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MXd4vpGP2wqmc4gF .marker.cross{stroke:#333333;}#mermaid-svg-MXd4vpGP2wqmc4gF svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MXd4vpGP2wqmc4gF p{margin:0;}#mermaid-svg-MXd4vpGP2wqmc4gF .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster-label text{fill:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster-label span{color:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster-label span p{background-color:transparent;}#mermaid-svg-MXd4vpGP2wqmc4gF .label text,#mermaid-svg-MXd4vpGP2wqmc4gF span{fill:#333;color:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF .node rect,#mermaid-svg-MXd4vpGP2wqmc4gF .node circle,#mermaid-svg-MXd4vpGP2wqmc4gF .node ellipse,#mermaid-svg-MXd4vpGP2wqmc4gF .node polygon,#mermaid-svg-MXd4vpGP2wqmc4gF .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MXd4vpGP2wqmc4gF .rough-node .label text,#mermaid-svg-MXd4vpGP2wqmc4gF .node .label text,#mermaid-svg-MXd4vpGP2wqmc4gF .image-shape .label,#mermaid-svg-MXd4vpGP2wqmc4gF .icon-shape .label{text-anchor:middle;}#mermaid-svg-MXd4vpGP2wqmc4gF .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-MXd4vpGP2wqmc4gF .rough-node .label,#mermaid-svg-MXd4vpGP2wqmc4gF .node .label,#mermaid-svg-MXd4vpGP2wqmc4gF .image-shape .label,#mermaid-svg-MXd4vpGP2wqmc4gF .icon-shape .label{text-align:center;}#mermaid-svg-MXd4vpGP2wqmc4gF .node.clickable{cursor:pointer;}#mermaid-svg-MXd4vpGP2wqmc4gF .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-MXd4vpGP2wqmc4gF .arrowheadPath{fill:#333333;}#mermaid-svg-MXd4vpGP2wqmc4gF .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MXd4vpGP2wqmc4gF .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MXd4vpGP2wqmc4gF .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MXd4vpGP2wqmc4gF .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-MXd4vpGP2wqmc4gF .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MXd4vpGP2wqmc4gF .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster text{fill:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF .cluster span{color:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MXd4vpGP2wqmc4gF .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-MXd4vpGP2wqmc4gF rect.text{fill:none;stroke-width:0;}#mermaid-svg-MXd4vpGP2wqmc4gF .icon-shape,#mermaid-svg-MXd4vpGP2wqmc4gF .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MXd4vpGP2wqmc4gF .icon-shape p,#mermaid-svg-MXd4vpGP2wqmc4gF .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-MXd4vpGP2wqmc4gF .icon-shape rect,#mermaid-svg-MXd4vpGP2wqmc4gF .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MXd4vpGP2wqmc4gF .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-MXd4vpGP2wqmc4gF .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-MXd4vpGP2wqmc4gF :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

图像

分类

检测

分割

序列/文本

分类

生成

理解

时间序列

很长

选择架构

数据类型?

任务类型?

CNN

YOLOv8

U-Net

任务类型?

Transformer

GPT

BERT

序列长度?

RNN

LSTM/GRU

Transformer

9.2 各架构适用场景总结

#mermaid-svg-i47h3MyaeNUPBmg4{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-i47h3MyaeNUPBmg4 .error-icon{fill:#552222;}#mermaid-svg-i47h3MyaeNUPBmg4 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-i47h3MyaeNUPBmg4 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-i47h3MyaeNUPBmg4 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-i47h3MyaeNUPBmg4 .marker.cross{stroke:#333333;}#mermaid-svg-i47h3MyaeNUPBmg4 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-i47h3MyaeNUPBmg4 p{margin:0;}#mermaid-svg-i47h3MyaeNUPBmg4 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster-label text{fill:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster-label span{color:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster-label span p{background-color:transparent;}#mermaid-svg-i47h3MyaeNUPBmg4 .label text,#mermaid-svg-i47h3MyaeNUPBmg4 span{fill:#333;color:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 .node rect,#mermaid-svg-i47h3MyaeNUPBmg4 .node circle,#mermaid-svg-i47h3MyaeNUPBmg4 .node ellipse,#mermaid-svg-i47h3MyaeNUPBmg4 .node polygon,#mermaid-svg-i47h3MyaeNUPBmg4 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-i47h3MyaeNUPBmg4 .rough-node .label text,#mermaid-svg-i47h3MyaeNUPBmg4 .node .label text,#mermaid-svg-i47h3MyaeNUPBmg4 .image-shape .label,#mermaid-svg-i47h3MyaeNUPBmg4 .icon-shape .label{text-anchor:middle;}#mermaid-svg-i47h3MyaeNUPBmg4 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-i47h3MyaeNUPBmg4 .rough-node .label,#mermaid-svg-i47h3MyaeNUPBmg4 .node .label,#mermaid-svg-i47h3MyaeNUPBmg4 .image-shape .label,#mermaid-svg-i47h3MyaeNUPBmg4 .icon-shape .label{text-align:center;}#mermaid-svg-i47h3MyaeNUPBmg4 .node.clickable{cursor:pointer;}#mermaid-svg-i47h3MyaeNUPBmg4 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-i47h3MyaeNUPBmg4 .arrowheadPath{fill:#333333;}#mermaid-svg-i47h3MyaeNUPBmg4 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-i47h3MyaeNUPBmg4 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-i47h3MyaeNUPBmg4 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-i47h3MyaeNUPBmg4 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-i47h3MyaeNUPBmg4 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-i47h3MyaeNUPBmg4 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster text{fill:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 .cluster span{color:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-i47h3MyaeNUPBmg4 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-i47h3MyaeNUPBmg4 rect.text{fill:none;stroke-width:0;}#mermaid-svg-i47h3MyaeNUPBmg4 .icon-shape,#mermaid-svg-i47h3MyaeNUPBmg4 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-i47h3MyaeNUPBmg4 .icon-shape p,#mermaid-svg-i47h3MyaeNUPBmg4 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-i47h3MyaeNUPBmg4 .icon-shape rect,#mermaid-svg-i47h3MyaeNUPBmg4 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-i47h3MyaeNUPBmg4 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-i47h3MyaeNUPBmg4 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-i47h3MyaeNUPBmg4 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

YOLO适用场景

实时检测

自动驾驶

安防监控

工业检测

Transformer适用场景

大语言模型

机器翻译

文本理解

多模态任务

RNN/LSTM适用场景

语音识别

机器翻译

文本生成

时间序列预测

CNN适用场景

图像分类

目标检测

图像分割

人脸识别

9.3 技术栈关系总结

#mermaid-svg-zHvPmpiaiNdCH05M{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-zHvPmpiaiNdCH05M .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-zHvPmpiaiNdCH05M .error-icon{fill:#552222;}#mermaid-svg-zHvPmpiaiNdCH05M .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-zHvPmpiaiNdCH05M .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-zHvPmpiaiNdCH05M .marker{fill:#333333;stroke:#333333;}#mermaid-svg-zHvPmpiaiNdCH05M .marker.cross{stroke:#333333;}#mermaid-svg-zHvPmpiaiNdCH05M svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-zHvPmpiaiNdCH05M p{margin:0;}#mermaid-svg-zHvPmpiaiNdCH05M .edge{stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .section–1 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section–1 path,#mermaid-svg-zHvPmpiaiNdCH05M .section–1 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section–1 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section–1 text{fill:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth–1{stroke-width:17;}#mermaid-svg-zHvPmpiaiNdCH05M .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-0 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-0 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-0 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-0 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-0 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-0{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-0{stroke-width:14;}#mermaid-svg-zHvPmpiaiNdCH05M .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-1 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-1 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-1 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-1 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-1 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-1{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-1{stroke-width:11;}#mermaid-svg-zHvPmpiaiNdCH05M .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-2 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-2 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-2 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-2 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-2 text{fill:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-2{stroke-width:8;}#mermaid-svg-zHvPmpiaiNdCH05M .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-3 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-3 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-3 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-3 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-3 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-3{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-3{stroke-width:5;}#mermaid-svg-zHvPmpiaiNdCH05M .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-4 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-4 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-4 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-4 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-4 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-4{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-4{stroke-width:2;}#mermaid-svg-zHvPmpiaiNdCH05M .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-5 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-5 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-5 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-5 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-5 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-5{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-5{stroke-width:-1;}#mermaid-svg-zHvPmpiaiNdCH05M .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-6 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-6 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-6 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-6 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-6 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-6{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-6{stroke-width:-4;}#mermaid-svg-zHvPmpiaiNdCH05M .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-7 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-7 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-7 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-7 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-7 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-7{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-7{stroke-width:-7;}#mermaid-svg-zHvPmpiaiNdCH05M .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-8 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-8 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-8 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-8 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-8 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-8{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-8{stroke-width:-10;}#mermaid-svg-zHvPmpiaiNdCH05M .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-9 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-9 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-9 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-9 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-9 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-9{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-9{stroke-width:-13;}#mermaid-svg-zHvPmpiaiNdCH05M .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-10 rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-10 path,#mermaid-svg-zHvPmpiaiNdCH05M .section-10 circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-10 polygon,#mermaid-svg-zHvPmpiaiNdCH05M .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-10 text{fill:black;}#mermaid-svg-zHvPmpiaiNdCH05M .node-icon-10{font-size:40px;color:black;}#mermaid-svg-zHvPmpiaiNdCH05M .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .edge-depth-10{stroke-width:-16;}#mermaid-svg-zHvPmpiaiNdCH05M .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled,#mermaid-svg-zHvPmpiaiNdCH05M .disabled circle,#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:lightgray;}#mermaid-svg-zHvPmpiaiNdCH05M .disabled text{fill:#efefef;}#mermaid-svg-zHvPmpiaiNdCH05M .section-root rect,#mermaid-svg-zHvPmpiaiNdCH05M .section-root path,#mermaid-svg-zHvPmpiaiNdCH05M .section-root circle,#mermaid-svg-zHvPmpiaiNdCH05M .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-zHvPmpiaiNdCH05M .section-root text{fill:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .section-root span{color:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .section-2 span{color:#ffffff;}#mermaid-svg-zHvPmpiaiNdCH05M .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-zHvPmpiaiNdCH05M .edge{fill:none;}#mermaid-svg-zHvPmpiaiNdCH05M .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-zHvPmpiaiNdCH05M :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

AI技术栈

机器学习

监督学习

无监督学习

强化学习

深度学习

神经网络

CNN

图像处理

YOLOv8

RNN

序列处理

LSTM

Transformer

注意力机制

GPT/BERT

应用领域

计算机视觉

图像分类

目标检测

自然语言处理

文本分类

机器翻译

语音处理

语音识别

语音合成

9.4 学习路径建议

#mermaid-svg-oAmxcFpm6y8WUEu1{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-oAmxcFpm6y8WUEu1 .error-icon{fill:#552222;}#mermaid-svg-oAmxcFpm6y8WUEu1 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-oAmxcFpm6y8WUEu1 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .marker.cross{stroke:#333333;}#mermaid-svg-oAmxcFpm6y8WUEu1 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-oAmxcFpm6y8WUEu1 p{margin:0;}#mermaid-svg-oAmxcFpm6y8WUEu1 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster-label text{fill:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster-label span{color:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster-label span p{background-color:transparent;}#mermaid-svg-oAmxcFpm6y8WUEu1 .label text,#mermaid-svg-oAmxcFpm6y8WUEu1 span{fill:#333;color:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .node rect,#mermaid-svg-oAmxcFpm6y8WUEu1 .node circle,#mermaid-svg-oAmxcFpm6y8WUEu1 .node ellipse,#mermaid-svg-oAmxcFpm6y8WUEu1 .node polygon,#mermaid-svg-oAmxcFpm6y8WUEu1 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .rough-node .label text,#mermaid-svg-oAmxcFpm6y8WUEu1 .node .label text,#mermaid-svg-oAmxcFpm6y8WUEu1 .image-shape .label,#mermaid-svg-oAmxcFpm6y8WUEu1 .icon-shape .label{text-anchor:middle;}#mermaid-svg-oAmxcFpm6y8WUEu1 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .rough-node .label,#mermaid-svg-oAmxcFpm6y8WUEu1 .node .label,#mermaid-svg-oAmxcFpm6y8WUEu1 .image-shape .label,#mermaid-svg-oAmxcFpm6y8WUEu1 .icon-shape .label{text-align:center;}#mermaid-svg-oAmxcFpm6y8WUEu1 .node.clickable{cursor:pointer;}#mermaid-svg-oAmxcFpm6y8WUEu1 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .arrowheadPath{fill:#333333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-oAmxcFpm6y8WUEu1 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-oAmxcFpm6y8WUEu1 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-oAmxcFpm6y8WUEu1 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster text{fill:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 .cluster span{color:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-oAmxcFpm6y8WUEu1 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-oAmxcFpm6y8WUEu1 rect.text{fill:none;stroke-width:0;}#mermaid-svg-oAmxcFpm6y8WUEu1 .icon-shape,#mermaid-svg-oAmxcFpm6y8WUEu1 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-oAmxcFpm6y8WUEu1 .icon-shape p,#mermaid-svg-oAmxcFpm6y8WUEu1 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-oAmxcFpm6y8WUEu1 .icon-shape rect,#mermaid-svg-oAmxcFpm6y8WUEu1 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-oAmxcFpm6y8WUEu1 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-oAmxcFpm6y8WUEu1 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-oAmxcFpm6y8WUEu1 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

入门

Python基础

机器学习基础

深度学习基础

神经网络

CNN

RNN/LSTM

Transformer

计算机视觉

序列建模

NLP/LLM

YOLOv8

GPT/BERT


总结

核心概念关系回顾

#mermaid-svg-eTjeoWl80Nb8yB3U{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-eTjeoWl80Nb8yB3U .error-icon{fill:#552222;}#mermaid-svg-eTjeoWl80Nb8yB3U .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-eTjeoWl80Nb8yB3U .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-eTjeoWl80Nb8yB3U .marker{fill:#333333;stroke:#333333;}#mermaid-svg-eTjeoWl80Nb8yB3U .marker.cross{stroke:#333333;}#mermaid-svg-eTjeoWl80Nb8yB3U svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-eTjeoWl80Nb8yB3U p{margin:0;}#mermaid-svg-eTjeoWl80Nb8yB3U .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster-label text{fill:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster-label span{color:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster-label span p{background-color:transparent;}#mermaid-svg-eTjeoWl80Nb8yB3U .label text,#mermaid-svg-eTjeoWl80Nb8yB3U span{fill:#333;color:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U .node rect,#mermaid-svg-eTjeoWl80Nb8yB3U .node circle,#mermaid-svg-eTjeoWl80Nb8yB3U .node ellipse,#mermaid-svg-eTjeoWl80Nb8yB3U .node polygon,#mermaid-svg-eTjeoWl80Nb8yB3U .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-eTjeoWl80Nb8yB3U .rough-node .label text,#mermaid-svg-eTjeoWl80Nb8yB3U .node .label text,#mermaid-svg-eTjeoWl80Nb8yB3U .image-shape .label,#mermaid-svg-eTjeoWl80Nb8yB3U .icon-shape .label{text-anchor:middle;}#mermaid-svg-eTjeoWl80Nb8yB3U .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-eTjeoWl80Nb8yB3U .rough-node .label,#mermaid-svg-eTjeoWl80Nb8yB3U .node .label,#mermaid-svg-eTjeoWl80Nb8yB3U .image-shape .label,#mermaid-svg-eTjeoWl80Nb8yB3U .icon-shape .label{text-align:center;}#mermaid-svg-eTjeoWl80Nb8yB3U .node.clickable{cursor:pointer;}#mermaid-svg-eTjeoWl80Nb8yB3U .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-eTjeoWl80Nb8yB3U .arrowheadPath{fill:#333333;}#mermaid-svg-eTjeoWl80Nb8yB3U .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-eTjeoWl80Nb8yB3U .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-eTjeoWl80Nb8yB3U .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-eTjeoWl80Nb8yB3U .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-eTjeoWl80Nb8yB3U .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-eTjeoWl80Nb8yB3U .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster text{fill:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U .cluster span{color:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-eTjeoWl80Nb8yB3U .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-eTjeoWl80Nb8yB3U rect.text{fill:none;stroke-width:0;}#mermaid-svg-eTjeoWl80Nb8yB3U .icon-shape,#mermaid-svg-eTjeoWl80Nb8yB3U .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-eTjeoWl80Nb8yB3U .icon-shape p,#mermaid-svg-eTjeoWl80Nb8yB3U .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-eTjeoWl80Nb8yB3U .icon-shape rect,#mermaid-svg-eTjeoWl80Nb8yB3U .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-eTjeoWl80Nb8yB3U .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-eTjeoWl80Nb8yB3U .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-eTjeoWl80Nb8yB3U :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

人工智能

机器学习

深度学习

神经网络

CNN图像处理

RNN/LSTM序列处理

Transformer注意力机制

YOLOv8目标检测

GPT/BERT大语言模型

关键要点

  • 层级关系:AI ⊃ ML ⊃ DL ⊃ NN
  • CNN:图像处理的王者,核心是卷积和池化
  • RNN/LSTM:序列数据的利器,LSTM解决长距离依赖
  • Transformer:NLP的革命,核心是自注意力机制
  • YOLOv8:目标检测的SOTA,融合CNN和最新技术
  • 面试加分话术

  • 展示深度理解:

    “CNN的核心思想是局部感受野和权重共享,这大大减少了参数量。Transformer通过自注意力机制实现了全局依赖建模,解决了RNN的串行计算问题。”

  • 展示实践能力:

    “我在项目中使用YOLOv8进行目标检测,通过数据增强和模型微调,将mAP从70%提升到85%。同时使用Transformer构建了文本分类模型。”

  • 展示学习能力:

    “我持续关注最新的技术发展,如Vision Transformer将Transformer应用于图像领域,以及YOLOv8的Anchor-Free设计。”


  • 文档版本: v1.0 最后更新: 2024年 作者: E教千问技术团队


    参考资料

    经典论文

    • Attention Is All You Need (Transformer, 2017)
    • YOLOv8 (2023)
    • Long Short-Term Memory (LSTM, 1997)

    开源项目

    • PyTorch官方文档
    • Ultralytics YOLOv8
    • Hugging Face Transformers

    学习资源

    • 深度学习花书
    • CS231n: CNN for Visual Recognition
    • CS224n: NLP with Deep Learning
    赞(0)
    未经允许不得转载:171主机测评 » 机器学习与深度学习:从基础概念到YOLOv8全解析
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址