【发布时间】:2016-10-15 23:09:34
【问题描述】:
我正在使用 Tensorflow 构建一个 LSTM RNN,它执行逐像素分类(或者,也许更好的说法是逐像素预测?)
请耐心等待我解释标题。
网络如下图...
这个想法是这样的......大小为 (200,200) 的输入图像是大小为 (200,200,200) 的 LSTM RNN 的输入。从 LSTM 张量向量(LSTM RNN 中的粉红色框)输出的每个序列都被输入到 MLP,然后 MLP 进行单个输出预测 -- ergo pixel-wise prediction(你可以看到一个输入像素如何生成一个输出“像素”
代码看起来像这样(不是所有的代码,只是需要的部分):
...
n_input_x = 200
n_input_y = 200
x = tf.placeholder("float", [None, n_input_x, n_input_y])
y = tf.placeholder("float", [None, n_input_x, n_input_y])
def RNN(x):
x = tf.transpose(x, [1, 0, 2])
x = tf.reshape(x, [-1, n_input_x])
x = tf.split(0, n_steps, x)
lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0, state_is_tuple=True)
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)
output_matrix = []
for i in xrange(200):
temp_vector = []
for j in xrange(200):
lstm_vector = outputs[j]
pixel_pred = multilayer_perceptron(lstm_vector, mlp_weights, mlp_biases)
temp_vector.append(pixel_pred)
output_matrix.append(temp_vector)
print i
return output_matrix
temp = RNN(x)
pred = tf.placeholder(temp, [None, n_input_x, n_input_y])
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
...
我已经确认RNN的输出——也就是temp中存储的是<tf.Tensor 'Softmax_39999:0' shape=(?, 1) dtype=float32>的200x200数组
如您所见,我将temp 放置在相同形状的tf.placeholder 中(None 用于批量大小......或者我需要这个吗?)......然后程序就像退出一样它完成了运行。理想情况下,当我调试和打印 pred 时,我想看到的内容类似于 <tf.Tensor shape=(200,200)>
当我调试时,我第一次执行 pred = tf.placeholder(temp, [None, n_input_x, n_input_y]) 我得到 TypeError: TypeErro...32>]].",) 然后是 returns 我再试一次,它说 Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7f1ab77c26e0> ignored
编辑我现在也意识到我需要放置线条
lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0, state_is_tuple=True)
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)
在第一个循环中生成新的 2D LSTM RNN,但是我收到关于变量重用的错误 ValueError: Variable RNN/BasicLSTMCell/Linear/Matrix does not exist, disallowed. Did you mean to set reuse=None in VarScope?
也就是说,不是自动递增 RNN 张量名称吗?
【问题讨论】:
标签: python machine-learning neural-network artificial-intelligence tensorflow