Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get error while trying to build an architecture with multiple inputs in Keras?

I am trying to build an architecture with multiple inputs in Keras. As mentioned in 1, I used similar code as followed:

model_merged = Model(inputs=[model_parts1, model_parts2,
                             model_parts3, model_parts4])

But I get the following error:

TypeError: _init_subclassed_network() got an unexpected keyword argument 'inputs'

I have searched online and some people mentioned that Keras should be updated to version 2.0.0; though I have version 2.2.2 installed which I suppose is not the problem.

Can anyone help me with this error?

like image 211
iBM Avatar asked Dec 02 '18 13:12

iBM


People also ask

What is the meaning of model Sequentil () in Keras?

The Sequential model API is a way of creating deep learning models where an instance of the Sequential class is created and model layers are created and added to it.


1 Answers

Keras functional api Model expects two positional arguments namely inputs, and outputs. The error

TypeError: _init_subclassed_network() got an unexpected keyword argument 'inputs'

is thrown when the output of the model is not specified.

input1 = keras.layers.Input(shape=(8,))
input2 = keras.layers.Input(shape=(8,))
h1 = keras.layers.Concatenate()([input1, input2])
model = keras.models.Model(inputs=[input1, input2])

this throws the following error

TypeError: _init_subclassed_network() got an unexpected keyword argument 'inputs'

But if outputs are specified it works without error

model = keras.models.Model(inputs=[input1, input2], outputs=h1)

Similar exception is thrown when the outputs argument is passed without inputs argument.

model = keras.models.Model(outputs=h1)
TypeError: _init_subclassed_network() got an unexpected keyword argument 'outputs'

I think it would be very helpful, if the error message would have been more informative. The inputs and outputs arguments are "not unexpected" arguments here. It would be more informative if the error message would have been

TypeError: _init_subclassed_network() missing expected keyword argument 'outputs'

for the former case where only inputs argument is specified and

TypeError: _init_subclassed_network() missing expected keyword argument 'inputs'

for the later case where there only outputs argument is specified.

like image 175
Mitiku Avatar answered Sep 28 '22 06:09

Mitiku