我想创建一个高斯激活函数,在这里我要训练平均值和标准偏差。因此,使用自定义图层,我返回了平均值和 std ,但是无法提取学习到的参数并将其馈送到激活单元。
MyLayer(Layer)类:
def __init__(self, output_dim,m,st, **kwargs):
self.units = output_dim
self.m=m
self.st=st
super(MyLayer, self).__init__(**kwargs)
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.kernel = self.add_weight(name='kernel',
shape=(input_shape[1], self.output_dim),
initializer='uniform',
trainable=True)
self.m = self.add_weight(name='mean',
shape=(1, 1),
initializer='uniform',
trainable=True)
self.std = self.add_weight(name='std',
shape=(1, 1),
initializer='uniform',
trainable=True)
super(MyLayer, self).build(input_shape) # Be sure to call this at the end
def call(self, x):
return K.dot(x, self.kernel)
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim,m,std)
如何与此自定义层一起使用自定义激活功能