Xin chào Tôi đang sử dụng chức năng sau cho ô lstm rnn.Tensor Flow - LSTM - đối tượng 'Tensor' không thể lặp lại
def LSTM_RNN(_X, _istate, _weights, _biases):
# Function returns a tensorflow LSTM (RNN) artificial neural network from given parameters.
# Note, some code of this notebook is inspired from an slightly different
# RNN architecture used on another dataset:
# https://tensorhub.com/aymericdamien/tensorflow-rnn
# (NOTE: This step could be greatly optimised by shaping the dataset once
# input shape: (batch_size, n_steps, n_input)
_X = tf.transpose(_X, [1, 0, 2]) # permute n_steps and batch_size
# Reshape to prepare input to hidden activation
_X = tf.reshape(_X, [-1, n_input]) # (n_steps*batch_size, n_input)
# Linear activation
_X = tf.matmul(_X, _weights['hidden']) + _biases['hidden']
# Define a lstm cell with tensorflow
lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Split data because rnn cell needs a list of inputs for the RNN inner loop
_X = tf.split(0, n_steps, _X) # n_steps * (batch_size, n_hidden)
# Get lstm cell output
outputs, states = rnn.rnn(lstm_cell, _X, initial_state=_istate)
# Linear activation
# Get inner loop last output
return tf.matmul(outputs[-1], _weights['out']) + _biases['out']
Kết quả của hàm được lưu dưới biến số tiền trước.
pred = LSTM_RNN(x, istate, weights, biases)
Nhưng hiển thị lỗi sau. (Trong đó nêu rằng đối tượng tensor không iterable.)
Dưới đây là liên kết hình ảnh LỖI - http://imgur.com/a/NhSFK
Xin hãy giúp tôi với điều này và tôi xin lỗi nếu câu hỏi này có vẻ ngớ ngẩn như tôi khá mới đến lstm và tensor lưu lượng thư viện.
Cảm ơn.
lệnh định lại hình dạng của nó, hãy kiểm tra xem http://stackoverflow.com/questions/33884978/build-a-graph-that-works-with-variable-batch-size-using-tensorflow –
nhưng lệnh định hình lại là loại cần thiết để chuyển đổi thành hình dạng yêu cầu. –
chắc chắn, hãy thử với tf.reshape (x, tf.pack (n_input, -1])) –