def transpose_conv_layer(inputs, kernel_size, stride, num_features, idx, nonlinearity=None):
with tf.variable_scope('{0}_trans_conv'.format(idx)) as scope:
input_channels = int(inputs.get_shape()[3])
weights = _variable('weights', shape=[kernel_size,kernel_size,num_features,input_channels],initializer=tf.contrib.layers.xavier_initializer_conv2d())
biases = _variable('biases',[num_features],initializer=tf.contrib.layers.xavier_initializer_conv2d())
batch_size = tf.shape(inputs)[0]
output_shape = tf.pack([tf.shape(inputs)[0], tf.shape(inputs)[1]*stride, tf.shape(inputs)[2]*stride, num_features])
conv = tf.nn.conv2d_transpose(inputs, weights, output_shape, strides=[1,stride,stride,1], padding='SAME')
conv_biased = tf.nn.bias_add(conv, biases)
if nonlinearity is not None:
conv_biased = nonlinearity(conv_biased)
#reshape
shape = int_shape(inputs)
conv_biased = tf.reshape(conv_biased, [shape[0], shape[1]*stride, shape[2]*stride, num_features])
return conv_biased
nerve_architecture.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录