NLP進階之(七)膨脹卷積神經網絡


NLP進階之(七)膨脹卷積神經網絡
1. Dilated Convolutions 膨脹卷積神經網絡
1.2 動態理解
1.2.2 轉置卷積動畫
1.2.3 理解
2. Dilated Convolutions 優點
3. 應用

理論來自Multi-scale context aggregation by dilated convolutions ICLR 2016
作者將代碼貢獻於github
針對語義分割問題 semantic segmentation,這里使用 dilated convolutions 得到multi-scale context 信息來提升分割效果。
1. Dilated Convolutions 膨脹卷積神經網絡
dilated convolutions:
首先來看看膨脹卷積 dilated convolutions,


圖(a):就是一個常規的3x3卷積,1-dilated convolution得到F1,F1的每個位置的卷積感受眼是3x3=9。
圖(b):在F1的基礎上,進行一個2-dilated convolution,注意它的點乘位置,不是相鄰的3x3,得到了F2,F2的每個位置的 卷積感受眼是7x7=49。
圖©:在F2的基礎上,進行一個4-dilated convolution,得到了F3,F3的每個位置的卷積感受眼是15×15=225,注意這里dilated convolution的參數數量是相同的,都是 3x3=9。

從上圖中可以看出,卷積核的參數個數保持不變,卷積感受眼的大小隨着dilation rate參數的增加呈指數增長。
1.2 動態理解
N.B.: Blue maps are inputs, and cyan maps are outputs.

 


1.2.2 轉置卷積動畫
N.B.: Blue maps are inputs, and cyan maps are outputs.

1.2.3 理解
shape of input : [batch, in_height, in_width, in_channels]
shape of filter : [filter_height, filter_width, in_channels, out_channels]

with tf.variable_scope("idcnn" if not name else name):
#shape=[1*3*120*100]
shape=[1, self.filter_width, self.embedding_dim,
self.num_filter]
print(shape)
filter_weights = tf.get_variable(
"idcnn_filter",
shape=[1, self.filter_width, self.embedding_dim,
self.num_filter],
initializer=self.initializer)
layerInput = tf.nn.conv2d(model_inputs,
filter_weights,
# 上下都是移動一步
strides=[1, 1, 1, 1],
padding="SAME",
name="init_layer",use_cudnn_on_gpu=True)
self.layerInput_test=layerInput
finalOutFromLayers = []

totalWidthForLastDim = 0
# 第一次卷積結束后就放入膨脹卷積里面進行卷積
for j in range(self.repeat_times):
for i in range(len(self.layers)):
#1,1,2:1是步長,2就是中間插了一個孔
dilation = self.layers[i]['dilation']
isLast = True if i == (len(self.layers) - 1) else False
with tf.variable_scope("atrous-conv-layer-%d" % i,
reuse=True
if (reuse or j > 0) else False):
#w 卷積核的高度,卷積核的寬度,圖像通道數,卷積核個數
w = tf.get_variable(
"filterW",
shape=[1, self.filter_width, self.num_filter,
self.num_filter],
initializer=tf.contrib.layers.xavier_initializer())
if j==1 and i==1:
self.w_test_1=w
if j==2 and i==1:
self.w_test_2=w
b = tf.get_variable("filterB", shape=[self.num_filter])
conv = tf.nn.atrous_conv2d(layerInput,
w,
rate=dilation,
padding="SAME")
self.conv_test=conv
conv = tf.nn.bias_add(conv, b)
conv = tf.nn.relu(conv)
if isLast:
finalOutFromLayers.append(conv)
totalWidthForLastDim += self.num_filter
layerInput = conv
finalOut = tf.concat(axis=3, values=finalOutFromLayers)
keepProb = 1.0 if reuse else 0.5
finalOut = tf.nn.dropout(finalOut, keepProb)
finalOut = tf.squeeze(finalOut, [1])
finalOut = tf.reshape(finalOut, [-1, totalWidthForLastDim])
self.cnn_output_width = totalWidthForLastDim
return finalOut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2. Dilated Convolutions 優點
3. 應用
擴張卷積在圖像分割、語音合成、機器翻譯、目標檢測中都有應用。
---------------------
作者:Merlin17Crystal33
來源:CSDN
原文:https://blog.csdn.net/qq_35495233/article/details/86638098
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM