-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcheckpoints.lua
38 lines (30 loc) · 963 Bytes
/
checkpoints.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
local checkpoint = {}
function checkpoint.latest(opt)
if opt.resume == 'none' then
return nil
end
local latestPath = paths.concat(opt.resume, 'latest.t7')
if not paths.filep(latestPath) then
return nil
end
print('=> Loading checkpoint ' .. latestPath)
local latest = torch.load(latestPath)
local optimState = torch.load(paths.concat(opt.resume, latest.optimFile))
return latest, optimState
end
function checkpoint.save(epoch, model, optimState)
-- Don't save the DataParallelTable for easier loading on other machines
if torch.type(model) == 'nn.DataParallelTable' then
model = model:get(1)
end
local modelFile = 'model_' .. epoch .. '.t7'
local optimFile = 'optimState_' .. epoch .. '.t7'
torch.save(modelFile, model)
torch.save(optimFile, optimState)
torch.save('latest.t7', {
epoch = epoch,
modelFile = modelFile,
optimFile = optimFile,
})
end
return checkpoint