Reputation: 55
In following this tutorial, I am receiving the following error:
ValueError: prefix tensor must be either a scalar or vector, but saw tensor: Tensor("Placeholder_2:0", dtype=int32)
The error originates from these lines:
# Take the output from the final convolutional layer and send it to a recurrent layer
# The input must be reshaped into [batch x trace x units] for rnn processing, and then returned to
# [batch x units] when sent through the upper levels
self.batch_size = tf.placeholder(dtype=tf.int32)
self.convFlat = tf.reshape(slim.flatten(self.conv4), [self.batch_size, self.trainLength, h_size])
# !!!!This is the line where error city happens!!!!
self.state_in = rnn_cell.zero_state(self.batch_size, tf.float32)
After the network is initialized:
mainQN = Qnetwork(h_size, cell, 'main')
This error is still present when solely running the code in a python console so the error is consistent.
I will post more of the code if that will be helpful
Upvotes: 2
Views: 1267
Reputation: 106
There is another solution to solve this problem.
Change
self.batch_size = tf.placeholder(dtype=tf.int32)
TO
self.batch_size = tf.placeholder(dtype=tf.int32, [])
Upvotes: 3
Reputation: 106
I met the same problem with the version of tensorflow is 1.2.+.
When i changed it to 1.1.0, the problem resolved.
I think it because the API of rnn_cell.zero_state makes arg batch_size must be a scalar or vector, but not tensor.
So, if you change batch_size to scalar, e.g. 128, the problem also could be resolved.
Upvotes: 1