forked from szagoruyko/imagine-nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpatialCrossResponseNormalization.lua
35 lines (27 loc) · 1.1 KB
/
SpatialCrossResponseNormalization.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local C = inn.C
local SpatialCrossResponseNormalization, parent = torch.class('inn.SpatialCrossResponseNormalization', 'nn.Module')
function SpatialCrossResponseNormalization:__init(size, alpha, beta, k)
parent.__init(self)
self.size = size
self.alpha = alpha or 0.0001
self.beta = beta or 0.75
self.k = k or 1
self.output = torch.Tensor()
self.gradInput = torch.Tensor()
self.scale = torch.Tensor()
self:cuda()
end
function SpatialCrossResponseNormalization:updateOutput(input)
assert(torch.isTypeOf(input, 'torch.CudaTensor'))
C.LRNforward(cutorch.getState(), input:cdata(), self.output:cdata(),
self.scale:cdata(), self.size, self.alpha, self.beta, self.k)
return self.output
end
function SpatialCrossResponseNormalization:updateGradInput(input, gradOutput)
assert(torch.isTypeOf(input, 'torch.CudaTensor'))
assert(torch.isTypeOf(gradOutput, 'torch.CudaTensor'))
C.LRNbackward(cutorch.getState(), input:cdata(), self.output:cdata(),
gradOutput:cdata(), self.gradInput:cdata(), self.scale:cdata(),
self.size, self.alpha, self.beta, self.k)
return self.gradInput
end