self.embed = Sequential([Embedding(9488, output_dim=512,input_length=14),
Activation('relu'),
Dropout(0.5)], name='embed.0')
self.fc_embed = Sequential([Dense(512, input_shape=(10,2048)),
Activation('relu'),
Dropout(0.5)], name='fc_embed.0')
inputs_bedding = Input(shape=(10,))
xt = self.embed(inputs_bedding)
input_feats = Input(shape=(10,2048))
fc_feats = self.fc_embed(input_feats)
fc_feats_new = K.reshape(fc_feats, [fc_feats.shape[1], fc_feats.shape[2]])
xt_new = K.reshape(xt, [xt.shape[1], xt.shape[2]])
prev_h = state[0][-1] (shape is (10,512))
att_lstm_input = Concatenate([prev_h, fc_feats_new, xt_new], axis=1)
lstm, h_att, c_att = LSTM(units=512, name='core.att_lstm', return_state=True)(att_lstm_input)
model = Model([input_feats, inputs_att, inputs_bedding], lstm)
model.summary()
这是我得到的错误:
File "copy_eval.py", line 165, in <module>
model1 = TopDownModel.forward(fc_feats, att_feats, seq, att_masks)
文件“ /home/ubuntu/misc/customize_keras.py”,向前127行 lstm,h_att,c_att = LSTM(单位= 512,名称='core.att_lstm',return_state = True)(att_lstm_input) 调用中的文件“ /usr/local/lib/python2.7/dist-packages/keras/layers/recurrent.py”,第500行 返回超级(RNN,自我)。调用(输入,** kwargs) 在调用中,文件“ /usr/local/lib/python2.7/dist-packages/keras/engine/topology.py”,第575行 self.assert_input_compatibility(输入) 在assert_input_compatibility中的文件“ /usr/local/lib/python2.7/dist-packages/keras/engine/topology.py”,行448 str(输入)+'。图层的所有输入' ValueError:层core.att_lstm的输入不是符号张量。收到的类型:。完整输入:[]。该层的所有输入都应为张量。
要获得更多输入,如何将它们合并为一个输出?
答案 0 :(得分:0)
串联应用作图层,如下所示:
att_lstm_input = Concatenate(axis=1)([prev_h, fc_feats_new, xt_new])