Ошибка Keras: у объекта NoneType нет атрибута '_inbound_nodes' - PullRequest
0 голосов
/ 17 марта 2019

Я пытаюсь запрограммировать тип сети кодер-декодер с модулем внимания в keras 2.2.4, но у меня есть следующая ошибка, и я не смог ее исправить. Кто-то, кто может помочь мне с этим?

def model(Tx, Ty, encoder_unit_size, decoder_unit_size, encoder_embedding_input_size, decoder_embedding_input_size, embedding_size, out_size):
"""
Arguments:
Tx -- length of the input sequence
Ty -- length of the output sequence
encoder_unit_size -- hidden state size of the Bi-LSTM
decoder_unit_size -- hidden state size of the LSTM
encoder_embedding_input_size -- size of the input embedding in encoder module
decoder_embedding_input_size -- size of the input embedding in decoder module
embedding_size -- embedding size of the decoder input
Returns:
model -- Keras model instance
"""

# Encoder module
encoder_input = Input(shape=(Tx, encoder_embedding_input_size))

# Step 1: Define Deep Bi-LSTM Enconder
fl_enc_seq, flast_h, flast_s, _, _ = Bidirectional(LSTM(encoder_unit_size, 
                                                       return_sequences=True,
                                                       return_state=True), 
                                                       merge_mode="concat")(encoder_input)


sl_enc_seq, slast_h, slast_s, _, _ = Bidirectional(LSTM(encoder_unit_size, 
                                                        return_sequences=True,
                                                        return_state=True), 
                                                        merge_mode="concat")(fl_enc_seq)

# Decoder module 

decoder_input = Input(shape=(Ty, decoder_embedding_input_size)) 

# Step 2: Define Deep LSTM Decoder. Hidden and state initialization with last outputs of encoder.
fl_dec_seq = LSTM(decoder_unit_size, 
                  return_sequences=True,
                  unroll= False)(decoder_input, initial_state=[flast_h, flast_s])

sl_dec_seq = LSTM(decoder_unit_size, 
                  return_sequences=True, 
                  unroll= False)(fl_dec_seq, initial_state=[slast_h, slast_s])

# Step 3: Attention module
outputs = [] 

# Iterate for Ty steps
for t in range(Ty):
    context_vector = one_step_attention(sl_enc_seq, sl_dec_seq[:,t,:])
    decoder_context = concatenator([tf.expand_dims(sl_dec_seq[:,t,:], 1), context_vector])

    fc_out = dense_output_layer(decoder_context)

    outputs.append(fc_out)    

output_tensor = Lambda(lambda x:tf.convert_to_tensor(x, dtype=tf.float32))(outputs)
outputs_layer = TimeDistributed(Dense(out_size, activation="softmax"))(output_tensor)
print(outputs_layer.shape)

model = Model(inputs = [encoder_input, decoder_input], outputs = outputs_layer)
return model

Это вывод:

(50,?, 1, 1024)
...
...
AttributeError: у объекта 'NoneType' нет атрибута '_inbound_nodes'

Я думаю, что ошибка при возврате вывода:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...