cnn卷積神經網絡
Convolutional neural networks (CNNs) are the most popular machine leaning models for image and video analysis.
卷積神經網絡(CNN)是用于圖像和視訊分析的最流行的機器學習模型。
示例任務 (Example Tasks)
Here are some example tasks that can be performed with a CNN:
以下是一些可以使用CNN執行的示例任務:
-
Binary Classification: given an input image from a medical scan, determine if the patient has a lung nodule (1) or not (0)
二進制分類:給定來自醫學掃描的輸入圖像,确定患者是否患有肺結節(1)(0)
-
Multilabel Classification: given an input image from a medical scan, determine if the patient has none, some, or all of the following: lung opacity, nodule, mass, atelectasis, cardiomegaly, pneumothorax
多标簽分類:給定來自醫學掃描的輸入圖像,确定患者是否患有以下疾病:肺渾濁,結節,腫塊,肺不張,心髒肥大,氣胸
CNN如何運作 (How CNNs Work)
In a CNN, a convolutional filter slides across an image to produce a feature map (which is labeled “convolved feature” in the image below):
在CNN中,卷積濾鏡會在圖像上滑動以生成特征圖(下圖中标記為“卷積特征”):
A filter detects a pattern.
過濾器檢測圖案。
High values in the output feature map are produced when the filter passes over an area of the image containing the pattern.
當濾鏡經過包含圖案的圖像區域時,将在輸出要素圖中産生較高的值。
Different filters detect different patterns.
不同的過濾器檢測不同的模式。
The kind of pattern that a filter detects is determined by the filter’s weights, which are shown as red numbers in the animation above.
過濾器檢測到的模式類型取決于過濾器的權重,權重在上方的動畫中顯示為紅色數字。
A filter weight gets multiplied against the corresponding pixel value, and then the results of these multiplications are summed up to produce the output value that goes in the feature map.
将濾鏡權重與相應的像素值相乘,然後将這些相乘的結果相加,以生成輸出到特征圖中的輸出值。
A convolutional neural network involves applying this convolution operation many time, with many different filters.
卷積神經網絡需要使用許多不同的濾波器多次應用此卷積運算。
This figure shows the first layer of a CNN:
此圖顯示了CNN的第一層:

