RdlP
RdlP

Reputation: 1396

ValueError: Shapes (16,) and (1, 16) are not compatible in tensorflow1.0

When I run the following code in 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()

I get the following error

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

Why I get this error?

Upvotes: 2

Views: 2049

Answers (1)

ayplam
ayplam

Reputation: 1953

From https://www.tensorflow.org/api_docs/python/tf/train/input_producer, element_shape is the shape of a row which refers to a 1D numpy array (16,) as opposed to the 2D numpy array supplied, (1, 16). If you remove element_shape or replace it with `(16,) it should work.

Upvotes: 1

Related Questions