forked from fqnchina/CEILNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputeYGrad.lua
More file actions
24 lines (20 loc) · 801 Bytes
/
ComputeYGrad.lua
File metadata and controls
24 lines (20 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local ComputeYGrad, parent = torch.class('nn.ComputeYGrad', 'nn.Module')
function ComputeYGrad:__init()
parent.__init(self)
end
function ComputeYGrad:updateOutput(input)
local height = input:size(3)
self.output = torch.csub(input:narrow(3,2,height-1),input:narrow(3,1,height-1))
return self.output
end
function ComputeYGrad:updateGradInput(input, gradOutput)
local height = input:size(3)
self.gradInput:resizeAs(input)
local temp1 = self.gradInput:narrow(3,1,1)
temp1:copy(-gradOutput:narrow(3,1,1))
local temp2 = self.gradInput:narrow(3,height,1)
temp2:copy(gradOutput:narrow(3,height-1,1))
local temp3 = self.gradInput:narrow(3,2,height-2)
temp3:copy(torch.csub(gradOutput:narrow(3,1,height-2),gradOutput:narrow(3,2,height-2)))
return self.gradInput
end