将 LSTM 输出与占位符连接起来
Concatenating LSTM output with a placeholder
我定义了一个 LSTM
cell = tf.contrib.rnn.LSTMCell(num_hidden,state_is_tuple=True)
val, _ = tf.nn.dynamic_rnn(cell, sequential_feed_data, dtype=tf.float32)
val = tf.transpose(val, [1, 0, 2])
last = tf.gather(val, int(val.get_shape()[0]) - 1)
weight_sequential = tf.Variable(tf.truncated_normal([num_hidden,int(target.get_shape()[1])]))
bias_sequential = tf.Variable(tf.constant(0.1, shape=[target.get_shape()[1]]))
output_sequential = tf.nn.softmax(tf.matmul(last, weight_sequential) + bias_sequential)
此 output_sequential 的尺寸为 [BATCH_SIZE, 1]。我希望通过使用 tf.concat 将其与维度 [BATCH_SIZE, 10] 的另一个占位符节点连接起来,以获得维度 [BATCH, 11] 的另一个值 as
combined_data_for_MLP = tf.concat(feed_data, output_sequential, 1)
但是,我收到以下错误
TypeError: expected string or bytes-like object
如何根据需要连接?
查看 tf.concat 的文档:https://www.tensorflow.org/api_docs/python/tf/concat
您会看到,对于被连接的对象的参数称为 "values",它必须是单个张量或 张量列表。 因此,您的案例的函数调用应该是 tf.concat([feed_data, output_sequential], 1)
我定义了一个 LSTM
cell = tf.contrib.rnn.LSTMCell(num_hidden,state_is_tuple=True)
val, _ = tf.nn.dynamic_rnn(cell, sequential_feed_data, dtype=tf.float32)
val = tf.transpose(val, [1, 0, 2])
last = tf.gather(val, int(val.get_shape()[0]) - 1)
weight_sequential = tf.Variable(tf.truncated_normal([num_hidden,int(target.get_shape()[1])]))
bias_sequential = tf.Variable(tf.constant(0.1, shape=[target.get_shape()[1]]))
output_sequential = tf.nn.softmax(tf.matmul(last, weight_sequential) + bias_sequential)
此 output_sequential 的尺寸为 [BATCH_SIZE, 1]。我希望通过使用 tf.concat 将其与维度 [BATCH_SIZE, 10] 的另一个占位符节点连接起来,以获得维度 [BATCH, 11] 的另一个值 as
combined_data_for_MLP = tf.concat(feed_data, output_sequential, 1)
但是,我收到以下错误
TypeError: expected string or bytes-like object
如何根据需要连接?
查看 tf.concat 的文档:https://www.tensorflow.org/api_docs/python/tf/concat
您会看到,对于被连接的对象的参数称为 "values",它必须是单个张量或 张量列表。 因此,您的案例的函数调用应该是 tf.concat([feed_data, output_sequential], 1)