<p dir="auto">Hi all,</p>
<p dir="auto">I am writing as I have some fundamental confusion about the merge/concatenate layers. I have not found an answer to my question on stackoverflow or other site, so any help would be appreciated.</p>
<p dir="auto">Context: I have built two sequential models. Both models are two different data types although they both lead to the same classifications on the other side. What I would like to do is merge layers between two models in order to share information and learn new features based on both models that are leading to classifications made.</p>
<p dir="auto">My models are as follows: (please note they are the same for this post, however one will stay the same one will highly likely have another layer added on plus more neurons in each layer when more data becomes available:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="**model1**
model= Sequential()
model.add(Dense(units=64, input_dim=5078, activation=&quot;relu&quot;))
model.add(Dense(units=32, activation=&quot;relu&quot;))
model.add(Dense(units=100, activation=&quot;relu&quot;))
model.add(Dense(units=24, activation=&quot;sigmoid&quot;))

**model2**
modelSC= Sequential()
modelSC.add(Dense(units=64, input_dim=5078, activation=&quot;relu&quot;))
modelSC.add(Dense(units=32, activation=&quot;relu&quot;))
modelSC.add(Dense(units=100, activation=&quot;relu&quot;))
modelSC.add(Dense(units=24, activation=&quot;sigmoid&quot;))"><pre class="notranslate"><code class="notranslate">**model1**
model= Sequential()
model.add(Dense(units=64, input_dim=5078, activation="relu"))
model.add(Dense(units=32, activation="relu"))
model.add(Dense(units=100, activation="relu"))
model.add(Dense(units=24, activation="sigmoid"))

**model2**
modelSC= Sequential()
modelSC.add(Dense(units=64, input_dim=5078, activation="relu"))
modelSC.add(Dense(units=32, activation="relu"))
modelSC.add(Dense(units=100, activation="relu"))
modelSC.add(Dense(units=24, activation="sigmoid"))
</code></pre></div>
<p dir="auto">I would like the penultimate layers in each model to merge before the output: (Dense 100)</p>
<p dir="auto">My first question: Both models are comprised of multiple layers: The keras documentations states the following for layer merging:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="left_branch = Sequential()
left_branch= Sequential()
left_branch.add(Dense(units=64, input_dim=5078, activation=&quot;relu&quot;))
left_branch.add(Dense(units=32, activation=&quot;relu&quot;))
left_branch.add(Dense(units=100, activation=&quot;relu&quot;))

right_branch = Sequential()
right_branch= Sequential()
right_branch.add(Dense(units=64, input_dim=5078, activation=&quot;relu&quot;))
right_branch.add(Dense(units=32, activation=&quot;relu&quot;))
right_branch.add(Dense(units=100, activation=&quot;relu&quot;))

merged = Concatenate([left_branch, right_branch])

final_model.add(Dense(24, activation='sigmoid'))

final_model.compile(optimizer='adam', loss='binary_crossentropy')
final_model.fit([X_train, X_trainSC], trainingtarget1)"><pre class="notranslate"><code class="notranslate">left_branch = Sequential()
left_branch= Sequential()
left_branch.add(Dense(units=64, input_dim=5078, activation="relu"))
left_branch.add(Dense(units=32, activation="relu"))
left_branch.add(Dense(units=100, activation="relu"))

right_branch = Sequential()
right_branch= Sequential()
right_branch.add(Dense(units=64, input_dim=5078, activation="relu"))
right_branch.add(Dense(units=32, activation="relu"))
right_branch.add(Dense(units=100, activation="relu"))

merged = Concatenate([left_branch, right_branch])

final_model.add(Dense(24, activation='sigmoid'))

final_model.compile(optimizer='adam', loss='binary_crossentropy')
final_model.fit([X_train, X_trainSC], trainingtarget1)
</code></pre></div>
<p dir="auto">For the <code class="notranslate">model.fit</code> call. I don't understand how to implement from training and test data, each tensor that comes from the different models, and also the one-hot data is different in each one, number of samples etc. the model.fit doesn't appear to support adding all of these elements.</p>
<p dir="auto">Can anybody offer any advice on how to resolve this/further clarify where I have made a mistake? The goal of what I am trying to do is to is to have 2 models (or more in the future with different data sources[that are not the same as each other]), for all the data to be shared at one layer in order to further inform the final classification.</p>
<p dir="auto">Also, idf two models contain different amounts of layers each, is there a default by which keras defines which layers become merged? is is the last layer in right or left_branch.add?</p>
<p dir="auto">Thank you for your time!</p>
<p dir="auto">I request that the global precision, recall and f1 metrics (for binary classification) be added to callbacks.py. It would be useful for users if they could see their model's precision, recall or f1 score on the validation data (after each epoch). Many times, these metrics are more useful than simple accuracy.<br>
Thank you!</p>
<ul dir="auto">
<li>
<p dir="auto">[y] Check that you are up-to-date with the master branch of Keras. You can update with:<br>
<code class="notranslate">pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps</code></p>
</li>
<li>
<p dir="auto">[y] Check that your version of TensorFlow is up-to-date. The installation instructions can be found <a href="https://www.tensorflow.org/get_started/os_setup" rel="nofollow">here</a>.</p>
</li>
<li>
<p dir="auto">[] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).</p>
</li>
</ul>