'Keras: get output before activation

In pretrained VGG19 model layers are defined like

x = layers.Conv2D(64, (3, 3),
                  activation='relu',
                  padding='same',
                  name='block1_conv1')(img_input)

I'm using already pretrained network, is it possible to get output before relu activation? or it's only an option to create new model with separate conv2d and activation and copy weights from pretrained model?



Solution 1:[1]

I guess you may disable the activation by model.layers[the layer your want to output].activation = None after loading the pre-trained model. Then compile the model using model.compile(). Then the output of the layer you chose should be before activation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yifei