简体   繁体   English

Keras model 有多个输入在拟合时会导致奇怪的错误

[英]Keras model having multiple inputs causes strange errors when fitting

I am currently working on a encoder-decoder model using GRUs.我目前正在使用 GRU 开发编码器-解码器 model。 It takes 2 inputs, encoder input and decoder input.它需要2个输入,编码器输入和解码器输入。 There is only one output from the decoder.解码器中只有一个 output。 The model is: model 是:

encoder=tf.keras.layers.GRU(10,return_state=True)
_,state=encoder(encoder_input)

decoder_input=tf.keras.layers.Input(shape=(None,10))
decoder=tf.keras.layers.GRU(10,return_sequences=True)
decoder_output=decoder(decoder_input,initial_state=state)

model=tf.keras.models.Model(inputs=[encoder_input,decoder_input],outputs=decoder_output)

model.compile(optimizer='Adam',loss='MeanSquaredError',metrics=['Accuracy'])

When I try to fit the model with the following pseudocode: model.fit(x=[encoder_data,decoder_data],y=decoder_truth) , encoder_data , decoder_data and decoder_truth all being nested lists of lists and having shape (None,None,10) , and decoder_data and decoder_truth having the same shape当我尝试使用以下伪代码拟合 model 时: model.fit(x=[encoder_data,decoder_data],y=decoder_truth) , encoder_data , decoder_datadecoder_truth都是嵌套的列表列表并且具有形状(None,None,10) , 和decoder_datadecoder_truth具有相同的形状

The code raises: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).代码引发: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).

Decoder_data and decoder_truth should be the same length as GRUs give one output for each input. Decoder_data 和 decoder_truth 应该与 GRU 的长度相同,为每个输入提供一个 output。 Also, the number of time steps per batch should remain constant.此外,每批的时间步数应保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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