Skip to content

Commit 91e5824

Browse files
zsdonghaonebulaV
authored andcommitted
update Depthwiseconv2d with rate (#369)
* update DepthwiseConv2d with rate * update DepthwiseConv2d - params names
1 parent 0840f17 commit 91e5824

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tensorlayer/layers/convolution.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,8 @@ class DepthwiseConv2d(Layer):
15611561
The activation function of this layer.
15621562
padding : str
15631563
The padding algorithm type: "SAME" or "VALID".
1564+
rate: tuple of 2 int
1565+
The dilation rate in which we sample input values across the height and width dimensions in atrous convolution. If it is greater than 1, then all values of strides must be 1.
15641566
W_init : initializer
15651567
The initializer for the weight matrix.
15661568
b_init : initializer or None
@@ -1574,28 +1576,29 @@ class DepthwiseConv2d(Layer):
15741576
15751577
Examples
15761578
---------
1577-
>>> t_im = tf.placeholder("float32", (None, 256, 256, 3))
1578-
>>> net = InputLayer(t_im, name='in')
1579-
>>> net = DepthwiseConv2d(net, 32, (3, 3), (1, 1, 1, 1), tf.nn.relu, padding="SAME", name='dep')
1580-
>>> print(net.outputs.get_shape())
1581-
... (?, 256, 256, 96)
1579+
>>> x = tf.placeholder(tf.float32, shape=[None, 28, 28, 1], name='x')
1580+
>>> n = InputLayer(x, name='in')
1581+
>>> n = Conv2d(n, 32, (3, 3), (2, 2), act=tf.nn.relu, name='c1')
1582+
>>> n = DepthwiseConv2d(n, 1, (3, 3), (1, 1), name='d1')
1583+
>>> print(n.outputs.get_shape())
1584+
... (?, 14, 14, 32)
15821585
15831586
References
15841587
-----------
15851588
- tflearn's `grouped_conv_2d <https://github.com/tflearn/tflearn/blob/3e0c3298ff508394f3ef191bcd7d732eb8860b2e/tflearn/layers/conv.py>`__
15861589
- keras's `separableconv2d <https://keras.io/layers/convolutional/#separableconv2d>`__
15871590
1588-
"""
1591+
""" # # https://zhuanlan.zhihu.com/p/31551004 https://github.com/xiaohu2015/DeepLearning_tutorials/blob/master/CNNs/MobileNet.py
15891592

15901593
def __init__(
15911594
self,
15921595
layer,
1593-
# n_filter = 32,
1594-
channel_multiplier=3,
1596+
channel_multiplier=1,
15951597
shape=(3, 3),
15961598
strides=(1, 1),
15971599
act=tf.identity,
15981600
padding='SAME',
1601+
rate=(1, 1),
15991602
W_init=tf.truncated_normal_initializer(stddev=0.02),
16001603
b_init=tf.constant_initializer(value=0.0),
16011604
W_init_args=None,
@@ -1629,13 +1632,13 @@ def __init__(
16291632

16301633
with tf.variable_scope(name):
16311634
W = tf.get_variable(
1632-
name='W_sepconv2d', shape=shape, initializer=W_init, dtype=D_TYPE,
1635+
name='W_depthwise2d', shape=shape, initializer=W_init, dtype=D_TYPE,
16331636
**W_init_args) # [filter_height, filter_width, in_channels, channel_multiplier]
16341637
if b_init:
1635-
b = tf.get_variable(name='b_sepconv2d', shape=(pre_channel * channel_multiplier), initializer=b_init, dtype=D_TYPE, **b_init_args)
1636-
self.outputs = act(tf.nn.depthwise_conv2d(self.inputs, W, strides=strides, padding=padding) + b)
1638+
b = tf.get_variable(name='b_depthwise2d', shape=(pre_channel * channel_multiplier), initializer=b_init, dtype=D_TYPE, **b_init_args)
1639+
self.outputs = act(tf.nn.depthwise_conv2d(self.inputs, W, strides=strides, padding=padding, rate=rate) + b)
16371640
else:
1638-
self.outputs = act(tf.nn.depthwise_conv2d(self.inputs, W, strides=strides, padding=padding))
1641+
self.outputs = act(tf.nn.depthwise_conv2d(self.inputs, W, strides=strides, padding=padding, rate=rate))
16391642

16401643
self.all_layers = list(layer.all_layers)
16411644
self.all_params = list(layer.all_params)

0 commit comments

Comments
 (0)