This is more of a conceptual question, but it is related to a practical problem I am having. Suppose I define a model, as an example, something like this:
import tensorflow as tf
from tensorflow.keras.layers import Input, Conv1D, MaxPooling1D, Dense, GlobalAveragePooling1D, Dropout
from tensorflow.keras.models import Model
def root(input_shape):
input_tensor = Input(input_shape)
cnn1 = Conv1D(100, 10, activation='relu', input_shape=input_shape)(input_shape)
mp1 = MaxPooling1D((3,))(cnn1)
cnn3 = Conv1D(160, 10, activation='relu')(mp1)
gap1 = GlobalAveragePooling1D()(cnn3)
drp1 = Dropout(0.5)(gap1)
return Model(input_tensor, drp1)
And then the two branches
def branch_1(input_shape):
input_tensor = Input(input_shape)
dense1 = Dense(10, activation='relu')(input_tensor)
prediction = Dense(1, activation='sigmoid')(dense1)
return Model(input_tensor, prediction)
def branch_2(input_shape):
input_tensor = Input(input_shape)
dense1 = Dense(25, activation='relu')(input_shape)
dropout1 = Dropout(rate=0.4)(dense1)
prediction = Dense(1, activation='sigmoid')(dropout1)
return Model(input_tensor, prediction)
Now, I create my final model as:
input_shape = (256, 1)
base_model = root(input_shape)
root_input = Input(input_shape)
root_output = base_model(root_input)
b1 = branch_1(root_output[0].shape[1:])
b1_output = b1(root_output)
b2 = branch_2(root_output[0].shape[1:])
b2_output = b2(root_output)
outputs = [b1_output, b2_output]
branched_model = Model(root_input, outputs)
The root_output
is linked to both branch_1
and branch_2
. As such, the error propagated to the last layer of model root
comes from the outputs of both branch_1
and branch_2
. My question is, how those errors are combined when propagated to the last layer of model root
? Can I affect the way this combination is performed?