Exercise

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.

Instructions

100 XP
  • 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.