計算機視覺中的各種卷積(Convolution in Computer Vision)

1. 卷積與互相關Cross-correlation

在信號處理、圖像處理和其它工程/科學領域,卷積都是一種使用廣泛的技術。但是,深度學習領域的卷積本質上是信號/圖像處理領域內的互相關(cross-correlation)。這兩種操作之間存在細微的差別。
在信號/圖像處理領域,卷積的定義是:
在這裏插入圖片描述
其定義是一個函數經過反轉和位移後 g(t - t’) 和另一個函數 f(t’) 相乘得到的積f(t’) * g(t - t’) 的積分。在信號處理中,函數 g 是過濾器。它被反轉後再沿水平軸滑動。在每一個位置,我們都計算 f 和反轉後的 g 之間相交區域的面積。這個相交區域的面積就是特定位置處的卷積值。計算過程可視化如下:
在這裏插入圖片描述
在信號處理中,與標準的卷積運算不同的是互相關是兩個函數之間的滑動點積或滑動內積互相關中的過濾器不經過反轉,而是直接滑過函數 f。f 與 g 之間的交叉區域即是互相關。下圖展示了卷積與互相關之間的差異。
在這裏插入圖片描述
Note:在深度學習中,卷積中的過濾器不經過反轉嚴格來說,這是互相關,本質上是執行逐元素乘法和加法。但在深度學習中,直接將其稱之爲卷積更加方便。這沒什麼問題,因爲過濾器的權重是在訓練階段學習到的。如果上面例子中的反轉函數 g 是正確的函數,那麼經過訓練後,學習得到的過濾器看起來就會像是反轉後的函數 g。因此,在訓練之前,沒必要像在真正的卷積中那樣首先反轉過濾器。

2. 深度學習中的卷積(單通道版本,多通道版本)(single channel version, multi-channel version)

單通道和多通道也就是 filter 的個數不同,個數爲1則輸出 single channel ,個數爲多個則輸出 multi-channel。
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

3. 3D 卷積

  • 當過濾器深度與輸入層深度一樣時,在對一個 3D 體積執行卷積,仍在深度學習中稱之爲 2D 卷積。因爲這個 3D 過濾器僅沿兩個方向移動(圖像的高和寬),這種操作的輸出是一張 2D 圖像(僅有一個通道)。
    在這裏插入圖片描述
  • 而當過濾器深度小於輸入層深度(核大小<通道大小)時,3D 過濾器可以在所有三個方向(圖像的高度、寬度、通道)上移動。在每個位置,逐元素的乘法和加法都會提供一個數值。因爲過濾器是滑過一個 3D 空間,所以輸出數值也按 3D 空間排布,也就是說輸出是一個 3D 數據。
    在這裏插入圖片描述
  • 與 2D 卷積(編碼了 2D 域中目標的空間關係)類似,3D 卷積可以描述 3D 空間中目標的空間關係。對某些應用(比如生物醫學影像中的 3D 分割/重構)而言,這樣的 3D 關係很重要,比如在 CT 和 MRI 中,血管之類的目標會在 3D 空間中蜿蜒曲折。

4. 1×1 卷積

Since we talked about depth-wise operation in the previous section of 3D convolution, let’s look at another interesting operation, 1 x 1 convolution.

You may wonder why this is helpful. Do we just multiply a number to every number in the input layer? Yes and No. The operation is trivial for layers with only one channel. There, we multiply every element by a number.

Things become interesting if the input layer has multiple channels. The following picture illustrates how 1 x 1 convolution works for an input layer with dimension H x W x D. After 1 x 1 convolution with filter size 1 x 1 x D, the output channel is with dimension H x W x 1. If we apply N such 1 x 1 convolutions and then concatenate results together, we could have a output layer with dimension H x W x N.
在這裏插入圖片描述
Initially, 1 x 1 convolutions were proposed in the Network-in-network paper. They were then highly used in the Google Inception paper. A few advantages of 1 x 1 convolutions are:

  • Dimensionality reduction for efficient computations
  • Efficient low dimensional embedding, or feature pooling
  • Applying nonlinearity again after convolution

