繁体   English   中英

Tensorflow:ValueError:尺寸必须相等

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM