12/06/2017

keras multiple outputs

========================================
from keras.layers import Input, Dense
from keras.model import Model

inputs = Input(shape=(N,))

x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)

output1 = Dense(M, activation='softmax')(x)
output2 = Dense(M, activation='softmax')(x)
output3 = Dense(M, activation='softmax')(x)

outputk = Dense(M, activation='softmax')(x)

model = Model(input=inputs, output=[output1, output2, output3,...,outputk])

model.compile(optimizer='rmsprop',
                    loss='categorical_crossentorpy',
                    metrics=['accuracy'])

model.fit(inputData, [output1, output2, output3,.....,outputk], nb_epochs=10, batch_size=64)

========================================

댓글 없음: