ValueError:形状(16,)和(1,16)在tensorflow1.0中不兼容

时间:2017-03-15 19:10:33

标签: python machine-learning tensorflow

当我在tensorflow

中运行以下代码时
import tensorflow as tf
import numpy as np

x_input_data = np.random.random((1024,16))
q = tf.train.input_producer(x_input_data, element_shape=[1,16])
input = q.dequeue() # It replaces our input placeholder
print (x_input_data.shape)
print (input.get_shape())

sess = tf.Session()
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
example_batch = tf.train.batch([input], batch_size=1024, num_threads=4, capacity=40, enqueue_many=True)
for step in range(1000):
    sess.run(example_batch)
coord.request_stop()
coord.join(threads)
sess.close()

我收到以下错误

ValueError: Shapes (16,) and (1, 16) are not compatible

为什么我会收到此错误?

1 个答案:

答案 0 :(得分:1)

https://www.tensorflow.org/api_docs/python/tf/train/input_producer开始,element_shape是行的形状,它引用1D numpy数组(16,),而不是提供的2D numpy数组(1, 16)。如果删除element_shape或用`(16,)替换它,它应该可以工作。