def localResponseNormalizationCrossChannel(incoming, alpha=1e-4,
k=2, beta=0.75, n=5):
"""
Implement the local response normalization cross the channels described
in <ImageNet Classification with Deep Convolutional Neural Networks>,
A.Krizhevsky et al. sec.3.3.
Reference of the code:
https://github.com/Lasagne/Lasagne/blob/master/lasagne/layers/
normalization.py
https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/expr/normalize.py
Parameters:
incomping: The feature maps. (output of the convolution layer).
alpha: float scalar
k: float scalr
beta: float scalar
n: integer: number of adjacent channels. Must be odd.
"""
if n % 2 == 0:
raise NotImplementedError("Works only with odd n")
input_shape = incoming.shape
half_n = n // 2
input_sqr = T.sqr(incoming)
b, ch, r, c = input_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)
scale = k
for i in range(n):
scale += alpha * input_sqr[:, i:i+ch, :, :]
scale = scale ** beta
return incoming / scale
评论列表
文章目录