天天看點

卷積層中的 group 參數了解

卷積層中 group 參數了解

Convolution 層的參數中有一個group參數,其意思是将對應的輸入通道與輸出通道數進行分組, 預設值為1, 也就是說預設輸出輸入的所有通道各為一組. 比如輸入資料大小為

90x100x100x32 90是資料批大小 100x100是圖像資料shape,32是通道數,要經過一個3x3x48的卷積,group預設是1,就是全連接配接的卷積層,

如果group是2,那麼對應要将輸入的32個通道分成2個16的通道,将輸出的48個通道分成2個24的通道。對輸出的2個24的通道,第一個24通道與輸入的第一個16通道進行全卷積,第二個24通道與輸入的第二個16通道進行全卷積。極端情況下,輸入輸出通道數相同,比如為24,group大小也為24,那麼每個輸出卷積核,隻與輸入的對應的通道進行卷積。

caffe官網原話是:

group (g) [default 1]: If g > 1, we restrict the connectivity of each filter to a subset of the input. Specifically, the input and output channels are separated into g groups, and the i-th output group channels will be only connected to the i-th input group channels.

mobilenet V1 是基于 tensorflow 實作的,如果現在需要利用 caffe 實作 depthwise separable convolution ,應該怎麼辦呢?

解決方法:使用卷積參數group實作。

group對輸入輸出對應分組,預設為1,也就是說預設輸出輸入的所有通道各為一組。輸出一個通道由輸入所有通道進行卷積運算。如果我們把卷積group等于輸入通道,輸出通道等于輸入通道便輕松實作了depthwize separable convolution結構。

總結

賈揚清在 https://www.zhihu.com/question/26871787 裡說 group 沒什麼用,隻是為了保證向下相容性。

不過,caffe 在實作用反卷積做上采樣的時候,用 group 參數進行了加速,具體見下面的 PR 和 issue:

https://github.com/BVLC/caffe/pull/2213

Please note that I assume you specify group: {{num_in}} in convolution_param. That results channel-wise convolution, and it is more efficient for both memory and computation.

https://github.com/BVLC/caffe/issues/3906

This filler is intended to be used with grouped convolution that makes it effectively diagonal as you outlined.

參考文章

[1]. 卷積參數group的使用

[2]. caffe group參數了解

[3]. 為什麼depthwise convolution 比 convolution更加耗時?

[4]. Depthwise卷積與Pointwise卷積

[5]. caffe架構中 LRN層有什麼作用

繼續閱讀