【问题标题】:Error In Multi input model for graph neural network in tf kerastf keras中图神经网络的多输入模型中的错误
【发布时间】:2020-09-25 16:03:46
【问题描述】:

我正在使用带有辅助输入层的 Spektral 训练 Graph 神经网络。我正在连接图层。该模型完美编译。但是在将数据拟合到模型中时,出现以下错误。

ValueError: No data provided for "input_10". Need data for each key in: ['input_10', 'input_12']

代码如下

X_in = Input(shape=(1375, 3))
A_in = Input(tensor=sp_matrix_to_sp_tensor(adj_mat))

Feat_input = Input(shape=(55,8))

Feat_layer = Bidirectional(LSTM(32, return_sequences=True,),name='lstm_input')(Feat_input)
Feat_layer = Dense(512,activation='relu')(Feat_layer)
Feat_layer = Flatten()(Feat_layer)

graph_conv = GraphConvSkip(64, activation='relu',kernel_regularizer=l2(l2_reg),name='graph_input')([X_in, A_in])
graph_conv = Dropout(0.5)(graph_conv)

graph_conv = ChebConv(32, activation='relu', kernel_regularizer=l2(l2_reg)([graph_conv,A_in])

graph_conv = Dropout(0.5)(graph_conv)

graph_conv = GraphConvSkip(64, activation='relu', kernel_regularizer=l2(l2_reg)([graph_conv,A_in])
graph_conv = Dropout(0.5)(graph_conv)
graph_conv = ChebConv(32, activation='relu', kernel_regularizer=l2(l2_reg))([graph_conv, A_in])

flatten = Flatten()(graph_conv)

concatenated = concatenate([flatten, Feat_layer])

fc = Dense(512, activation='relu')(concatenated)
fc = Dense(256, activation='relu')(FC)
output = Dense(n_out, activation='softmax')(FC)

model = Model(inputs={'graph_input':[X_in, A_in], 'lstm_input':Feat_input}, outputs=output)

optimizer = RMSprop(lr=learning_rate)

model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['acc'])
model.summary()
history = model.fit({'graph_input': [X_train], 'lstm_input': x_train_feat }, y_train, batch_size=28, epochs=250,steps_per_epoch=10)

【问题讨论】:

    标签: tensorflow keras neural-network lstm


    【解决方案1】:

    在此处定义Model 时,您已使用two inputs 定义graph_input - X_inA_in

    model = Model(inputs={'graph_input':[X_in, A_in], 'lstm_input':Feat_input}, outputs=output)
    

    但是在调用model.fit 时,您只是将one input 传递给graph_input。即X_train 并且缺少另一个输入。这就是它抛出错误的原因。

    history = model.fit({'graph_input': [X_train], 'lstm_input': x_train_feat }, y_train, batch_size=28, epochs=250,steps_per_epoch=10)
    

    请将Second input 传递给graph_input,错误应该已修复。

    希望这能回答您的问题。快乐学习。

    【讨论】:

    • @CodeHead - 希望我们已经回答了您的问题。如果您对答案感到满意,请您接受并投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 2021-03-04
    相关资源
    最近更新 更多