最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Tensorflow tf.nn.depthwise_conv2d如何實(shí)現(xiàn)深度卷積的

 更新時(shí)間:2020年04月20日 11:52:32   作者:xf__mao  
這篇文章主要介紹了Tensorflow tf.nn.depthwise_conv2d如何實(shí)現(xiàn)深度卷積的,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

實(shí)驗(yàn)環(huán)境:tensorflow版本1.2.0,python2.7

介紹

depthwise_conv2d來源于深度可分離卷積:

Xception: Deep Learning with Depthwise Separable Convolutions

tf.nn.depthwise_conv2d(input,filter,strides,padding,rate=None,name=None,data_format=None)

除去name參數(shù)用以指定該操作的name,data_format指定數(shù)據(jù)格式,與方法有關(guān)的一共五個(gè)參數(shù):

input:
指需要做卷積的輸入圖像,要求是一個(gè)4維Tensor,具有[batch, height, width, in_channels]這樣的shape,具體含義是[訓(xùn)練時(shí)一個(gè)batch的圖片數(shù)量, 圖片高度, 圖片寬度, 圖像通道數(shù)]

filter:
相當(dāng)于CNN中的卷積核,要求是一個(gè)4維Tensor,具有[filter_height, filter_width, in_channels, channel_multiplier]這樣的shape,具體含義是[卷積核的高度,卷積核的寬度,輸入通道數(shù),輸出卷積乘子],同理這里第三維in_channels,就是參數(shù)value的第四維

strides:
卷積的滑動(dòng)步長(zhǎng)。

padding:
string類型的量,只能是”SAME”,”VALID”其中之一,這個(gè)值決定了不同邊緣填充方式。

rate:
這個(gè)參數(shù)的詳細(xì)解釋見【Tensorflow】tf.nn.atrous_conv2d如何實(shí)現(xiàn)空洞卷積?

結(jié)果返回一個(gè)Tensor,shape為[batch, out_height, out_width, in_channels * channel_multiplier],注意這里輸出通道變成了in_channels * channel_multiplier

實(shí)驗(yàn)

為了形象的展示depthwise_conv2d,我們必須要建立自定義的輸入圖像和卷積核

img1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]]]],dtype=tf.float32)
img2 = tf.constant(value=[[[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]]]],dtype=tf.float32)
img = tf.concat(values=[img1,img2],axis=3)
filter1 = tf.constant(value=0, shape=[3,3,1,1],dtype=tf.float32)
filter2 = tf.constant(value=1, shape=[3,3,1,1],dtype=tf.float32)
filter3 = tf.constant(value=2, shape=[3,3,1,1],dtype=tf.float32)
filter4 = tf.constant(value=3, shape=[3,3,1,1],dtype=tf.float32)
filter_out1 = tf.concat(values=[filter1,filter2],axis=2)
filter_out2 = tf.concat(values=[filter3,filter4],axis=2)
filter = tf.concat(values=[filter_out1,filter_out2],axis=3)

建立好了img和filter,就可以做卷積了

out_img = tf.nn.conv2d(input=img, filter=filter, strides=[1,1,1,1], padding='VALID')

好了,用一張圖來詳細(xì)展示這個(gè)過程

 

這是普通的卷積過程,我們?cè)賮砜瓷疃染矸e。

out_img = tf.nn.depthwise_conv2d(input=img, filter=filter, strides=[1,1,1,1], rate=[1,1], padding='VALID')

 

現(xiàn)在我們可以形象的解釋一下depthwise_conv2d卷積了??雌胀ǖ木矸e,我們對(duì)卷積核每一個(gè)out_channel的兩個(gè)通道分別和輸入的兩個(gè)通道做卷積相加,得到feature map的一個(gè)channel,而depthwise_conv2d卷積,我們對(duì)每一個(gè)對(duì)應(yīng)的in_channel,分別卷積生成兩個(gè)out_channel,所以獲得的feature map的通道數(shù)量可以用in_channel* channel_multiplier來表達(dá),這個(gè)channel_multiplier,就可以理解為卷積核的第四維。

代碼清單

import tensorflow as tf


img1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]]]],dtype=tf.float32)
img2 = tf.constant(value=[[[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]]]],dtype=tf.float32)
img = tf.concat(values=[img1,img2],axis=3)
filter1 = tf.constant(value=0, shape=[3,3,1,1],dtype=tf.float32)
filter2 = tf.constant(value=1, shape=[3,3,1,1],dtype=tf.float32)
filter3 = tf.constant(value=2, shape=[3,3,1,1],dtype=tf.float32)
filter4 = tf.constant(value=3, shape=[3,3,1,1],dtype=tf.float32)
filter_out1 = tf.concat(values=[filter1,filter2],axis=2)
filter_out2 = tf.concat(values=[filter3,filter4],axis=2)
filter = tf.concat(values=[filter_out1,filter_out2],axis=3)

out_img = tf.nn.depthwise_conv2d(input=img, filter=filter, strides=[1,1,1,1], rate=[1,1], padding='VALID')

輸出:

rate=1, VALID mode result:
[[[[ 0. 36. 9. 27.]
[ 0. 54. 9. 27.]]

[[ 0. 36. 9. 27.]
[ 0. 54. 9. 27.]]]]

到此這篇關(guān)于Tensorflow tf.nn.depthwise_conv2d如何實(shí)現(xiàn)深度卷積的的文章就介紹到這了,更多相關(guān)Tensorflow tf.nn.depthwise_conv2d深度卷積內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

淮阳县| 太和县| 长顺县| 浦城县| 乐都县| 宁晋县| 台北市| 临海市| 邹城市| 阜康市| 手游| 鸡西市| 鄱阳县| 长宁区| 吐鲁番市| 格尔木市| 高雄县| 土默特左旗| 瑞安市| 禄劝| 桐梓县| 垫江县| 如东县| 嘉峪关市| 工布江达县| 屏边| 汝南县| 扎兰屯市| 万山特区| 泗洪县| 永胜县| 桂东县| 阳曲县| 凤冈县| 涿州市| 奉化市| 仁怀市| 喀喇| 水城县| 隆林| 丽水市|