The first two advantages can be observed in the image above. After 1 x 1 convolution, we significantly reduce the dimension depth-wise. Say if the original input has 200 channels, the 1 x 1 convolution will embed these channels (features) into a single channel. The third advantage comes in as after the 1 x 1 convolution, non-linear activation such as ReLU can be added. The non-linearity allows the network to learn more complex function.

5. 卷積算術Convolution Arithmetic

6. 轉置卷積(去卷積、棋盤效應)Transposed Convolution (Deconvolution, checkerboard artifacts)

  • 對於很多網絡架構的很多應用而言,往往需要進行與普通卷積(下采樣)方向相反的轉換,即希望執行上採樣。例子包括生成高分辨率圖像以及將低維特徵圖映射到高維空間,比如在自動編碼器或語義分割中。(在後者的例子中,語義分割首先會提取編碼器中的特徵圖,然後在解碼器中恢復原來的圖像大小,使其可以分類原始圖像中的每個像素。)
  • 在傳統的方法中實現上採樣是應用插值方案或人工創建規則。而神經網絡等現代架構則傾向於讓網絡自動學習合適的變換,無需人類干預。
  • 轉置卷積在文獻中也被稱爲去卷積或 fractionally strided convolution。但是,需要指出“去卷積(deconvolution)”這個名稱並不是很合適,因爲轉置卷積並非信號/圖像處理領域定義的那種真正的去卷積(deconvolution)。從技術上講,信號處理中的去卷積是卷積運算的逆運算,但深度學習中卻不是這種運算。因此,某些作者強烈反對將轉置卷積稱爲去卷積(deconvolution)。人們稱之爲去卷積(deconvolution)主要是因爲這樣說更簡單。

計算過程可視化例子

  • 在一個 2×2 的輸入(周圍加了 2×2 的單位步長的零填充)上應用一個 3×3 核的轉置卷積。上採樣輸出的大小是 4×4。
    在這裏插入圖片描述
  • 通過應用各種填充和步長,可以將同樣的 2×2 輸入圖像映射到不同的圖像尺寸。下面,轉置卷積被用在了同一張 2×2 輸入上(輸入之間插入了一個零,並且周圍加了 2×2 的單位步長的零填充),所得輸出的大小是 5×5。
    在這裏插入圖片描述

普通卷積 / 轉置卷積的矩陣實現
定義:C 爲卷積核,Large 爲輸入圖像,Small 爲輸出圖像。經過卷積(矩陣乘法)後,可以將大圖像下采樣爲小圖像。這種矩陣乘法的卷積的實現遵照:C x Large = Small。
具體實現:如下圖例子所示,將輸入平展爲 16×1 的矩陣,並將卷積核轉換爲一個稀疏矩陣(4×16)。然後,在稀疏矩陣和平展的輸入之間使用矩陣乘法。之後,再將所得到的矩陣(4×1)轉換爲 2×2 的輸出。
在這裏插入圖片描述
在上圖中等式的兩邊都乘上矩陣的轉置 CT,並藉助“一個矩陣與其轉置矩陣的乘法得到一個單位矩陣”這一性質,那麼我們就能得到公式 CT x Small = Large,如下圖所示。實現了從小圖像到大圖像的上採樣的目標,轉置卷積中的“轉置”因此而來。
轉置矩陣的算術解釋可參閱:https://arxiv.org/abs/1603.07285
在這裏插入圖片描述
Checkerboard artifacts
One unpleasant behavior that people observe when using transposed convolution is the so-called checkerboard artifacts.
在這裏插入圖片描述

The paper “Deconvolution and Checkerboard Artifacts” has an excellent description about this behavior. Please check out this article for more details. Here, I just summarize a few key points.

