What’s the purpose of keras.backend.function()

I have the following understanding of this function keras.backend.function. I will explain it with the help of a code snippet from this.

The part of code snippet is as follows

final_conv_layer = get_output_layer(model, "conv5_3")
get_output = K.function([model.layers[0].input], 
                        [final_conv_layer.output, model.layers[-1].output])
[conv_outputs, predictions] = get_output([img])
    

In this code, there is a model from which conv5_3 layer is extracted (line 1). In the function K.function(), the first argument is input to this model and second is set of 2 outputs – one for convolution and second for softmax output at the last layer.

As per the Keras/Tensorflow manual, this function runs the computation graph that we have created in the code, taking input from the first parameter and extracting the number of outputs as per the layers mentioned in the second parameter. Thus, conv_outputs are output of final_conv_layer and predictions are output of model.layers[-1], i.e. the last layer of the model.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)