编码器解码器Conc行为Keras

时间:2019-08-01 15:42:53

标签: python tensorflow keras lstm

当尝试实现时,纸生成级联网络(Lipton等人,2015)将来自LSTM的隐藏状态输出与解码器输入进行无级级联,以馈入解码器级,但出现以下错误: >

“节点=层。_inbound_nodes[node_index] AttributeError:'NoneType'对象没有属性'_inbound_nodes'“


from keras.layers import Input, Embedding, LSTM, Dense
from keras.models import Model
import keras
import tensorflow as tf

encoder_input = Input(shape=(46, 21), dtype='float32', name='encoder_input')

# Encoder stage
_, h_s, c_s = LSTM(256,
                   return_sequences=True,
                   return_state=True,
                   dropout=0.0,
                   recurrent_dropout=0.0)(encoder_input)
encoder_states = [h_s, c_s]

decoder_input = Input(shape=(46, 21), name='decoder_input')

conc = True
if conc:
    # Reshape tensor to dimensions -1, 46, 21
    h_s_s = tf.reshape(h_s, (-1, 46, 21))
    x = keras.layers.concatenate([h_s_s, decoder_input])
else:
    x = decoder_input

# Decoder stage
decoder_lstm = LSTM(256, return_sequences=True, return_state=True,
                    dropout=0.0,
                    recurrent_dropout=0.0)
decoder_outputs, _, _ = decoder_lstm(x,
                                     initial_state=encoder_states)

# FC layer
main_output = Dense(21, activation='sigmoid', name='main_output')(decoder_outputs)

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


我希望对象模型是a,但是在创建对象时错误是:

“节点=层。_inbound_nodes[node_index] AttributeError:'NoneType'对象没有属性'_inbound_nodes'“

1 个答案:

答案 0 :(得分:0)

问题在这里:

php artisan scout:import "App\Models\YourModel

您不能直接在Keras张量中应用TF或后端操作,您需要将它们包装在Lambda层中,但是已经有一个用于重塑的层:

h_s_s = tf.reshape(h_s, (-1, 46, 21))

这将产生另一个错误(from keras.layers import Reshape h_s_s = Reshape((46, 21))(h_s) ),并且您必须对其进行修复,因为重塑尺寸不适用于图层输出。只有OP知道正确的值。