tf.unstack
具有参数num
,该参数必须为整数才能确定输出将具有多少行。
tf.unstack(
value,
num=None,
axis=0,
name='unstack'
)
我需要使用tf.placeholder输入以下值:
self.num = tf.placeholder(tf.int32, shape = ())
但是由于self.num
是张量,所以出现此错误。有什么建议吗?
TypeError: Expected int for argument 'num' not <tf.Tensor 'inputs/Placeholder_2:0' shape=() dtype=int32>.
这是与代码相关的部分:
class PGNetwork:
def __init__(self, state_size, action_size, learning_rate):
self.state_size = state_size
self.action_size = action_size
self.learning_rate = learning_rate
self.weights = [
tf.get_variable('wd1', shape = weight_shapes[0], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
tf.get_variable('wd2', shape = weight_shapes[1], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
tf.get_variable('wd3', shape = weight_shapes[2], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
tf.get_variable('bd1', shape = weight_shapes[3], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
tf.get_variable('bd2', shape = weight_shapes[4], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
tf.get_variable('bd3', shape = weight_shapes[5], dtype=tf.float64, initializer=tf.contrib.layers.xavier_initializer(dtype=tf.float64)),
]
with tf.name_scope("inputs"):
self.inputs_ = tf.placeholder(tf.float64, [None, self.state_size], name="inputs_")
self.actions = tf.placeholder(tf.int32, [None, self.action_size], name="actions")
self.discounted_episode_rewards_ = tf.placeholder(tf.float64, [None,], name="discounted_episode_rewards")
self.flat_multiplier_tensor = tf.placeholder(tf.float64, shape = [None])
self.parameters = tf.placeholder(tf.float64, shape = [None])
self. num = tf.placeholer(tf.int32, shape = ())
with tf.name_scope('PGNetwork'):
self.logits = policy(self.inputs_, self.weights)
with tf.name_scope("softmax"):
self.action_distribution = tf.nn.softmax(self.logits)
#self.variables = [v for v in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)]
self.var_list = tf.trainable_variables()
self.trainable_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
self.var_names = [var.name for var in self.trainable_vars]
with tf.name_scope("sample_gradient"):
self.split_inputs = tf.unstack(self.inputs_, num = self.num, axis=0)
self.split_actions = tf.unstack(self.actions, num = self.num, axis = 0)
self.intermediate = [tf.expand_dims(self.split_inputs[i], 0) for i in range(self.num)]
当我尝试使用sess.run时,出现错误。