我有一个包含多个输出的Keras LSTM模型。 模型定义如下:
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')
我在重塑输出数据时遇到问题。 重塑输出数据的代码是:
^{2}$我得到了以下错误:
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]],
[[0.16652206], [0.25114482], [0.36952324], [0.09429612],...
如何正确地重塑输出数据的形状?在
由于输出数量等于
output_branches
,因此输出数据必须是具有相同数量数组的list
。在基本上,如果输出数据是您的
reshape
建议的中间维度:这取决于
y
最初是如何构造的。这里我假设y
是批处理中每个序列的单值标签。在当有多个输入/输出时,
model.fit()
期望给出相应的输入/输出列表。np.split(y, output_branches, axis=-1)
在下面的一个完全可复制的例子中,正是这样做的-对于每个批次,将单个输出列表拆分为一个单独的输出列表,其中每个输出(在本例中)是1个元素列表:由于没有指定数据的确切外观,可能需要使用轴。在
编辑: 当作者从官方来源寻找答案时,它提到了here(虽然不是明确的,它只提到数据集应该产生什么,因此
model.fit()
期望什么样的输入结构):相关问题 更多 >
编程相关推荐