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.
Diese Übung ist Teil des Kurses
<Kurs>Introduction to Deep Learning with Keras</Kurs>Übungsanweisungen
- Import
tensorflow.keras.backendasK. - Use the
model.layerslist to get a reference to the input and output of the first layer. - Use
K.function()to define a function that mapsinptoout. - Print the results of passing
X_testthrough the 1st layer.
Interaktive praktische Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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(____([____]))