Skip to content

Commit 783929e

Browse files
committed
add 3D Deconvolutional Layer
1 parent f5a91c0 commit 783929e

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

docs/modules/layers.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ In addition, if you want to update the parameters of previous 2 layers at the sa
264264
DropconnectDenseLayer
265265
Conv2dLayer
266266
Conv3dLayer
267+
DeConv3dLayer
267268
PoolLayer
268269
RNNLayer
269270
FlattenLayer
@@ -360,7 +361,7 @@ so to implement 1D CNN, you can use Reshape layer as follow.
360361
^^^^^^^^^^^^^^^^^^^^^^^
361362

362363
.. autoclass:: Conv3dLayer
363-
364+
.. autoclass:: DeConv3dLayer
364365

365366
Pooling layer
366367
----------------

tensorlayer/layers.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,71 @@ def __init__(
11141114
self.all_layers.extend( [self.outputs] )
11151115
self.all_params.extend( [W, b] )
11161116

1117+
class DeConv3dLayer(Layer):
1118+
"""
1119+
The :class:`DeConv3dLayer` class is deconvolutional 3D layer, see `tf.nn.conv3d_transpose`.
1120+
1121+
Parameters
1122+
----------
1123+
layer : a :class:`Layer` instance
1124+
The `Layer` class feeding into this layer.
1125+
act : activation function
1126+
The function that is applied to the layer activations.
1127+
shape : list of shape
1128+
shape of the filters, [depth, height, width, output_channels, in_channels], filter's in_channels dimension must match that of value.
1129+
output_shape : list of output shape
1130+
representing the output shape of the deconvolution op.
1131+
strides : a list of ints.
1132+
The stride of the sliding window for each dimension of the input tensor.
1133+
padding : a string from: "SAME", "VALID".
1134+
The type of padding algorithm to use.
1135+
W_init : weights initializer
1136+
The initializer for initializing the weight matrix.
1137+
b_init : biases initializer
1138+
The initializer for initializing the bias vector.
1139+
W_init_args : dictionary
1140+
The arguments for the weights initializer.
1141+
b_init_args : dictionary
1142+
The arguments for the biases initializer.
1143+
name : a string or None
1144+
An optional name to attach to this layer.
1145+
1146+
Links
1147+
------
1148+
`tf.nn.conv3d_transpose <https://www.tensorflow.org/versions/master/api_docs/python/nn.html#conv3d_transpose>`_
1149+
1150+
"""
1151+
def __init__(
1152+
self,
1153+
layer = None,
1154+
act = tf.nn.relu,
1155+
shape = [2, 2, 2, 512, 1024],
1156+
output_shape = [None, 50, 50,50,512],
1157+
strides = [1,2,2,2,1],
1158+
padding = 'SAME',
1159+
W_init = tf.truncated_normal_initializer(stddev=0.1),
1160+
b_init = tf.constant_initializer(value=0.0),
1161+
W_init_args = {},
1162+
b_init_args = {},
1163+
name ='decnn_layer',
1164+
):
1165+
Layer.__init__(self, name=name)
1166+
self.inputs = layer.outputs
1167+
print(" tensorlayer:Instantiate DeConv2dLayer %s: %s, %s, %s, %s, %s" %
1168+
(self.name, str(shape), str(output_shape), str(strides), padding, act))
1169+
1170+
with tf.variable_scope(name) as vs:
1171+
W = tf.get_variable(name='W_deconv3d', shape=shape, initializer=W_init, **W_init_args )
1172+
b = tf.get_variable(name='b_deconv3d', shape=(shape[-2]), initializer=b_init, **b_init_args )
1173+
1174+
self.outputs = act( tf.nn.conv3d_transpose(self.inputs, W, output_shape=output_shape, strides=strides, padding=padding) + b )
1175+
1176+
self.all_layers = list(layer.all_layers)
1177+
self.all_params = list(layer.all_params)
1178+
self.all_drop = dict(layer.all_drop)
1179+
self.all_layers.extend( [self.outputs] )
1180+
self.all_params.extend( [W, b] )
1181+
11171182

11181183
# Pooling layer
11191184
class PoolLayer(Layer):

0 commit comments

Comments
 (0)