Архитектура в порядке. Вот игрушечный пример с обучающими данными о том, как его можно определить с помощью функционального API-интерфейса keras:
from keras.models import Model
from keras.layers import Dense, Input
# two separate inputs
in_1 = Input((10,10))
in_2 = Input((10,10))
# both inputs share these layers
dense_1 = Dense(10)
dense_2 = Dense(10)
# both inputs are passed through the layers
out_1 = dense_1(dense_2(in_1))
out_2 = dense_1(dense_2(in_2))
# create and compile the model
model = Model(inputs=[in_1, in_2], outputs=[out_1, out_2])
model.compile(optimizer='adam', loss='mse')
model.summary()
# train the model on some dummy data
import numpy as np
i_1 = np.random.rand(10, 10, 10)
i_2 = np.random.rand(10, 10, 10)
model.fit(x=[i_1, i_2], y=[i_1, i_2])
Изменить, учитывая, что вы хотите рассчитать потери вместе, которые вы можете использовать Concatenate()
output = Concatenate()([out_1, out_2])
Любая функция потерь, которую вы передаете в model.compile
, будет применяться к output
в комбинированном состоянии. После того, как вы получите вывод из прогноза, вы можете просто разделить его обратно в исходное состояние:
f = model.predict(...)
out_1, out_2 = f[:n], f[n:]