A4.3.9 · Machine learning approaches (HL only)
A4.3.9 · 机器学习方法(仅 HL)
Convolutional Neural Networks
卷积神经网络
A farm's sorting robot needs to tell a ripe apple from an unripe one in a photo. Feeding every pixel into a plain ANN loses the fact that nearby pixels belong together, a patch of red skin, the curve of an edge. A CNN is built to notice exactly that.
一个农场的分拣机器人需要从照片中分辨出苹果是成熟还是未成熟。如果把每个像素单独喂给一个普通的 ANN,就会丢失相邻像素本应属于一起这个事实,比如一片红色的果皮,一道边缘的弧线。CNN 正是为了留意这些而设计的。
CNNs belong to the deep learning family named in A4.1.1, but this statement asks specifically about the mechanism, not just the label.
CNN 属于 A4.1.1 中提到的深度学习家族,但本条考纲具体问的是它的机制,而不只是这个名称。
Explainer
讲解
Built for grid-shaped data
为网格状数据而生
A CNN (convolutional neural network) is a deep learning network purpose-built for data laid out on a grid, most often images. A small matrix called a kernel (filter) slides across the input, at every position performing a convolution (a weighted sum over the pixels under it) to produce a feature map that highlights where a specific pattern was detected.
卷积神经网络(CNN)是一种为网格排列的数据(最常见是图像)而设计的深度学习网络。一个称为卷积核(滤波器)的小矩阵在输入上滑动,在每个位置执行一次卷积(对其下方的像素做一次加权求和),生成一张特征图,标出检测到某个特定模式的位置。
| Layer | What it does |
|---|---|
| Input layer | Where the image enters the network, as a grid of pixel values (three grids stacked for RGB colour) |
| Convolutional layer | Slides several kernels across the input, each producing its own feature map for a specific pattern (an edge, a texture) |
| Activation function | Applied to each feature map (commonly ReLU), introducing non-linearity so complex patterns can be learned |
| Pooling layer | Shrinks each feature map (e.g. max pooling keeps only the largest value in each small block), reducing computation and making detection less sensitive to exact position |
| Fully connected layer | Flattens the surviving features into one vector and reasons over all of them together |
| Output layer | Produces the final probabilities, often via a softmax function, for each possible class |
| 层 | 它做什么 |
|---|---|
| 输入层 | 接收原始像素网格(RGB 彩色图像则是三张网格) |
| 卷积层 | 把若干个卷积核滑过输入,每个核为某种特定模式(边缘、纹理)生成自己的特征图 |
| 激活函数 | 应用于每张特征图(常用 ReLU),引入非线性,使网络能学到复杂的模式 |
| 池化层 | 压缩每张特征图(例如最大池化,只保留每个小区块中最大的值),减少计算量,并让检测对具体位置不那么敏感 |
| 全连接层 | 把留下的特征展平成一个向量,并对它们整体进行推理 |
| 输出层 | 为每个可能的类别产生最终的概率,常通过 softmax 函数实现 |
Worked example
例题
Sorting ripe from unripe apples
分拣成熟与未成熟的苹果
A tiny 6×6 patch of an apple photo, walked through the pipeline stage by stage.
一小块 6×6 的苹果照片色块,逐个阶段走过整条流水线。
Explainer
讲解
What shapes what a CNN learns
什么决定了 CNN 学到什么
| Factor | Effect |
|---|---|
| Number of layers | A shallow network learns basic features (edges, blotches of colour); a deeper network builds those up into higher-level features (a bruise shape, the pattern of a stem) |
| Kernel size | A larger kernel captures broader, more global patterns in one pass; a smaller kernel focuses on fine local detail |
| Stride | How far the kernel moves each step; a small stride keeps more detail in the resulting map, a bigger jump between positions trades that detail for less computation |
| Activation function | ReLU is common in hidden layers for speed and to reduce a known training problem (vanishing gradients) |
| Loss function | Guides training by measuring how wrong the prediction was; cross-entropy loss is common for classification |
| 因素 | 影响 |
|---|---|
| 层数 | 较浅的网络只能学到基本特征(边缘、色块);更深的网络会把这些组合成更高层的特征(一处瘀伤的形状、果梗的图案) |
| 卷积核大小 | 更大的核能在一次操作中捕捉更广、更全局的模式;更小的核专注于细节的局部特征 |
| 步幅 | 卷积核每一步移动多远;步幅小得到更精细的特征图,步幅大则更粗糙但计算更省 |
| 激活函数 | ReLU 在隐藏层中很常见,速度快,并能缓解一个已知的训练问题(梯度消失) |
| 损失函数 | 通过衡量预测有多离谱来指导训练;交叉熵损失在分类任务中很常见 |
Check your understanding
检验你的理解
What is the main purpose of a pooling layer in a CNN?
CNN 中池化层的主要目的是什么?
Common mistake
常见错误
RecurringDescribing a CNN as "a regular neural network with extra layers". The layer count is not what makes it a CNN. The defining mechanism is convolution: a kernel scanning across the grid to build feature maps that respect which pixels are near each other, something a plain, fully-connected ANN has no way to do, since it treats every input pixel as an unrelated number in a flat list.
反复出现把 CNN 描述成"层数更多的普通神经网络"。让它成为 CNN 的关键并不是层数。它的核心机制是卷积:一个卷积核在网格上扫描,构建出尊重"哪些像素彼此相邻"这一事实的特征图,这是一个普通的、全连接的 ANN 做不到的,因为它把每个输入像素都当成一个扁平列表中互不相关的数字。
Wrong: "A CNN is just an ANN with more hidden layers, which lets it handle images."
错误: "CNN 只是隐藏层更多的 ANN,这让它能处理图像。"
Right: "A CNN's convolutional layers slide a kernel across the grid, so nearby pixels are processed together and a feature map preserves where a pattern was found. A plain ANN flattens the image into a list of unrelated numbers first, losing that spatial relationship."
正确: "CNN 的卷积层让卷积核在网格上滑动,使相邻的像素被一起处理,特征图也保留了模式被发现的位置。而普通的 ANN 会先把图像展平成一串互不相关的数字,丢失了这种空间关系。"
Revision questions
复习题
Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.
采用样卷风格。写下答案,然后展开评分要点给自己打分。
[1]State one layer found in a convolutional neural network.
[1]说出卷积神经网络中的一种层。
[3]Describe how a convolutional layer processes an input image.
[3]描述卷积层如何处理一张输入图像。
Marking points
评分要点
- A kernel (small matrix of weights) slides across the input image.
- At each position it performs a convolution (a weighted sum over the pixels it covers).
- The result is a feature map showing where a specific pattern was detected.
- 一个卷积核(权重构成的小矩阵)在输入图像上滑动。
- 在每个位置执行一次卷积(对其覆盖的像素做加权求和)。
- 结果是一张特征图,显示出某个特定模式被检测到的位置。
[1]State one problem that could result from training a CNN on a set of images that still contains mislabelled or corrupted examples.
[1]说出在一组仍含有标签错误或损坏样本的图像上训练 CNN,可能引发的一个问题。
Marking points
评分要点
- The model could learn from wrong information and end up biased, or fit noise instead of the real pattern (overfitting), making its predictions on new, correctly labelled data less reliable.
- 模型可能从错误的信息中学习,导致产生偏差,或者拟合了噪声而不是真实的模式(过拟合),使它在新的、标签正确的数据上做出的预测更不可靠。
[3]Explain why the F1 score would be a more informative choice than accuracy alone for judging this apple-sorting CNN.
[3]解释为什么用 F1 分数来评判这个苹果分拣 CNN,会比单看准确率更有参考价值。
Marking points
评分要点
- If ripe apples are much more common than unripe ones on the sorting line, accuracy alone can look high even if the model rarely catches the unripe ones correctly.
- F1 combines precision and recall, so it only scores well when both wrongly-sorted ripe apples and missed unripe apples are kept low.
- Ties back to A4.3.3: F1 is the right metric whenever both a false positive and a false negative carry a real cost.
- 如果分拣线上成熟苹果比未成熟苹果多得多,即使模型很少正确抓出未成熟的苹果,准确率单独看也可能显得很高。
- F1 结合了精确率和召回率,所以只有当"误判为成熟的苹果"和"漏掉的未成熟苹果"都被控制住时,它才会得高分。
- 与 A4.3.3 相呼应:只要假阳性和假阴性都有真实代价,F1 就是合适的指标。
Flashcards
记忆卡片
Active recall for this statement’s key terms.
针对本条考纲陈述关键术语的主动回忆练习。
Keep this statement’s practice with you
把这条考纲陈述的练习保存下来
Free account: save your progress and unlock every revision question for A4.3.9, and every other IB CS 2027 statement.
免费账户:解锁 A4.3.9 以及所有其他 IB CS 2027 考纲陈述的每一道复习题,并同步你的学习进度。