Keras retrieve value of node before activation function

前端 未结 5 1233
感动是毒
感动是毒 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:28

    easy way to define new layer with new activation function:

    def change_layer_activation(layer):
    
        if isinstance(layer, keras.layers.Conv2D):
    
            config = layer.get_config()
            config["activation"] = "linear"
            new = keras.layers.Conv2D.from_config(config)
    
        elif isinstance(layer, keras.layers.Dense):
    
            config = layer.get_config()
            config["activation"] = "linear"
            new = keras.layers.Dense.from_config(config)
    
        weights = [x.numpy() for x in layer.weights]
    
        return new, weights
    

提交回复
热议问题