Reputation: 447
a question concerning keras regression with multiple outputs:
Could you explain the difference beteween this net:
two inputs -> two outputs
input = Input(shape=(2,), name='bla')
hidden = Dense(hidden, activation='tanh', name='bla')(input)
output = Dense(2, activation='tanh', name='bla')(hidden)
and: two single inputs -> two single outputs:
input = Input(shape=(2,), name='speed_input')
hidden = Dense(hidden_dim, activation='tanh', name='hidden')(input)
output = Dense(1, activation='tanh', name='bla')(hidden)
input_2 = Input(shape=(1,), name='angle_input')
hidden_2 = Dense(hidden_dim, activation='tanh', name='hidden')(input_2)
output_2 = Dense(1, activation='tanh', name='bla')(hidden_2)
model = Model(inputs=[speed_input, angle_input], outputs=[speed_output, angle_output])
They behave very similar. Other when I completly seperate them, then the two nets behave like they re supposed to.
And is it normal that two single output nets behave much more intelligible than a bigger one with two outputs, I didnt think the difference could be huge like I experienced.
Thanks a lot :)
Upvotes: 4
Views: 5989
Reputation: 524
This goes back to how neural networks operate. In your first model, each hidden neuron receives 2 input values (as it is a 'Dense' layer, the input propagates to every neuron). In your second model, you have twice as many neurons, but each of these only receive either speed_input
or angle_input
, and only works with that data instead of the entire data.
So, if speed_input
and angle_input
are 2 completely unrelated attributes, you'll likely see better performance from splitting the 2 models, since neurons aren't receiving what is basically noise input (they don't know that your outputs correspond to your inputs, they can only try to optimize your loss function). Essentially, you're creating 2 seperate models.
But in most cases, you want to feed the model relevant attributes that combine to draw a prediction. So splitting the model then would not make sense, since you're just stripping neccessary information away.
Upvotes: 4