为什么tf.concat的输出全为零?

时间:2019-05-29 08:31:20

标签: python python-3.x tensorflow

我想使用tf.concat连接两个张量,尽管输入是正常的,但输出始终保持全零。我的代码有什么问题?

这是一个简单的CNN模型,我尝试过独立输入数字,并且可以正常工作。

input_x = tf.transpose(self.input_x, [0, 2, 1])
pooled_outputs = []
for i, filter_size in enumerate(self.config.filter_sizes):
    with tf.name_scope("conv-maxpool-%s" % filter_size):
        print("conv-maxpool-%s" % filter_size)
        conv = tf.layers.conv1d(input_x, self.config.num_filters, filter_size, activation=tf.nn.relu)
        pooled = tf.reduce_max(conv, reduction_indices=[1])
        pooled_outputs.append(pooled)
num_filters_total = self.config.num_filters * len(self.config.filter_sizes)  # 64*4
pooled_reshape = tf.reshape(tf.concat(pooled_outputs, 1), [-1, num_filters_total])
# pooled_flat = tf.nn.dropout(pooled_reshape, self.keep_prob)

fc = tf.layers.dense(pooled_reshape, self.config.hidden_dim, activation=tf.nn.relu, name='fc1')
fc = tf.contrib.layers.dropout(fc, self.keep_prob)

我希望它的输出为张量,为[?,256]的形状,并且它的值与输入“ pooled_outputs”相同,但不全为零。

0 个答案:

没有答案