Python DRQN-前缀张量必须是标量或向量,但必须是saw张量
在下文中,我收到以下错误:Python DRQN-前缀张量必须是标量或向量,但必须是saw张量,python,tensorflow,Python,Tensorflow,在下文中,我收到以下错误: ValueError:前缀张量必须是标量或向量,但saw张量:张量(“占位符_2:0”,dtype=int32) 错误源于以下几行: # 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 t
ValueError:前缀张量必须是标量或向量,但saw张量:张量(“占位符_2:0”,dtype=int32)
错误源于以下几行:
# 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)
网络初始化后:
mainQN = Qnetwork(h_size, cell, 'main')
在python控制台中单独运行代码时,此错误仍然存在,因此错误是一致的
如果有帮助的话,我会发布更多的代码我在tensorflow is 1.2的版本中遇到了同样的问题 当我把它改为1.1.0时,问题解决了 我认为这是因为rnn_cell.zero_state的API使得arg batch_size必须是标量或向量,而不是张量
因此,如果将批次大小更改为标量,例如128,问题也可以解决。还有另一种解决方案 改变
self.batch_size = tf.placeholder(dtype=tf.int32)
到
self.batch_size = tf.placeholder(dtype=tf.int32, [])