How to do it...

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:

  1. Let's start by importing the required library and create an input layer:
library(keras)# input layerinputs <- layer_input(shape = c(784))
  1. 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")
  1. Now, we need to define a functional Keras model:
model_functional = keras_model(inputs = inputs,outputs = c(predictions1,predictions2)) ...

Get Deep Learning with R Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.