-
Notifications
You must be signed in to change notification settings - Fork 3
/
shareOpts.lua
90 lines (79 loc) · 3.53 KB
/
shareOpts.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local utee = require 'utee'
local M = { }
function M.getProject(arg)
local project
for k, v in ipairs(arg) do
if v == '-project' then
project = arg[k+1]
break
end
end
assert(project, 'Please specify a project')
return project
end
function M.option()
local cmd = torch.CmdLine()
cmd:text()
cmd:text('General Arguments Options:')
------------ General options --------------------
cmd:option('-manualSeed', 11, 'Manually set RNG seed')
cmd:option('-nGPU', 1, 'Number of GPUs to use by default')
cmd:option('-backend', 'cudnn', 'Options: cudnn | cunn')
cmd:option('-cudnn', 'deterministic', 'Options: fastest | default | deterministic')
cmd:option('-gen', 'gen', 'Path to save generated files')
cmd:option('-project', 'none', 'Project name')
cmd:option('-dataloader', 'dataloader','Data loader path')
cmd:option('-snapshotPath', 'none', 'The snapshot path to resume')
cmd:option('-shareGradInput', 'false', 'Share gradInput tensors to reduce memory usage')
cmd:option('-experimentsName', 'none', 'The name of this experiment')
cmd:option('-stopNSamples', -1, 'When to stop after some mini-batches, -1 represent not stop')
------------- Data options ------------------------
cmd:option('-data', '/work/shadow/', 'imagenet data path')
cmd:option('-dataset', 'none', 'Dataset want to load')
cmd:option('-nThreads', 1, 'number of data loading threads')
------------- Training options --------------------
cmd:option('-nEpochs', 1, 'Number of total epochs to run')
cmd:option('-batchSize', 32, 'mini-batch size (1 = pure stochastic)')
cmd:option('-testOnly', 'false', 'Run on validation set only')
cmd:option('-tenCrop', 'false', 'Ten-crop testing')
---------- Optimization options ----------------------
cmd:option('-LR', 0.1, 'initial learning rate')
cmd:option('-momentum', 0.9, 'momentum')
cmd:option('-weightDecay', 1e-4, 'weight decay')
cmd:option('-nesterov', 'true', 'nesterov')
---------- Model options ----------------------------------
cmd:option('-netType', 'baseline', 'Model name')
cmd:option('-device', 'gpu', 'GPU or CPU mode')
cmd:option('-debug', 'false', 'Whether to print the info for debuging')
cmd:option('-swapChannel', 'false', 'Swap the first convolution kernel')
cmd:text()
return cmd
end
function M.parse(cmd, arg)
local opt = cmd:parse(arg or {})
opt.testOnly = opt.testOnly ~= 'false'
opt.tenCrop = opt.tenCrop ~= 'false'
opt.shareGradInput = opt.shareGradInput ~= 'false'
opt.nesterov = opt.nesterov ~= 'false'
if opt.experimentsName == 'none' then
cmd:error('Experiment name required')
end
-- handle workspace and exps dir
local expsPath = paths.concat('project', opt.project, 'exps')
opt.workspace = paths.concat(expsPath, opt.experimentsName)
if not paths.filep(expsPath) then
paths.mkdir(expsPath)
end
-- test only
if opt.testOnly then
print('Test Mode')
end
if opt.device ~= 'cpu' and opt.device ~= 'gpu' then
cmd:error(('Unknown device : %s'):foramt(opt.device))
end
assert(opt.dataset ~= 'none', 'Dataset required')
opt.debug = opt.debug ~= 'false'
opt.swapChannel = opt.swapChannel ~= 'false'
return opt
end
return M