CommencerCommencer gratuitement

It's a flow of tensors

If you have already built a model, you can use the model.layers and the tensorflow.keras.backend to build functions that, provided with a valid input tensor, return the corresponding output tensor.

This is a useful tool when we want to obtain the output of a network at an intermediate layer.

For instance, if you get the input and output from the first layer of a network, you can build an inp_to_out function that returns the result of carrying out forward propagation through only the first layer for a given input tensor.

So that's what you're going to do right now!

X_test from the Banknote Authentication dataset and its model are preloaded. Type model.summary() in the console to check it.

Cet exercice fait partie du cours

Introduction to Deep Learning with Keras

Afficher le cours

Instructions

  • Import tensorflow.keras.backend as K.
  • Use the model.layers list to get a reference to the input and output of the first layer.
  • Use K.function() to define a function that maps inp to out.
  • Print the results of passing X_test through the 1st layer.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import tensorflow.keras backend
import ____

# Input tensor from the 1st layer of the model
inp = ____.____[____].input

# Output tensor from the 1st layer of the model
out = ____.____

# Define a function from inputs to outputs
inp_to_out = K.function([____], [____])

# Print the results of passing X_test through the 1st layer
print(____([____]))
Modifier et exécuter le code