简体   繁体   中英

Keras model having multiple inputs causes strange errors when fitting

I am currently working on a encoder-decoder model using GRUs. It takes 2 inputs, encoder input and decoder input. There is only one output from the decoder. The model is:

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

The code raises: 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. Also, the number of time steps per batch should remain constant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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