所以我想制作3层双向LSTM,我正在使用tensorflow tf.contrib.rnn.stack_bidirectional_dynamic_rn
这是一个小代码,我只想知道我哪里出错了。
learning_rate=0.01
batch_size=3187
annealing_rate=0.85
beta1=0.9
beta2=0.99
epsilon=10**(-8)
dropout=0.95
layer_size=3
lstm_size=1024
time_steps=34
num_hidden=1024
place_x=tf.placeholder("float",[85409,34,41])
place_y=tf.placeholder("float",[None,32,70])
cell_forw=[tf.nn.rnn_cell.BasicLSTMCell(num_hidden)]
cell_back=[tf.nn.rnn_cell.BasicLSTMCell(num_hidden)]
for i in range(1,3):
cell_forw.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True,reuse=tf.AUTO_REUSE)]*i))
cell_back.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True,reuse=tf.AUTO_REUSE)]*i))
# xf=tf.unstack(place_x,34,1)
def lstm_cell():
return tf.contrib.rnn.BasicLSTMCell(lstm_size)
cell_f= tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(3)])
cell_b= tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(3)])
outputs,_,_=tf.contrib.rnn.stack_bidirectional_dynamic_rnn(cell_forw,cell_back,
place_x,
dtype=tf.float32,
)
这是我基本上得到的错误
ValueError: Dimensions must be equal, but are 2048 and 3072 for 'stack_bidirectional_rnn/cell_2/bidirectional_rnn/fw/fw/while/fw/multi_rnn_cell/cell_0/basic_lstm_cell/MatMul_1' (op: 'MatMul') with input shapes: [85409,2048], [3072,4096].
我尝试使用其他stackoverflow问题的技术,比如,
def lstm_cell():
return tf.contrib.rnn.BasicLSTMCell(lstm_size)
cell_f= tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(3)])
cell_b= tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(3)])
似乎没什么用,谢谢。
答案 0 :(得分:1)
这是个简单的错误,
更改
for i in range(1,3):
cell_forw.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True,reuse=tf.AUTO_REUSE)]*i))
cell_back.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True,reuse=tf.AUTO_REUSE)]*i))
到
for i in range(1,3):
cell_forw.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True)]))
cell_back.append(tf.nn.rnn_cell.MultiRNNCell([tf.nn.rnn_cell.BasicLSTMCell(num_hidden,state_is_tuple=True)]))