Reputation: 11
Problem: I have created my encoder-decoder model to forecast time series. Model trains well, but I struggle with the error in the inference model and I dont know how to troubleshoot it:
WARNING:tensorflow:Keras is training/fitting/evaluating on array-like data. Keras may not be optimized for this format, so if your input data format is supported by TensorFlow I/O (https://github.com/tensorflow/io) we recommend using that to load a Dataset instead.
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
Data: There are 2 inputs: input1 (encoder) - multi-step univariate sequences, and input2 (decoder) - multi-step univariate sequences. Both inputs are used in training, while only input 2 is used in inference. My output is multi-step univarite sequence.
Model:
N = 32
encoder_inputs = KL.Input(shape=(n_past, n_feat1))
encoder = KL.LSTM(N, return_state=True, return_sequences=False)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
enc_states = [state_h, state_c]
decoder_inputs = KL.Input(shape=(n_past, n_feat2))
decoder_lstm = KL.LSTM(N, return_sequences=True, return_state=False)
decoder_output = decoder_lstm(decoder_inputs, initial_state=enc_states)
dense1 = KL.TimeDistributed(KL.Dense(N, activation='relu'))
dense1_output = dense1(decoder_output)
dense2 = KL.TimeDistributed(KL.Dense(1))
out = dense2(dense1_output)
model = keras.models.Model([encoder_inputs, decoder_inputs], out)
decoder_state_input_h = KL.Input(shape=(N,))
decoder_state_input_c = KL.Input(shape=(N,))
decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
decoder_outputs = decoder_lstm(decoder_inputs, initial_state=decoder_states_inputs)
out = dense1(decoder_outputs)
out = dense2(out)
inf_model = keras.models.Model([decoder_inputs]+decoder_states_inputs, out)
The error is created by :
<compile and fit training model>
inf_model.predict([val_x[1]] + enc_states)
where val_x = [enc_input, dec_input]. enc_states is a list of 2 tensors from Keras (e.g. <KerasTensor: shape=(None, 32) dtype=float32 (created by layer 'lstm')>), while dec_input is an array with shape (14284, 24, 6).
Upvotes: 0
Views: 62
Reputation: 11
The reasons of the error:
I was passing state_h
and state_c
that were symbolic tensors. What I needed it was to calculate them first with an encoder model.
Upvotes: 0