Tensorflow

时间:2017-02-06 06:48:00

标签: tensorflow

输入的形状为[batch_size, maxstep, 50, 50]。我想在每一步使用某个cnn使其成为[batch_size, maxstep, 5 * 5 * 32]。乍一看,我想我应该使用while_loop

但是很难建立这个图,“maxstep”和“batch_size”都是可变的,那么如何迭代这个张量呢?

这是我的错误代码:

x = tf.placeholder(tf.float32, [2, None, None, 50, 50])
source = list()
target = list()

W_conv, B_conv = weight_and_bias('conv', [5, 5, 1, 32])

for e in x[0]:
    e_tmp = tf.reshape(e, [-1, 50, 50 ,1])
    h_conv = tf.nn.relu(conv2d(e_tmp, W_conv) + B_conv)
    h_pool = max_pool_2x2(h_conv)
    h_flat = tf.reshape(h_pool2, [-1, 5 * 5 * 32])
    source.append(e_tmp)

for e in x[1]:
    e_tmp = tf.reshape(e, [-1, 50, 50 ,1])
    h_conv = tf.nn.relu(conv2d(e_tmp, W_conv) + B_conv)
    h_pool = max_pool_2x2(h_conv)
    h_flat = tf.reshape(h_pool2, [-1, 5 * 5 * 32])
    target.append(e_tmp)

source = np.array(source)
target = np.array(target)

1 个答案:

答案 0 :(得分:0)

AllenLavoie的帮助下,我终于解决了这个问题。

首先,我将输入的形状[batch_size, variable_step_len, 50, 50]填入[batch_size, max_step_len, 50, 50],然后将其重新整形为[batch_size*max_step_len, 50, 50]

其次我在它上面并重新塑造它。