-
Notifications
You must be signed in to change notification settings - Fork 95
/
opts.lua
143 lines (124 loc) · 6.07 KB
/
opts.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--
-- Copyright (c) 2016-2017, Fangchang Ma.
-- Copyright (c) 2016, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
--
local M = { }
function M.parse(arg)
local cmd = torch.CmdLine()
cmd:text()
cmd:text('Sparse-to-Dense Training script')
cmd:text('See https://github.com/fangchangma/sparse-to-dense for details')
cmd:text()
cmd:text('Train Options:')
------------ Model options --------------------
cmd:option('-dataset', 'nyudepthv2', 'Options: nyudepthv2 | kitti')
cmd:option('-inputType', 'rgb', 'Options: rgb | rgbd | d | g | gd')
cmd:option('-nSample', 0, 'average number of depth samples')
cmd:option('-criterion', 'l1', 'Options: l1 | l2 | berhu')
cmd:option('-pretrain', 'false', 'use pretrained model')
cmd:option('-rep', 'linear', 'Representation of depth. Options: linear | log | inverse')
cmd:option('-encoderType', 'conv', 'Options: conv | channeldrop | depthsep')
cmd:option('-decoderType', 'upproj', 'Options: deconv2 | deconv3 | upconv | upproj')
------------ General options --------------------
cmd:option('-manualSeed', 0, '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', 'fastest', 'Options: fastest | default | deterministic')
cmd:option('-gen', 'gen', 'Path to save generated files')
cmd:option('-precision', 'single', 'Options: single | double | half')
------------- Data options ------------------------
cmd:option('-nThreads', 2, 'number of data loading threads')
------------- Training options --------------------
cmd:option('-nEpochs', 20, 'Number of total epochs to run')
cmd:option('-epochNumber', 1, 'Manual epoch number (useful on restarts)')
cmd:option('-batchSize', 16, 'mini-batch size (1 = pure stochastic)')
cmd:option('-testOnly', 'false', 'Run on validation set only')
cmd:option('-tenCrop', 'false', 'Ten-crop testing')
cmd:option('-resume', 'none', 'Path to directory containing checkpoint')
---------- Optimization options ----------------------
cmd:option('-LR', 0.01, 'initial learning rate')
cmd:option('-momentum', 0.9, 'momentum')
cmd:option('-weightDecay', 1e-4, 'weight decay')
cmd:option('-recomputeBatchNorm', 'false', 'recompute batch norm statistics')
---------- Model options ----------------------------------
cmd:option('-shortcutType', '', 'Options: A | B | C')
cmd:option('-optimState', 'none', 'Path to an optimState to reload from')
cmd:option('-optnet', 'true', 'Use optnet to reduce memory usage')
cmd:option('-nClasses', 0, 'Number of classes in the dataset')
cmd:text()
local opt = cmd:parse(arg or {})
opt.testOnly = opt.testOnly ~= 'false'
opt.tenCrop = opt.tenCrop ~= 'false'
opt.recomputeBatchNorm = opt.recomputeBatchNorm ~= 'false'
opt.data = paths.concat('data', opt.dataset)
if opt.dataset == '' then
cmd:error('-dataset required. Options: nyudepthv2 | kitti')
elseif opt.dataset == 'nyudepthv2' or opt.dataset == 'kitti' then
local trainDir = paths.concat(opt.data, 'train')
local testDir = paths.concat(opt.data, 'val')
if not paths.dirp(opt.data) then
cmd:error('error: missing directory ./data/' .. opt.dataset)
elseif not paths.dirp(trainDir) then
cmd:error('error: ' .. opt.dataset .. ' missing `train` directory: ' .. trainDir)
elseif not paths.dirp(testDir) then
cmd:error('error: ' .. opt.dataset .. ' missing `val` directory: ' .. testDir)
end
else
cmd:error('unknown dataset: ' .. opt.dataset)
end
-- Default shortcutType=B and nEpochs=90
opt.shortcutType = opt.shortcutType == '' and 'B' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 20 or opt.nEpochs
-- Number of samples
if opt.inputType == 'rgb' then
opt.nSample = 0
end
-- Tensor type
if opt.precision == nil or opt.precision == 'single' then
opt.tensorType = 'torch.CudaTensor'
elseif opt.precision == 'double' then
opt.tensorType = 'torch.CudaDoubleTensor'
elseif opt.precision == 'half' then
opt.tensorType = 'torch.CudaHalfTensor'
else
cmd:error('unknown precision: ' .. opt.precision)
end
-- Save directory
local saveDir = paths.concat('results', ('%s.input=%s.nsample=%d.rep=%s.encoder=%s.decoder=%s.criterion=%s.lr=%g.bs=%d.pretrained=%s'):format
(opt.dataset, opt.inputType, opt.nSample, opt.rep, opt.encoderType, opt.decoderType, opt.criterion, opt.LR, opt.batchSize, opt.pretrain))
if opt.resume~='none' then
opt.saveDir = opt.resume
else
opt.saveDir = saveDir
end
-- Model Depth
if opt.dataset == 'nyudepthv2' then
opt.depth = 50
else
opt.depth = 18
end
opt.pretrain = opt.pretrain ~= 'false'
if opt.pretrain then
if opt.resume~='none' then
cmd:error('error: cannot simultaneously load pretrained model and resume previous training')
end
opt.pretrainedPath = paths.concat('pretrained', 'resnet-'..opt.depth..'.t7')
if not opt.testOnly and not paths.filep(opt.pretrainedPath) then
cmd:error('error: pretrained model ' .. opt.pretrainedPath .. ' not found')
end
end
if opt.testOnly then
opt.bestmodelPath = paths.concat(opt.saveDir, 'model_best.t7')
if not paths.filep(opt.bestmodelPath) then
cmd:error('error: trained model does not exist: ' .. opt.bestmodelPath)
end
end
print('Result directory: ' .. opt.saveDir)
return opt
end
return M