You will come across scenarios where you'll want the output of one model in order to feed it into another model alongside another input. The layer_concatenate() function can be used to do this. Let's define a new input that we will concatenate with the predictions1 output layer we defined in the How to do it section of this recipe and build a model:
# Define new input of the model
new_input <- layer_input(shape = c(5), name = "new_input")
# Define output layer of new model
main_output <- layer_concatenate(c(predictions1, new_input)) %>%
layer_dense(units = 64, activation = 'relu') %>%
layer_dense(units = 1, activation = 'sigmoid', name = 'main_output')
# We define a multi input and multi output model
model <- keras_model(
inputs = c(inputs, new_input),
outputs = c(predictions1, main_output)
)
We can visualize the summary of the model using the summary() function.
It is good practice to give different layers unique names while working with complex models.