擅长:python、mysql、java
<p>我不认为您需要添加<code>mean</code>和{<cd2>}作为权重。您可以在<code>call</code>函数中计算它们。我也不太明白为什么要用这个来代替<code>BatchNormalization</code>,但是无论如何,也许你可以试试这个代码</p>
<pre><code>class PreprocessLayer(Layer):
def __init__(self, eps=1e-6, **kwargs):
self.eps = eps
super(PreprocessLayer, self).__init__(**kwargs)
def build(self, input_shape):
super(PreprocessLayer, self).build(input_shape)
def call(self, x):
mean = K.mean(x, axis=-1, keepdims=True)
std = K.std(x, axis=-1, keepdims=True)
return (x - mean) / (std + self.eps)
def compute_output_shape(self, input_shape):
return input_shape
</code></pre>
<p><code>eps</code>是为了避免被0除。在</p>
<p>我不能保证这会奏效,但也许可以试试。在</p>