-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathopts.lua
183 lines (170 loc) · 9.69 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
--
-- 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('Torch-7 ResNet Training script')
cmd:text('See https://github.com/facebook/fb.resnet.torch/blob/master/TRAINING.md for examples')
cmd:text()
cmd:text('Options:')
------------ General options --------------------
cmd:option('-data', '', 'Path to dataset')
cmd:option('-dataset', 'pdb', 'Options: pdbs | emdb | pemd | cifar10')
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')
------------ xukui
cmd:option('-hdf', 'false', 'use hdf formated file')
cmd:option('-gendata', 'gen', 'Path to save generated files')
cmd:option('-dataaug', '1', 'Data Augmentation, density multiple 1,10,1000')
cmd:option('-dataprepro', '0', 'Data Preprocess 0:no prepro, 1:mean, 2:low-pass-filter, 3:mesh')
cmd:option('-debug', 0, 'Debug mode:0,1,2')
cmd:option('-train_data', '', 'txt file containing train h5 filenames')
cmd:option('-test_data', '', 'txt file containing test h5 filenames')
------------- Data options ------------------------
cmd:option('-nThreads', 2, 'number of data loading threads')
------------- Training options --------------------
cmd:option('-nEpochs', 0, 'Number of total epochs to run')
cmd:option('-epochNumber', 1, 'Manual epoch number (useful on restarts)')
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')
------------- Checkpointing options ---------------
cmd:option('-save', 'checkpoints', 'Directory in which to save checkpoints')
cmd:option('-resume', 'none', 'Resume from the latest checkpoint in this directory')
---------- Optimization options ----------------------
cmd:option('-LR', 0.1, 'initial learning rate')
cmd:option('-momentum', 0.9, 'momentum')
cmd:option('-weightDecay', 1e-4, 'weight decay')
---------- Model options ----------------------------------
cmd:option('-netType', 'resnet', 'Options: resnet | preresnet')
cmd:option('-depth', 34, 'ResNet depth: 18 | 34 | 50 | 101 | ...', 'number')
cmd:option('-shortcutType', '', 'Options: A | B | C')
cmd:option('-retrain', 'none', 'Path to model to retrain with')
cmd:option('-optimState', 'none', 'Path to an optimState to reload from')
---------- Model options ----------------------------------
cmd:option('-shareGradInput', 'false', 'Share gradInput tensors to reduce memory usage')
cmd:option('-optnet', 'false', 'Use optnet to reduce memory usage')
cmd:option('-resetClassifier', 'false', 'Reset the fully connected layer for fine-tuning')
cmd:option('-nClasses', 10, 'Number of classes in the dataset')
---------- Barry Kui
cmd:option('-datatype', '2dclf', '2dclf, 3dclf(image level), 2dseg, 3dseg(pixel level)')
cmd:option('-lossfunc', 'cross', 'loss function or criterion, cross, nll')
cmd:option('-deconv', 'false', 'Options: resnet | preresnet')
cmd:option('-parallel', 'false', 'Parallel criterion')
cmd:option('-classweight', 'false', 'set classweight for imbalanced case')
cmd:option('-classweights', '[]', '1D Tensor of size nClasses')
cmd:option('-ignore', 'false', 'Ignore label')
cmd:option('-ignorelabel', 99, 'Ignore label n')
cmd:option('-ignorelabels', '1,22', 'Ignore labels, eg. 1,22,23')
cmd:option('-relabels', '1,2', 'relabels, eg. 1,22,23')
cmd:option('-relabelstr', '1,2', 'relabelstr, eg. 1,22,23')
cmd:option('-labelstart0', 'false', 'if your label start from 0, use this option')
cmd:option('-plot', 'false', 'plot netword')
---------- Model options for DenseNet ----------------------------------
cmd:option('-growthRate', 12, 'Number of output channels at each convolutional layer')
cmd:option('-bottleneck', 'true', 'Use 1x1 convolution to reduce dimension (DenseNet-B)')
cmd:option('-reduction', 0.5, 'Channel compress ratio at transition layer (DenseNet-C)')
cmd:option('-dropRate', 0, 'Dropout probability')
cmd:option('-optMemory', 2, 'Optimize memory for DenseNet: 0 | 1 | 2 | 3 | 4 | 5', 'number')
-- The following hyperparameters are activated when depth is not from {121, 161, 169, 201} (for ImageNet only)
cmd:option('-d1', 0, 'Number of layers in block 1')
cmd:option('-d2', 0, 'Number of layers in block 2')
cmd:option('-d3', 0, 'Number of layers in block 3')
cmd:option('-d4', 0, 'Number of layers in block 4')
cmd:text()
local opt = cmd:parse(arg or {})
opt.testOnly = opt.testOnly ~= 'false'
opt.tenCrop = opt.tenCrop ~= 'false'
opt.shareGradInput = opt.shareGradInput ~= 'false'
opt.optnet = opt.optnet ~= 'false'
opt.ignore = opt.ignore ~= 'false'
opt.hdf = opt.hdf ~= 'false'
opt.parallel = opt.parallel ~= 'false'
opt.resetClassifier = opt.resetClassifier ~= 'false'
opt.ignorelabel = opt.nClasses
opt.classweight = opt.classweight ~= 'false'
opt.deconv = opt.deconv ~= 'false'
opt.labelstart0 = opt.labelstart0 ~= 'false'
opt.plot = opt.plot ~= 'false'
--print("================================")
--print("Debug Mode:" .. opt.debug)
--print(("ClassWeight: %s"):format(opt.classweight))
--print(("Deconv: %s"):format(opt.deconv) )
--print(("Igonre: %s"):format(opt.ignore) )
--print(("IgonreLabel: %s"):format(opt.ignorelabel) )
--print(("IgonreLabels: %s"):format(opt.ignorelabels) )
--print("DataAugmentation:" .. opt.dataaug)
--print("DataPreprocess:" .. opt.dataprepro)
--print("================================")
opt.ignorelabels = opt.ignorelabels:split(',')
opt.relabelstr = opt.relabels
opt.relabels = opt.relabels:split(',')
if not paths.dirp(opt.save) and not paths.mkdir(opt.save) then
cmd:error('error: unable to create checkpoint directory: ' .. opt.save .. '\n')
end
print(opt.dataset)
if opt.dataset == 'imagenet' then
-- Handle the most common case of missing -data flag
local trainDir = paths.concat(opt.data, 'train')
if not paths.dirp(opt.data) then
cmd:error('error: missing imagenet simulation data directory')
elseif not paths.dirp(trainDir) then
cmd:error('error: ImageNet missing `train` directory: ' .. trainDir)
end
-- Default shortcutType=B and nEpochs=90
opt.shortcutType = opt.shortcutType == '' and 'B' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 90 or opt.nEpochs
elseif opt.dataset == 'emdb' then
-- Default shortcutType=A and nEpochs=164
opt.shortcutType = opt.shortcutType == '' and 'A' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 164 or opt.nEpochs
elseif opt.dataset == 'mnist' then
-- Default shortcutType=A and nEpochs=164
opt.shortcutType = opt.shortcutType == '' and 'A' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 100 or opt.nEpochs
elseif opt.dataset == 'modelnet' then
-- Default shortcutType=A and nEpochs=164
opt.shortcutType = opt.shortcutType == '' and 'A' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 100 or opt.nEpochs
elseif opt.dataset == 'cifar10' then
-- Default shortcutType=A and nEpochs=164
opt.shortcutType = opt.shortcutType == '' and 'A' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 164 or opt.nEpochs
elseif opt.dataset == 'cifar100' then
-- Default shortcutType=A and nEpochs=164
opt.shortcutType = opt.shortcutType == '' and 'A' or opt.shortcutType
opt.nEpochs = opt.nEpochs == 0 and 164 or opt.nEpochs
else
cmd:error('unknown dataset: ' .. opt.dataset)
end
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
if opt.resetClassifier then
if opt.nClasses == 0 then
cmd:error('-nClasses required when resetClassifier is set')
end
end
if opt.shareGradInput and opt.optnet then
cmd:error('error: cannot use both -shareGradInput and -optnet')
end
return opt
end
return M