如何在Keras中实现L2池化层?

时间:2019-06-27 01:45:54

标签: tensorflow machine-learning keras keras-layer

我试图找出是否有任何方法可以在Keras中实现L2池化层。有谁知道如何处理它?<​​/ p>

1 个答案:

答案 0 :(得分:0)

this答案的基础上,我在此处的评论中提到的是您要查找的L2-norm池化层。

from keras.layers import Lambda
import keras.backend as K

def l2_norm2d(x, pool_size = (2,2), strides = None,
             padding = 'valid', data_format=None):
    if strides is None:
        strides = pool_size
    x = x ** 2
    output = K.pool2d(x, pool_size, strides,
                          padding, data_format, pool_mode='avg')
    output  = K.sqrt(output)
    return output