具有共享层的Model.fit在keras中的行为

时间:2018-02-06 17:16:31

标签: neural-network keras backpropagation keras-layer loss-function

我有以下型号:

enter image description here

sharedLSTM1 = LSTM((data.shape[1]), return_sequences=True)
sharedLSTM2 = LSTM(data.shape[1])
def createModel(dropoutRate=0.0, numNeurons=40, optimizer='adam'):
    inputLayer = Input(shape=(timesteps, data.shape[1]))
    sharedLSTM1Instance = sharedLSTM1(inputLayer)
    sharedLSTM2Instance =  sharedLSTM2(sharedLSTM1Instance)
    dropoutLayer = Dropout(dropoutRate)(sharedLSTM2Instance)
    denseLayer1 = Dense(numNeurons)(dropoutLayer)
    denseLayer2 = Dense(numNeurons)(denseLayer1)
    outputLayer = Dense(1, activation='sigmoid')(denseLayer2)
    return (inputLayer, outputLayer)

inputLayer1, outputLayer1 = createModel()
inputLayer2, outputLayer2 = createModel()
model = Model(inputs=[inputLayer1, inputLayer2], outputs=[outputLayer1, outputLayer2])
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

此模型中model.fit([data1, data2], [labels1, labels2])的行为是什么?它是否会为每个时代训练两个神经网络?或者它会完全训练一个网络,然后训练另一个网络?或者其他一些方式?

1 个答案:

答案 0 :(得分:1)

它将立即训练唯一的现有网络。

您没有两种型号,只有一种型号。这个模型将被训练。

Data1和Data2将同时输入 损失函数将应用于两个输出,并且两者都将反向传播。