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

前端 未结 3 657
说谎
说谎 2020-12-29 20:06

The Keras manual doesn\'t say too much:

keras.backend.function(inputs, outputs, updates=None)

Instantiates a Keras function.
Arguments
inputs: List of place         


        
3条回答
  •  梦谈多话
    2020-12-29 20:48

    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.

提交回复
热议问题