[英]Tensorflow : ValueError: Dimensions must be equal
我運行了該教程的代碼,但出現以下錯誤
我讀過一些類似的帖子,但並沒有真正幫助我
ValueError:尺寸必須相等,但對於'RNN_forward / rnn / while / rnn / multi_rnn_cell / cell_0 / basic_lstm_cell / MatMul_1'(op:'MatMul'),輸入形狀分別為[250,128],[364,256],尺寸為128和364。
這是本教程結尾的代碼:
n_words = len(word_index)
embed_size = 300
batch_size = 250
lstm_size = 128
num_layers = 2
dropout = 0.5
learning_rate = 0.001
epochs = 100
multiple_fc = False
fc_units = 256
# Train the model with the desired tuning parameters# Train
for lstm_size in [64,128]:
for multiple_fc in [True, False]:
for fc_units in [128, 256]:
log_string = 'ru={},fcl={},fcu={}'.format(lstm_size,
multiple_fc,
fc_units)
model = build_rnn(n_words = n_words,
embed_size = embed_size,
batch_size = batch_size,
lstm_size = lstm_size,
num_layers = num_layers,
dropout = dropout,
learning_rate = learning_rate,
multiple_fc = multiple_fc,
fc_units = fc_units)
train(model, epochs, log_string)
我更改了應用分析的數據集,並嘗試對其進行調整。 您是否知道如何解決該錯誤?
我讀了一些類似的文章,但並沒有真正幫助我。
非常感謝你
我通過該帖子解決了這個問題,我替換了以下代碼:
with tf.name_scope('RNN_layers'):
lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size)
drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=keep_prob)
cell = tf.contrib.rnn.MultiRNNCell([drop] * num_layers)
通過該代碼:
with tf.name_scope('RNN_layers'):
cell = tf.contrib.rnn.MultiRNNCell([lstm_cell(lstm_size, keep_prob) for _ in
range(num_layers)])
通過添加以下功能:
def lstm_cell(lstm_size, keep_prob):
lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size)
drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=keep_prob)
return drop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.