目錄
舉例
單個張量與多個卷積核的分離卷積
參考資料
舉例網絡 |
分離卷積就是先在深度上分別卷積,而後再進行卷積,對應代碼爲:ide
import tensorflow as tf # [batch, in_height, in_width, in_channels] input =tf.reshape(tf.constant([2,5,3,3,8,2,6,1,1,2,5,4,7,9,2,3,-1,3], tf.float32),[1,3,3,2]) # [filter_height, filter_width, in_channels, out_channels] depthwise_filter = tf.reshape(tf.constant([3,1,-2,2,-1,-3,4,5], tf.float32),[2,2,2,1]) pointwise_filter = tf.reshape(tf.constant([-1,1], tf.float32),[1,1,2,1]) print(tf.Session().run(tf.nn.separable_conv2d(input,depthwise_filter,pointwise_filter,[1,1,1,1],"VALID"))) [[[[ 20.] [ 9.]] [[-24.] [ 29.]]]]
返回目錄學習
單個張量與多個卷積核的分離卷積spa |
對應代碼爲:code
import tensorflow as tf # [batch, in_height, in_width, in_channels] input =tf.reshape(tf.constant([2,5,3,3,8,2,6,1,1,2,5,4,7,9,2,3,-1,3], tf.float32),[1,3,3,2]) # [filter_height, filter_width, in_channels, out_channels] depthwise_filter = tf.reshape(tf.constant([3,1,-3,1,-1,7,-2,2,-5,2,7,3,-1,3,1,-3,-8,6,4,6,8,5,9,-5], tf.float32),[2,2,2,3]) pointwise_filter = tf.reshape(tf.constant([0,0,1,0,0,1,0,0,0,0,0,0], tf.float32),[1,1,6,2]) print(tf.Session().run(tf.nn.separable_conv2d(input,depthwise_filter,pointwise_filter,[1,1,1,1],"VALID"))) [[[[ 32. -7.] [ 52. -8.]] [[ 41. 0.] [ 11. -34.]]]]
返回目錄blog
參考資料input |
《圖解深度學習與神經網絡:從張量到TensorFlow實現》_張平深度學習
返回目錄io