In this section, we will use the same simulated dataset that we created in the previous section of this recipe, Sequential API. Here, we will create a multi-output functional model:
- Let's start by importing the required library and create an input layer:
library(keras)# input layerinputs <- layer_input(shape = c(784))
- Next, we need to define two outputs:
predictions1 <- inputs %>% layer_dense(units = 8)%>% layer_activation('relu') %>% layer_dense(units = 1,name = "pred_1")predictions2 <- inputs %>% layer_dense(units = 16)%>% layer_activation('tanh') %>% layer_dense(units = 1,name = "pred_2")
- Now, we need to define a functional Keras model:
model_functional = keras_model(inputs = inputs,outputs = c(predictions1,predictions2)) ...