<p>我有一个包含多个输出的Keras LSTM模型。
模型定义如下:</p>
<pre><code>outputs=[]
main_input = Input(shape= (seq_length,feature_cnt), name='main_input')
lstm = LSTM(32,return_sequences=True)(main_input)
for _ in range((output_branches)): #output_branches is the number of output branches of the model
prediction = LSTM(8,return_sequences=False)(lstm)
out = Dense(1)(prediction)
outputs.append(out)
model = Model(inputs=main_input, outputs=outputs)
model.compile(optimizer='rmsprop',loss='mse')
</code></pre>
<p>我在重塑输出数据时遇到问题。
重塑输出数据的代码是:</p>
^{2}$
<p>我得到了以下错误:</p>
<blockquote>
<p>ValueError: Error when checking model target: the list of Numpy arrays
that you are passing to your model is not the size the model expected.
Expected to see 5 array(s), but instead got the following list of 1
arrays: [array([[[0.29670931],
[0.16652206],
[0.25114482],
[0.36952324],
[0.09429612]],</p>
<pre><code> [[0.16652206],
[0.25114482],
[0.36952324],
[0.09429612],...
</code></pre>
</blockquote>
<p>如何正确地重塑输出数据的形状?在</p>
<p>由于输出数量等于<code>output_branches</code>,因此输出数据必须是具有相同数量数组的<code>list</code>。在</p>
<p>基本上,如果输出数据是您的<code>reshape</code>建议的中间维度:</p>
<pre><code>y = [ y[:,i] for i in range(output_branches)]
</code></pre>