Checkerboard artifacts result from “uneven overlap” of transposed convolution. Such overlap puts more of the metaphorical paint in some places than others.

In the image below, the layer on the top is the input layer, and the layer on the bottom is the output layer after transposed convolution. During transposed convolution, a layer with small size is mapped to a layer with larger size.

In the example (a), the stride is 1 and the filer size is 2. As outlined in red, the first pixel on the input maps to the first and second pixels on the output. As outlined in green, the second pixel on the input maps to the second and the third pixels on the output. The second pixel on the output receives information from both the first and the second pixels on the input. Overall, the pixels in the middle portion of the output receive same amount of information from the input. Here exist a region where kernels overlapped. As the filter size is increased to 3 in the example (b), the center portion that receives most information shrinks. But this may not be a big deal, since the overlap is still even. The pixels in the center portion of the output receive same amount of information from the input.
在這裏插入圖片描述
Now for the example below, we change stride = 2. In the example (a) where filter size = 2, all pixels on the output receive same amount of information from the input. They all receive information from a single pixel on the input. There is no overlap of transposed convolution here.
在這裏插入圖片描述

If we change the filter size to 4 in the example (b), the evenly overlapped region shrinks. But still, one can use the center portion of the output as the valid output, where each pixel receives the same amount of information from the input.

However, things become interesting if we change the filter size to 3 and 5 in the example © and (d). For these two cases, every pixel on the output receives different amount of information compared to its adjacent pixels. One cannot find a continuous and evenly overlapped region on the output.

The transposed convolution has uneven overlap when the filter size is not divisible by the stride. This “uneven overlap” puts more of the paint in some places than others, thus creates the checkerboard effects. In fact, the unevenly overlapped region tends to be more extreme in two dimensions. There, two patterns are multiplied together, the unevenness gets squared.

Two things one could do to reduce such artifacts, while applying transposed convolution. First, make sure you use a filer size that is divided by your stride, avoiding the overlap issue. Secondly, one can use transposed convolution with stride = 1, which helps to reduce the checkerboard effects. However, artifacts can still leak through, as seen in many recent models.

The paper further proposed a better up-sampling approach: resize the image first (using nearest-neighbor interpolation or bilinear interpolation) and then do a convolutional layer. By doing that, the authors avoid the checkerboard effects. You may want to try it for your applications.

7. 擴張卷積Dilated Convolution (Atrous Convolution)

別名空洞卷積,膨脹卷積,多孔卷積,帶孔卷積
擴張卷積由這兩篇論文引入:

這是一個標準的卷積:
在這裏插入圖片描述
擴張卷積如下:
在這裏插入圖片描述
直觀而言,擴張卷積就是通過在覈元素之間插入空格來使核“膨脹”。新增的參數 l(擴張率)表示希望將核加寬的程度。具體實現可能各不相同,但通常是在覈元素之間插入 l-1 個空格。下圖展示了 l = 1, 2, 4 時的核大小。
在這裏插入圖片描述

由圖可見,l=1 時感受野爲 3×3,l=2 時爲 7×7。l=3 時,感受野的大小就增加到了 15×15。值得注意的是,與這些操作相關的參數數量是相等的,均爲3x3。從而說明「觀察」更大的感受野不會有額外的成本。因此,擴張卷積可用於廉價地增大輸出單元的感受野,而不會增大其核大小,這在多個擴張卷積彼此堆疊時尤其有效。

8. 可分卷積(空間可分卷積,深度可分卷積) (Spatially Separable Convolution, Depthwise Separable Convolution)

