-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalmostIdentity.lua
More file actions
40 lines (35 loc) · 917 Bytes
/
almostIdentity.lua
File metadata and controls
40 lines (35 loc) · 917 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local almostIdentity, parent = torch.class('nn.almostIdentity', 'nn.Module')
function almostIdentity:__init()
parent.__init(self)
self.i = 0
end
function almostIdentity:updateOutput(input)
self.output = input
return self.output
end
function almostIdentity:updateGradInput(input, gradOutput)
self.i = self.i+1
if(self.i % 100 == 0) then
print(self.i)
end
self.gradInput = gradOutput
--print(self.gradInput)
return self.gradInput
end
function almostIdentity:clearState()
-- don't call set because it might reset referenced tensors
local function clear(f)
if self[f] then
if torch.isTensor(self[f]) then
self[f] = self[f].new()
elseif torch.type(self[f]) == 'table' then
self[f] = {}
else
self[f] = nil
end
end
end
clear('output')
clear('gradInput')
return self
end