-
Notifications
You must be signed in to change notification settings - Fork 79
/
options.py
179 lines (160 loc) · 6.16 KB
/
options.py
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
"""Parsing arguments from the commandline"""
import argparse
import numpy as np
import torch
import torch.nn.functional as F
def parse_arguments():
"""Parse input arguments"""
parser = argparse.ArgumentParser("Pytorch 3D Point Cloud Generation")
# Training related
parser.add_argument(
"--experiment", default="0",
help="name for experiment")
parser.add_argument(
"--model", default="PCG",
help="name for model")
parser.add_argument(
"--path", default="data",
help="path to data folder")
parser.add_argument(
"--category", default="03001627",
help="category ID number")
parser.add_argument(
"--phase", type=str, default="stg1",
help="stg1, stg2, eval")
# For stage 2
parser.add_argument(
"--loadPath", type=str, default=None,
help="path to load model")
parser.add_argument(
"--loadEpoch", type=int, default=None,
help="model to load in loadPath, default load best")
parser.add_argument(
"--startEpoch", type=int, default=0,
help="start training from epoch")
parser.add_argument(
"--endEpoch", type=int, default=1000,
help="stop training at epoch")
parser.add_argument(
"--saveEpoch", type=int, default=None,
help="checkpoint model every --saveEpoch, None: best model only"
)
parser.add_argument(
"--chunkSize", type=int, default=100,
help="number of unique CAD models in each batch")
parser.add_argument(
"--batchSize", type=int, default=100,
help="number of unique images from chunkSize CADs models")
# Optimizer
parser.add_argument(
"--optim", type=str, default='sgd',
choices=['adam', 'sgd'],
help="what optimizer to use (adam/sgd)")
parser.add_argument(
"--lr", type=float, default=1e-4,
help="max learning rate")
parser.add_argument(
"--wd", type=float, default=0.0,
help="value for weight decay as implemented (L2 norm)")
parser.add_argument(
"--trueWD", type=float, default=0,
help="value for TRUE weight decay")
parser.add_argument(
"--momentum", type=float, default=0,
help="value formomentum, default=None")
# LR scheduler
parser.add_argument(
"--lrSched", type=str, default=None,
choices=['annealing', 'cyclical', 'restart'],
help="What learning rate scheduler to use")
parser.add_argument(
"--lrBase", type=float, default=0.3,
help="Base learning rate")
parser.add_argument(
"--lrStep", type=int, default=55,
help="Step size (#epoch) of lrSched, 2 steps == 1 cycle // 1 step -> restart")
parser.add_argument(
"--lrGamma", type=float, default=0.9,
help="Multiplicative factor of learning rate decay")
parser.add_argument(
"--lrRestart", type=str, default=None,
help="How many step to warm restart SGD/Adam's lr")
# For SGDR
parser.add_argument(
"--T_0", type=int, default=10,
help="number of epoch per cycle")
parser.add_argument(
"--T_mult", type=int, default=10,
help="multiplicative value for T0")
parser.add_argument(
"--gpu", type=int, default=0,
help="which GPU to use")
# For LR Finder only
parser.add_argument(
"--startLR", type=float, default=1e-7,
help="start range of lr in LR Finder")
parser.add_argument(
"--endLR", type=float, default=10,
help="end range of lr in LR Finder")
parser.add_argument(
"--itersLR", type=float, default=10,
help="Number of iterations to explore LR")
# Model related
parser.add_argument(
"--lambdaDepth", type=float, default=1.0,
help="loss weight factor (depth)")
parser.add_argument(
"--std", type=float, default=0.1,
help="initialization standard deviation")
parser.add_argument(
"--novelN", type=int, default=5,
help="number of novel views simultaneously")
parser.add_argument(
"--outViewN", type=int, default=8,
help="number of fixed views (output)")
parser.add_argument(
"--inSize", default="64x64",
help="resolution of encoder input")
parser.add_argument(
"--outSize", default="128x128",
help="resolution of decoder output")
parser.add_argument(
"--predSize", default="128x128",
help="resolution of prediction")
parser.add_argument(
"--upscale", type=int, default=5,
help="upscaling factor for rendering")
return parser.parse_args()
def get_arguments():
cfg = parse_arguments()
# these stay fixed
cfg.sampleN = 100
cfg.renderDepth = 1.0
cfg.BNepsilon = 1e-5
cfg.BNdecay = 0.999
cfg.inputViewN = 24
# ------ below automatically set ------
cfg.device = torch.device(
f"cuda:{cfg.gpu}" if torch.cuda.is_available() else "cpu")
cfg.inH, cfg.inW = [int(x) for x in cfg.inSize.split("x")]
cfg.outH, cfg.outW = [int(x) for x in cfg.outSize.split("x")]
cfg.H, cfg.W = [int(x) for x in cfg.predSize.split("x")]
cfg.Khom3Dto2D = torch.Tensor([[cfg.W, 0, 0, cfg.W / 2],
[0, -cfg.H, 0, cfg.H / 2],
[0, 0, -1, 0],
[0, 0, 0, 1]]).float().to(cfg.device)
cfg.Khom2Dto3D = torch.Tensor([[cfg.outW, 0, 0, cfg.outW / 2],
[0, -cfg.outH, 0, cfg.outH / 2],
[0, 0, -1, 0],
[0, 0, 0, 1]]).float().to(cfg.device)
cfg.fuseTrans = F.normalize(
torch.from_numpy(
np.load(f"{cfg.path}/trans_fuse{cfg.outViewN}.npy")),
p=2, dim=1).to(cfg.device)
print(f"EXPERIMENT: {cfg.model}_{cfg.experiment}")
print("------------------------------------------")
print(f"input:{cfg.inH}x{cfg.inW}, output:{cfg.outH}x{cfg.outW}, pred:{cfg.H}x{cfg.W}")
print(f"viewN:{cfg.outViewN}(out), upscale:{cfg.upscale}, novelN:{cfg.novelN}")
print(f"Device: {cfg.device}, depth_loss weight:{cfg.lambdaDepth}")
print("------------------------------------------")
return cfg