1、空間可分卷積
空間可分卷積操作的是圖像的 2D 空間維度,即高和寬。從概念上看,空間可分卷積是將一個卷積分解爲兩個單獨的運算。對於下面的示例,3×3 的 Sobel 核被分成了一個 3×1 核和一個 1×3 核。
在這裏插入圖片描述
在卷積中,3×3 核直接與圖像卷積。在空間可分卷積中,3×1 核首先與圖像卷積,然後再應用 1×3 核卷積。這樣,執行同樣的操作時僅需 6 個參數,而不是 9 個。此外,使用空間可分卷積時所需的矩陣乘法也更少。例如,5×5 圖像與 3×3 核的卷積(步幅=1,填充=0)要求在 3 個位置水平地掃描核(還有 3 個垂直的位置),總共就是 9 個位置,表示爲下圖中的點。在每個位置,會應用 9 次逐元素乘法。總共就是 9×9=81 次乘法。
在這裏插入圖片描述
另一方面,對於空間可分卷積,首先在 5×5 的圖像上應用一個 3×1 的過濾器,可以在水平 5 個位置和垂直 3 個位置掃描這樣的核。總共就是 5×3=15 個位置,表示爲下圖中的點。在每個位置,會應用 3 次逐元素乘法。總共就是 15×3=45 次乘法。現在得到了一個 3×5 的矩陣。這個矩陣再與一個 1×3 核卷積,即在水平 3 個位置和垂直 3 個位置掃描這個矩陣。對於這 9 個位置中的每一個,應用 3 次逐元素乘法。這一步需要 9×3=27 次乘法。因此,總體而言,空間可分卷積需要 45+27=72 次乘法,少於普通卷積。
在這裏插入圖片描述
一般化推廣
假設現在將卷積應用於一張 N×N 的圖像上,卷積核爲 m×m,步幅爲 1,填充爲 0。傳統卷積需要 (N-2) x (N-2) x m x m 次乘法,空間可分卷積需要 N x (N-2) x m + (N-2) x (N-2) x m = (2N-2) x (N-2) x m 次乘法。空間可分卷積與標準卷積的計算成本比爲:
在這裏插入圖片描述
因爲圖像尺寸 N 遠大於過濾器大小(N>>m),所以這個比就變成了 2/m。也就是說,在這種漸進情況(N>>m)下,當過濾器大小爲 3×3 時,空間可分卷積的計算成本是標準卷積的 2/3。過濾器大小爲 5×5 時這一數值是 2/5;過濾器大小爲 7×7 時則爲 2/7。
存在的問題
儘管空間可分卷積能節省成本,但深度學習卻很少使用它。一大主要原因是並非所有的核都能分成兩個更小的核。如果用空間可分卷積替代所有的傳統卷積,那麼就限制了在訓練過程中搜索所有可能的核。這樣得到的訓練結果可能是次優的。
2、深度可分卷積
首先快速回顧標準的 2D 卷積。舉一個具體例子,假設輸入層的大小是 7×7×3(高×寬×通道),而過濾器的大小是 3×3×3。經過與一個過濾器的 2D 卷積之後,輸出層的大小是 5×5×1(僅有一個通道)。
在這裏插入圖片描述
一般來說,兩個神經網絡層之間會應用多個過濾器。假設這裏有 128 個過濾器。在應用了這 128 個 2D 卷積之後,將有 128 個 5×5×1 的輸出映射圖(map)。然後將這些映射圖堆疊成大小爲 5×5×128 的單層。通過這種操作,可將輸入層(7×7×3)轉換成輸出層(5×5×128)。空間維度(即高度和寬度)會變小,而深度會增大。
在這裏插入圖片描述
使用深度可分卷積,目的就是利用1×1 卷積覈實現同樣的變換。

  • 首先,將深度卷積應用於輸入層。但不使用 2D 卷積中大小爲 3×3×3 的單個過濾器,而是分開使用 3 個核。每個過濾器的大小爲 3×3×1。每個核與輸入層的一個通道卷積。每個這樣的卷積都能提供大小爲 5×5×1 的映射圖。然後將這些映射圖堆疊在一起,創建一個 5×5×3 的圖像。經過這個操作之後,就可以得到大小爲 5×5×3 的輸出。

