Keras retrieve value of node before activation function

前端 未结 5 1386
感动是毒
感动是毒 2021-02-07 00:48

Imagine a fully-connected neural network with its last two layers of the following structure:

[Dense]
    units = 612
    activation = softplus

[Dense]
    unit         


        
5条回答
  •  清歌不尽
    2021-02-07 01:19

    So this is for fellow googlers, the working of the keras API has changed significantly since the accepted answer was posted. The working code for extracting a layer's output before activation (for tensorflow backend) is:

    model = Your_Keras_Model()
    the_tensor_you_need = model.output.op.inputs[0] #<- this is indexable, if there are multiple inputs to this node then you can find it with indexing.
    

    In my case, the final layer was a dense layer with activation softmax, so the tensor output I needed was .

提交回复
热议问题