Radiopedia) Radiopedia )
In the diagram above, a CT scan slice is the input to a CNN. A convolutional filter labeled “filter 1” is shown in red. This filter slides across the input CT slice to produce a feature map, shown in red as “map 1.”
在上圖中,CT掃描切片是CNN的輸入。 标記為“過濾器1”的卷積過濾器以紅色顯示。 該濾鏡在輸入CT切片上滑動以生成特征圖,以紅色顯示為“圖1”。
Then a different filter called “filter 2” (not explicitly shown) which detects a different pattern slides across the input CT slice to produce feature map 2, shown in purple as “map 2.”
然後,一個稱為“過濾器2”(未明确顯示)的不同過濾器會在輸入的CT切片上滑動,以檢測不同的模式,以生成特征圖2,以紫色顯示為“圖2”。
This process is repeated for filter 3 (producing map 3 in yellow), filter 4 (producing map 4 in blue) and so on, until filter 8 (producing map 8 in red).
對濾鏡3(以黃色生成圖3),濾鏡4(以藍色生成圖4)等重複此過程,直到濾鏡8(以紅色生成圖8)。
This is the “first layer” of the CNN. The output of the first layer is thus a 3D chunk of numbers, consisting in this example of 8 different 2D feature maps.
這是CNN的“第一層”。 是以,第一層的輸出是3D數字塊,在此示例中包含8個不同的2D特征圖。
Image by Author 圖檔作者
Next we go to the second layer of the CNN, which is shown above. We take our 3D representation (of 8 feature maps) and apply a filter called “filter a” to this. “Filter a” (in gray) is part of the second layer of the CNN. Notice that “filter a” is actually three dimensional, because it has a little 2×2 square of weights on each of the 8 different feature maps. Therefore the size of “filter a” is 8 x 2 x 2. In general, the filters in a “2D” CNN are 3D, and the filters in a “3D” CNN are 4D.
接下來,我們進入CNN的第二層,如上所示。 我們采用3D表示法(包含8個要素圖),并對此應用一個稱為“ filter a”的過濾器。 “過濾器a”(灰色)是CNN第二層的一部分。 請注意,“過濾器a”實際上是三維的,因為在8個不同的特征圖中,每個過濾器的權重隻有2×2平方。 是以,“過濾器a”的大小為8 x 2 x2。通常,“ 2D” CNN中的過濾器為3D,而“ 3D” CNN中的過濾器為4D。
We slide filter a across the representation to produce map a, shown in grey. Then, we slide filter b across to get map b, and filter c across to get map c, and so on. This completes the second layer of the CNN.
我們在表示中滑動濾鏡a,以生成地圖a,以灰色顯示。 然後,我們将過濾器b滑到地圖b上,将過濾器c滑到地圖c上,依此類推。 這樣就完成了CNN的第二層。
We can then continue on to a third layer, a fourth layer, etc. for however many layers of the CNN are desired. CNNs can have many layers. As an example, a ResNet-18 CNN architecture has 18 layers.
然後,我們可以繼續進行到第三層,第四層等,因為需要CNN的許多層。 CNN可以有很多層。 例如,ResNet-18 CNN體系結構具有18層。
The figure below, from Krizhevsky et al., shows example filters from the early layers of a CNN. The filters early on in a CNN detect simple patterns like edges and lines going in certain directions, or simple color combinations.
下圖來自Krizhevsky等人 ,顯示了來自CNN早期層的示例過濾器。 CNN早期的濾鏡可檢測簡單的圖案,例如沿特定方向延伸的邊緣和線條,或簡單的顔色組合。
The figure below, from Siegel et al. adapted from Lee et al., shows examples of early layer filters at the bottom, intermediate layer filters in the middle, and later layer filters at the top.
下圖來自Siegel等。 改編自李等人。 的示例在底部顯示早期層過濾器,在中間顯示中間層過濾器,在頂部顯示較後層過濾器。
The early layer filters once again detect simple patterns like lines going in certain directions, while the intermediate layer filters detect more complex patterns like parts of faces, parts of cars, parts of elephants, and parts of chairs. The later layer filters detect patterns that are even more complicated, like whole faces, whole cars, etc. In this visualization each later layer filter is visualized as a weighted linear combination of the previous layer’s filters.
早期的層過濾器再次檢測簡單的圖案,例如沿特定方向的線條,而中間層的過濾器檢測更複雜的圖案,例如面部,汽車部分,大象部分和椅子部分。 後面的圖層過濾器檢測甚至更複雜的模式,例如整張臉,整輛汽車等。在此可視化中,每個後面的圖層過濾器都可視為上一層過濾器的權重線性組合。
如何學習過濾器 (How to Learn the Filters)
How do we know what feature values to use inside of each filter? We learn the feature values from the data. This is the “learning” part of “machine learning” or “deep learning.”
我們如何知道在每個過濾器内部使用哪些特征值? 我們從資料中學習特征值。 這是“機器學習”或“深度學習”的“學習”部分。
Steps:
腳步:
-
Randomly initialize the feature values (weights). At this stage, the model produces garbage — its predictions are completely random and have nothing to do with the input.
随機初始化特征值(權重)。 在此階段,模型産生垃圾-其預測完全是随機的,與輸入無關。
-
Repeat the following steps for a bunch of training examples: (a) Feed a training example to the model (b) Calculate how wrong the model was using the loss function (c) Use the backpropagation algorithm to make tiny adjustments to the feature values (weights), so that the model will be less wrong next time. As the model becomes less and less wrong with each training example, it will ideally learn how to perform the task very well by the end of training.
對一堆訓練示例重複以下步驟:(a)向模型提供訓練示例(b)使用損失函數計算模型的錯誤程度(c)使用反向傳播算法對特征值進行微小調整(權重),這樣下次模型就不會出錯了。 随着模型在每個訓練示例中的錯誤越來越少,理想情況下,它将在訓練結束之前學習如何很好地執行任務。
-
Evaluate model on test examples it’s never seen before. The test examples are images that were set aside and not used in training. If the model does well on the test examples, then it’s learned generalizable principles and is a useful model. If the model does badly on the test examples, then it’s memorized the training data and is a useless model.
根據前所未有的測試示例評估模型。 測試示例是被擱置而未在訓練中使用的圖像。 如果該模型在測試示例上運作良好,那麼它就可以學習通用原則,并且是有用的模型。 如果該模型在測試示例上表現不佳,則它會記住訓練資料,并且是無用的模型。
The following animation created by Tamas Szilagyi shows a neural network model learning. The animation shows a feedforward neural network rather than a convolutional neural network, but the learning principle is the same. In this animation each line represents a weight. The number shown next to the line is the weight value. The weight value changes as the model learns.
由Tamas Szilagyi建立的以下動畫顯示了神經網絡模型學習。 動畫顯示的是前饋神經網絡,而不是卷積神經網絡,但是學習原理是相同的。 在此動畫中,每條線代表一個權重。 該行旁邊顯示的數字是重量值。 權重值随模型學習而變化。
衡量績效:AUROC (Measuring Performance: AUROC)
Image by Author 圖檔作者
One popular performance metric for CNNs is the AUROC, or area under the receiver operating characteristic. This performance metric indicates whether the model can correctly rank examples. The AUROC is the probability that a randomly selected positive example has a higher predicted probability of being positive than a randomly selected negative example. An AUROC of 0.5 corresponds to a coin flip or useless model, while an AUROC of 1.0 corresponds to a perfect model.
CNN的一種流行性能名額是AUROC,即接收機工作特性下的面積。 此性能名額訓示模型是否可以正确對示例進行排名。 AUROC是随機選擇的陽性示例比随機選擇的陰性示例具有更高的陽性預測機率的機率。 AUROC為0.5對應于硬币翻轉或無用模型,而AUROC為1.0對應于理想模型。
附加閱讀 (Additional Reading)
For more details about CNNs, see:
有關CNN的更多詳細資訊,請參閱:
-
How Computers See: Intro to Convolutional Neural Networks
計算機的外觀:卷積神經網絡簡介
-
The History of Convolutional Neural Networks
卷積神經網絡的曆史
-
Convolution vs. Cross-Correlation
卷積與互相關
For more details about how neural networks learn, see Introduction to Neural Networks.
有關神經網絡學習方式的更多詳細資訊,請參見《神經網絡簡介》 。
Finally, for more details about AUROC, see:
最後,有關AUROC的更多詳細資訊,請參見:
-
Measuring Performance: AUC (AUROC)
測量性能:AUC(AUROC)
-
The Complete Guide to AUC and Average Precision: Simulations nad Visualizations
AUC和平均精度的完整指南:模拟和可視化
Originally published at http://glassboxmedicine.com on August 3, 2020.
最初于 2020年8月3日 釋出在 http://glassboxmedicine.com 上。
翻譯自: https://towardsdatascience.com/convolutional-neural-networks-cnns-in-5-minutes-dc86d0e27e1e
cnn卷積神經網絡