【问题标题】:How to fix ValueError: too many values to unpack?? PYTHON如何修复 ValueError:解包的值太多?? PYTHON
【发布时间】:2020-01-15 02:57:41
【问题描述】:
lstm_layer = tf.keras.layers.LSTM(256, return_sequences=True,return_state=True)

bilstm1,state_h1,state_c1 = tf.keras.layers.Bidirectional(lstm_layer, name="BiLSTM1", merge_mode="concat")(reshape)
bilstm2,state_h2,state_c2 = tf.keras.layers.Bidirectional(lstm_layer, name="BiLSTM2", merge_mode='concat')(bilstm1)

但是

bilstm1,state_h1,state_c1 = tf.keras.layers.Bidirectional(lstm_layer, name="BiLSTM1", merge_mode="concat")(reshape)
ValueError: too many values to unpack (expected 3)

【问题讨论】:

    标签: python machine-learning lstm


    【解决方案1】:

    如果您只关心前 3 项,而想忽略其余的,您可能会这样做:

    bilstm1, state_h1, state_c1, *_ = tf.keras.layers.Bidirectional(lstm_layer, name="BiLSTM1", merge_mode="concat")(reshape)
    

    很可能,其他行也需要进行此类更改。

    不用说,如果正确的操作数在少于 3 个项目中解包,您仍然会收到错误。

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 2021-10-26
      • 2021-10-29
      • 2019-08-30
      • 2014-01-20
      • 1970-01-01
      相关资源
      最近更新 更多