本文介绍了如何在Keras中实现L2范数池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CNN上添加一个全局时间池层,该层具有三种不同的池功能:均值,最大值和L2-范数. Keras具有平均和最大池化功能,但我无法为L2找到一个.我怎么能自己实现呢?

I would like to add a global temporal pooling layer to my CNN that has three different pooling functions: mean, maximum, and L2-norm. Keras has mean and maximum pooling functions but I haven't been able to find one for L2. How could I implement this myself?

推荐答案

我也在寻找这个,在keras中没有开箱即用的功能.但是您可以使用Lambda层实现它

I was also looking for this, there's no such pool out of the box in keras.But you can implement it with the Lambda Layer

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

def l2_norm(x):
    x = x ** 2
    x = K.sum(x, axis=1)
    x = K.sqrt(x)
    return x
global_l2 = Lambda(lambda x: l2_norm(x))(previous_layer)

这篇关于如何在Keras中实现L2范数池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:33