forked from clementfarabet/lua---nnx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trainer.lua
40 lines (34 loc) · 872 Bytes
/
Trainer.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
36
37
38
39
40
local Trainer = torch.class('nn.Trainer')
function Trainer:__init()
self.learningRate = 0.01
self.learningRateDecay = 0
self.maxIteration = 25
end
function Trainer:train(dataset)
end
function Trainer:write(file)
file:writeDouble(self.learningRate)
file:writeDouble(self.learningRateDecay)
file:writeInt(self.maxIteration)
end
function Trainer:read(file)
self.learningRate = file:readDouble()
self.learningRateDecay = file:readDouble()
self.maxIteration = file:readInt()
end
function Trainer:share(mlp, ...)
for i,v in ipairs(arg) do
if self[v] ~=nil then self[v]:set(mlp[v]) end
end
end
function Trainer:clone(...)
local f = torch.MemoryFile("rw"):binary()
f:writeObject(self)
f:seek(1)
local clone = f:readObject()
f:close()
if select('#',...) > 0 then
clone:share(self,...)
end
return clone
end