1
votes

As the title says how do we compile a keras functional model with mulitple outputs?

# Multiple Outputs
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers.recurrent import LSTM
from keras.layers.wrappers import TimeDistributed

# input layer
visible = Input(shape=(4,2))
# feature extraction
extract = LSTM(10, return_sequences=True)(visible)
# classification output
class11 = LSTM(10)(extract)
class12 = Dense(8, activation='relu')(class11)
class13 = Dense(8, activation='relu')(class12)

output1 = Dense(9, activation='softmax')(class13)

# sequence output
output2 = TimeDistributed(Dense(1, activation='tanh'))(extract)
# output

model = Model(inputs=visible, outputs=[output1, output2])

# summarize layers
print(model.summary())

There are two output branches with two different types of output values. First output is a dense layer with softmax activation function and other output is a time distributed layer with tanh activation.

How should we compile this model. I tried this way

model.compile(optimizer=['rmsprop','adam'],
              loss=['categorical_crossentropy','mse'],
              metrics=['accuracy'])

But its giving this error

ValueError: ('Could not interpret optimizer identifier:', ['rmsprop', 'adam'])

1
If you don't mind, I'd appreciate an upvote.Marcin Możejko
I already gave one and also accepted your answerEka
Thanks a lot then :)Marcin Możejko

1 Answers

1
votes

The problem lies in the fact that you want to set two separate optimizer what is not plausible in keras. You need to choose either rmsprop or adam as the main optimizer.