Using tensorflow reduce_sum on tensorflow placeholder results in random error

时间:2018-04-18 18:15:51

标签: python tensorflow

I am implementing a Replicated Softmax Model in tensorflow. Given a batch of data, I have to sum along the rows (yielding a column vector) and I have to take an outer product of this with the hidden units bias. Using tf.matmul(tf.squeeze(tf.reduce_sum(visible_units, 1,keepdims=True)), tf.expand_dims(self.h, 1)) causes this error InvalidArgumentError (see above for traceback): In[0] is not a matrix

Here visible_units is a tf.placeholder (dimension: batch_size x n_visible_units) and self.h is hidden layer bias (n_hidden_units).

The error doesn't make sense and seems completely unrelated. If I replace tf.matmul(tf.squeeze(tf.reduce_sum(visible_units, 1,keepdims=True)), tf.expand_dims(self.h, 1)) with just self.h my code runs fine.

EDIT: tf.squeeze(tf.reduce_sum(visible_units, 1,keepdims=True)) generates a 1-D tensor so just had to reshape this.

0 个答案:

没有答案