Error In Multi input model for graph neural network in tf keras

Viewed 134

I am training a Graph neural network using Spektral with an auxiliary input layer. I am concatenating the layers. The model compiles perfectly. But when fitting the data into the model I am getting the following error.

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

The code is given below

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)
1 Answers

Here while you are defining the Model, you have defined with two inputs for graph_input - X_in and A_in.

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

But while calling model.fit, you are passing just one input for graph_input .i.e. X_train and another input is missing. That is the reason it is throwing error.

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

Kindly pass the Second input for graph_input and the error should be fixed.

Hope this answers your question. Happy Learning.

Related