在這裏插入圖片描述

  • 然後,爲了擴展深度,應用128個核大小爲 1×1×3 的 1×1 卷積。將 5×5×3 的輸入圖像與每個 1×1×3 的核卷積,可得到大小爲 5×5×128 的映射圖。

在這裏插入圖片描述
下圖展示了深度可分卷積的整個過程:
在這裏插入圖片描述
深度可分卷積的優點

  • 2D 普通卷積例子中的計算成本,有 128 個 3×3×3 個核移動了 5×5 次,也就是 128 x 3 x 3 x 3 x 5 x 5 = 86400 次乘法。而在深度可分卷積中,第一個深度卷積步驟,有 3 個 3×3×1 核移動 5×5 次,也就是 3x3x3x1x5x5 = 675 次乘法。在 1×1 卷積的第二步,有 128 個 1×1×3 核移動 5×5 次,即 128 x 1 x 1 x 3 x 5 x 5 = 9600 次乘法。因此,深度可分卷積共有 675 + 9600 = 10275 次乘法。這樣的成本大概僅有 2D 卷積的 12%
  • 一般化說明效率高。對於大小爲 H×W×D 的輸入圖像,如果使用 Nc 個大小爲 h×h×D 的核執行 2D 卷積(步幅爲 1,填充爲 0,其中 h 是偶數)。爲了將輸入層(H×W×D)變換到輸出層((H-h+1)x (W-h+1) x Nc),所需的總乘法次數爲:Nc x h x h x D x (H-h+1) x (W-h+1)。另一方面,對於同樣的變換,深度可分卷積所需的乘法次數爲:D x h x h x 1 x (H-h+1) x (W-h+1) + Nc x 1 x 1 x D x (H-h+1) x (W-h+1) = (h x h + Nc) x D x (H-h+1) x (W-h+1)。則深度可分卷積與 2D 卷積所需的乘法次數比爲:
    在這裏插入圖片描述
    現代大多數架構的輸出層通常都有很多通道,可達數百甚至上千。對於這樣的層(Nc >> h),則上式可約簡爲 1 / h²。基於此,如果使用 3×3 過濾器,則 2D 卷積所需的乘法次數是深度可分卷積的 9 倍。如果使用 5×5 過濾器,則 2D 卷積所需的乘法次數是深度可分卷積的 25 倍。

深度可分卷積的壞處
因爲利用1x1的卷積核來代替3x3卷積核以達到相同的 channel 深度,從而降低了卷積中參數的數量。因此,對於較小的模型而言,如果用深度可分卷積替代 2D 卷積,模型的表達能力可能會顯著下降,致使得到的模型可能是次優的。但是,如果使用得當,深度可分卷積能在不降低模型性能的前提下實現效率的提升。

9. 平展卷積Flattened Convolution

The flattened convolution was introduced in the paper “Flattened convolutional neural networks for feedforward acceleration”. Intuitively, the idea is to apply filter separation. Instead of applying one standard convolution filter to map the input layer to an output layer, we separate this standard filter into 3 1D filters. Such idea is similar as that in the spatial separable convolution described above, where a spatial filter is approximated by two rank-1 filters.

在這裏插入圖片描述

One should notice that if the standard convolution filter is a rank-1 filter, such filter can always be separated into cross-products of three 1D filters. But this is a strong condition and the intrinsic rank of the standard filter is higher than one in practice. As pointed out in the paper “As the difficulty of classification problem increases, the more number of leading components is required to solve the problem… Learned filters in deep networks have distributed eigenvalues and applying the separation directly to the filters results in significant information loss.”

To alleviate such problem, the paper “Flattened Convolutional Neural Networks for Feedforward Acceleration” restricts connections in receptive fields so that the model can learn 1D separated filters upon training. The paper claims that by training with flattened networks that consists of consecutive sequence of 1D filters across all directions in 3D space provides comparable performance as standard convolutional networks, with much less computation costs due to the significant reduction of learning parameters.

