R, keras: How to get output of a hidden layer?
You can get the answer here.
Here it is:
model &lt;- ...  # create the original model
layer_name &lt;- 'my_layer'
intermediate_layer_model &lt;- keras_model(inputs = model$input,
                                    outputs = get_layer(model, layer_name)$output)
intermediate_output &lt;- predict(intermediate_layer_model, data)