def call(self, x, mask=None):
X = x
half_n = self.n // 2
input_sqr = K.square(X)
if K._BACKEND == 'theano':
b, ch, r, c = X.shape
extra_channels = T.alloc(0., b, ch + 2*half_n, r, c)
input_sqr = T.set_subtensor(
extra_channels[:, half_n:half_n+ch, :, :], input_sqr)
elif K._BACKEND == 'tensorflow':
b, ch, r, c = K.int_shape(X)
up_dims = tf.pack([tf.shape(X)[0], half_n, r, c])
up = tf.fill(up_dims, 0.0)
middle = input_sqr
down_dims = tf.pack([tf.shape(X)[0], half_n, r, c])
down = tf.fill(down_dims, 0.0)
input_sqr = K.concatenate([up, middle, down], axis=1)
scale = self.k
norm_alpha = self.alpha / self.n
for i in range(self.n):
scale += norm_alpha * input_sqr[:, i:i+ch, :, :]
scale = scale ** self.beta
result = X / scale
return result
评论列表
文章目录