10. 分組卷積Grouped Convolution

AlexNet 論文在 2012 年引入了分組卷積。實現分組卷積的主要原因是讓網絡訓練可在 2 個內存有限(每個 GPU 有 1.5 GB 內存)的 GPU 上進行。下面圖中的 AlexNet 表明在大多數層中都有兩個分開的卷積路徑。這是在兩個 GPU 上執行模型並行化(當然如果可以使用更多 GPU,還能執行多 GPU 並行化)。
在這裏插入圖片描述
分組卷積的工作方式
首先,典型的 2D 卷積的步驟如下圖所示。在這個例子中,通過應用 128 個大小爲 3×3×3 的過濾器將輸入層(7×7×3)變換到輸出層(5×5×128)。推廣而言,即通過應用 Dout 個大小爲 h x w x Din 的核將輸入層(Hin x Win x Din)變換到輸出層(Hout x Wout x Dout)。
在這裏插入圖片描述
在分組卷積中,過濾器會被分爲 不同的組 。每一組都負責 特定深度 的典型 2D 卷積。
在這裏插入圖片描述
上圖展示了具有兩個過濾器分組的分組卷積。在每個過濾器分組中,每個過濾器的深度僅有名義上的 2D 卷積的一半。它們的深度是 Din/2。每個過濾器分組包含 Dout/2 個過濾器。第一個過濾器分組(紅色)與輸入層的前一半([:, :, 0:Din/2])卷積,而第二個過濾器分組(橙色)與輸入層的後一半([:, :, Din/2:Din])卷積。因此,每個過濾器分組都會創建 Dout/2 個通道。整體而言,兩個分組會創建 2×Dout/2 = Dout 個通道。然後我們將這些通道堆疊在一起,得到有 Dout 個通道的輸出層。

分組卷積的優點

  • 第一個優點是高效訓練。因爲卷積被分成了多個路徑,每個路徑都可由不同的 GPU 分開處理,所以模型可以並行方式在多個 GPU 上進行訓練。相比於在單個 GPU 上完成所有任務,這樣的在多個 GPU 上的模型並行化能讓網絡在每個步驟處理更多圖像。人們一般認爲模型並行化比數據並行化更好。後者是將數據集分成多個批次,然後分開訓練每一批。但是,當批量大小變得過小時,我們本質上是執行隨機梯度下降,而非批梯度下降。這會造成更慢,有時候更差的收斂結果。在訓練非常深的神經網絡時,分組卷積會非常重要,正如在 ResNeXt 中那樣。
    在這裏插入圖片描述
  • 第二個優點是模型會更高效,即模型參數會隨過濾器分組數的增大而減少。在之前的例子中,完整的標準 2D 卷積有 h x w x Din x Dout 個參數。具有 2 個過濾器分組的分組卷積有 (h x w x Din/2 x Dout/2) x 2 個參數。參數數量減少了一半。
  • 第三個優點模型性能更好。分組卷積也許能提供比標準完整 2D 卷積更好的模型。另一篇出色的博客已經解釋了這一點:https://blog.yani.io/filter-group-tutorial。這裏簡要總結一下。

模型性能更好的原因和稀疏過濾器的關係有關。下圖是相鄰層過濾器的相關性。其中的關係是稀疏的。
在這裏插入圖片描述
分組矩陣的相關性映射圖如下
在這裏插入圖片描述
上圖是當用 1、2、4、8、16 個過濾器分組訓練模型時,相鄰層的過濾器之間的相關性。那篇文章提出了一個推理:過濾器分組的效果是在通道維度上學習塊對角結構的稀疏性……在網絡中,具有高相關性的過濾器是使用過濾器分組以一種更爲結構化的方式學習到。從效果上看,不必學習的過濾器關係就不再參數化。這樣顯著地減少網絡中的參數數量能使其不容易過擬合,因此,一種類似正則化的效果讓優化器可以學習得到更準確更高效的深度網絡。 此外,每個過濾器分組都會學習數據的一個獨特表徵。正如 AlexNet 的作者指出的那樣,過濾器分組似乎會將學習到的過濾器結構性地組織成兩個不同的分組——黑白過濾器和彩色過濾器。
在這裏插入圖片描述

