How to implement L2-norm pooling in Keras?

旧巷老猫 提交于 2019-12-08 05:02:34

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/43728873/how-to-implement-l2-norm-pooling-in-keras

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!