Tensorflow 中train和test的batchsize不同时, 如何设置: tf.nn.conv2d_transpose?

注: 本文是作者的自我总结,主要作为个人总结记录, 欢迎大家批评,交流. https://zhouxiaowei1120.github.io/#blogs

大家可能都知道, 在tensorflow中, 如果想实现测试时的batchsize大小随意设置, 那么在训练时, 输入的placeholder的shape应该设置为[None, H, W, C]. 具体代码如下所示:

# Placeholders for input data and the targets

x_input = tf.placeholder(dtype=tf.float32, shape=[None, input_dim[0],input_dim[1],input_dim[2]], name='Input')

y_input = tf.placeholder(dtype=tf.float32, shape=[None, n_labels], name='Labels')

s_map = tf.placeholder(dtype=tf.float32,shape=[None,z_dim[0],z_dim[1],z_dim[2]], name='S_map')

x_target = tf.placeholder(dtype=tf.float32, shape=[None, input_dim[0],input_dim[1],input_dim[2]], name='Target')

test_encoder_input = tf.placeholder(dtype=tf.float32, shape=[None, input_dim[0],input_dim[1],input_dim[2]], name='Encoder_input')

然而, 如果设计的模型中, 有转置卷积网络, 其中用到了tf.nn.conv2d_transpose()函数, 那么该函数中的output_shape, 需要按照如下形式进行设置:

x = tf.nn.conv2d_transpose(x,w_t3,output_shape=tf.stack([tf.shape(x)[0],z_dim[0],z_dim[1],z_dim[2]]),strides=(1,8,8,1),padding='SAME',name='e_convt3')

Reference: https://groups.google.com/a/tensorflow.org/forum/#!topic/discuss/vf8eH9YMwVA

---------------------

作者:davefighting

来源:CSDN

原文:https://blog.csdn.net/zhouxiaowei1120/article/details/85699468

版权声明:本文为博主原创文章,转载请附上博文链接!