用Tensorlayer 搭建网络,将Deconv2dLayer封装成一个函数,提供一些默认实参,方便调用:
w_init = tf.random_normal_initializer(stddev=0.02)
b_init = None
g_init = tf.random_normal_initializer(1., 0.02)
def deconv2d(layer, out_channels=128, filter_size=3, out_size=(256,256), strides=(1, 2, 2, 1), act=tf.identity, W_init=w_init, b_init=b_init, name='deconv2d'):
"""
shape - shape of filter : [height, width, out_channels, in_channels]
output_shape - shape of outputs
"""
batch, h, w, in_channels = layer.outputs.get_shape().as_list()
filter_shape = (filter_size, filter_size, out_channels, in_channels)
output_shape = (batch, out_size[0], out_size[1], out_channels)
return tl.layers.DeConv2dLayer(layer, act=act, shape=filter_shape, output_shape=output_shape, strides=strides, padding='SAME', W_init=W_init, b_i