11. 混洗分組卷積Shuffled Grouped Convolution

Shuffled grouped convolution was introduced in the ShuffleNet from Magvii Inc (Face++). ShuffleNet is a computation-efficient convolution architecture, which is designed specially for mobile devices with very limited computing power (e.g. 10–150 MFLOPs).

The ideas behind the shuffled grouped convolution are linked to the ideas behind grouped convolution (used in MobileNet and ResNeXt for examples) and depthwise separable convolution (used in Xception).

Overall, the shuffled grouped convolution involves grouped convolution and channel shuffling.

In the section about grouped convolution, we know that the filters are separated into different groups. Each group is responsible for a conventional 2D convolutions with certain depth. The total operations are significantly reduced. For examples in the figure below, we have 3 filter groups. The first filter group convolves with the red portion in the input layer. Similarly, the second and the third filter group convolves with the green and blue portions in the input. The kernel depth in each filter group is only 1/3 of the total channel count in the input layer. In this example, after the first grouped convolution GConv1, the input layer is mapped to the intermediate feature map. This feature map is then mapped to the output layer through the second grouped convolution GConv2.
在這裏插入圖片描述
Grouped convolution is computationally efficient. But the problem is that each filter group only handles information passed down from the fixed portion in the previous layers. For examples in the image above, the first filter group (red) only process information that is passed down from the first 1/3 of the input channels. The blue filter group (blue) only process information that is passed down from the last 1/3 of the input channels. As such, each filter group is only limited to learn a few specific features. This property blocks information flow between channel groups and weakens representations during training. To overcome this problem, we apply the channel shuffle.

The idea of channel shuffle is that we want to mix up the information from different filter groups. In the image below, we get the feature map after applying the first grouped convolution GConv1 with 3 filter groups. Before feeding this feature map into the second grouped convolution, we first divide the channels in each group into several subgroups. The we mix up these subgroups.
在這裏插入圖片描述
After such shuffling, we continue performing the second grouped convolution GConv2 as usual. But now, since the information in the shuffled layer has already been mixed, we essentially feed each group in GConv2 with different subgroups in the feature map layer (or in the input layer). As a result, we allow the information flow between channels groups and strengthen the representations.

12. 逐點分組卷積Pointwise Grouped Convolution

The ShuffleNet paper also introduced the pointwise grouped convolution. Typically for grouped convolution such as in MobileNet or ResNeXt, the group operation is performed on the 3x3 spatial convolution, but not on 1 x 1 convolution.

The shuffleNet paper argues that the 1 x 1 convolution are also computationally costly. It suggests applying group convolution for 1 x 1 convolution as well. The pointwise grouped convolution, as the name suggested, performs group operations for 1 x 1 convolution. The operation is identical as for grouped convolution, with only one modification — performing on 1x1 filters instead of NxN filters (N>1).

In the ShuffleNet paper, authors utilized three types of convolutions we have learned: (1) shuffled grouped convolution; (2) pointwise grouped convolution; and (3) depthwise separable convolution. Such architecture design significantly reduces the computation cost while maintaining the accuracy. For examples the classification error of ShuffleNet and AlexNet is comparable on actual mobile devices. However, the computation cost has been dramatically reduced from 720 MFLOPs in AlexNet down to 40–140 MFLOPs in ShuffleNet. With relatively small computation cost and good model performance, ShuffleNet gained popularity in the field of convolutional neural net for mobile devices.

13. 動態卷積Dynamic Convolution

請參考我的另一篇博客:Dynamic Convolution: Attention over Convolution Kernels

代碼實現(Pytorch)

持續更新中

在這裏插入代碼片

參考文獻

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章