问题
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