forked from paschalidoud/superquadric_parsing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharguments.py
336 lines (308 loc) · 9.3 KB
/
arguments.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
def add_voxelizer_parameters(parser):
parser.add_argument(
"--voxelizer_factory",
choices=[
"occupancy_grid",
"tsdf_grid",
"image",
"image_rgbd" # Added for RGB-D
],
default="occupancy_grid",
help="The voxelizer factory to be used (default=occupancy_grid)"
)
parser.add_argument(
"--grid_shape",
type=lambda x: tuple(map(int, x.split(","))),
default="32,32,32",
help="The dimensionality of the voxel grid (default=(32, 32, 32)"
)
parser.add_argument(
"--save_voxels_to",
default=None,
help="Path to save the voxelised input to the network"
)
parser.add_argument(
"--image_shape",
type=lambda x: tuple(map(int, x.split(","))),
default="3,137,137",
help="The dimensionality of the voxel grid (default=(3,137,137)"
)
parser.add_argument( # Added for RGB-D
"--image_rgbd_shape",
type=lambda x: tuple(map(int, x.split(","))),
default="4,137,137",
help="The dimensionality of the voxel grid (default=(4,137,137)"
)
def add_training_parameters(parser):
"""Add arguments to a parser that are related with the training of the
network.
"""
parser.add_argument(
"--epochs",
type=int,
default=150,
help="Number of times to iterate over the dataset (default=150)"
)
parser.add_argument(
"--steps_per_epoch",
type=int,
default=500,
help=("Total number of steps (batches of samples) before declaring one"
" epoch finished and starting the next epoch (default=500)")
)
parser.add_argument(
"--batch_size",
type=int,
default=16,
help="Number of samples in a batch (default=32)"
)
parser.add_argument(
"--lr",
type=float,
default=1e-3,
help="Learning rate (default 1e-3)"
)
parser.add_argument(
"--lr_epochs",
type=lambda x: map(int, x.split(",")),
default="500,1000,1500",
help="Training epochs with diminishing learning rate"
)
parser.add_argument(
"--lr_factor",
type=float,
default=1.0,
help=("Factor according to which the learning rate will be diminished"
" (default=None)")
)
parser.add_argument(
"--optimizer",
choices=["Adam", "SGD"],
default="Adam",
help="The optimizer to be used (default=Adam)"
)
parser.add_argument(
"--momentum",
type=float,
default=0.9,
help=("Parameter used to update momentum in case of SGD optimizer"
" (default=0.9)")
)
def add_dataset_parameters(parser):
parser.add_argument(
"--dataset_type",
default="shapenet_quad",
choices=[
"shapenet_quad",
"shapenet_v1",
"shapenet_v2",
"surreal_bodies",
"dynamic_faust"
],
help="The type of the dataset type to be used"
)
parser.add_argument(
"--n_points_from_mesh",
type=int,
default=1000,
help="The maximum number of points sampled from mesh (default=1000)"
)
parser.add_argument(
"--model_tags",
type=lambda x: x.split(":"),
default=[],
help="The tags to the model to be used for testing",
)
def add_nn_parameters(parser):
"""Add arguments to control the design of the neural network architecture.
"""
parser.add_argument(
"--architecture",
choices=["tulsiani", "octnet", "resnet18", "rednet"],
default="tulsiani",
help="Choose the architecture to train"
)
parser.add_argument(
"--train_with_bernoulli",
action="store_true",
help="Learn the Bernoulli priors during training"
)
parser.add_argument(
"--make_dense",
action="store_true",
help="When true use an additional FC before its regressor"
)
def add_regularizer_parameters(parser):
parser.add_argument(
"--regularizer_type",
choices=[
"bernoulli_regularizer",
"entropy_bernoulli_regularizer",
"parsimony_regularizer",
"overlapping_regularizer",
"sparsity_regularizer"
],
nargs="+",
default=[],
help=("The type of the regularizer on the shapes to be used"
" (default=None)")
)
parser.add_argument(
"--bernoulli_regularizer_weight",
type=float,
default=0.0,
help=("The importance of the regularization term on Bernoulli priors"
" (default=0.0)")
)
parser.add_argument(
"--maximum_number_of_primitives",
type=int,
default=5000,
help=("The maximum number of primitives in the predicted shape "
" (default=5000)")
)
parser.add_argument(
"--minimum_number_of_primitives",
type=int,
default=5,
help=("The minimum number of primitives in the predicted shape "
" (default=5)")
)
parser.add_argument(
"--entropy_bernoulli_regularizer_weight",
type=float,
default=0.0,
help=("The importance of the regularizer term on the entropy of"
" the bernoullis (default=0.0)")
)
parser.add_argument(
"--sparsity_regularizer_weight",
type=float,
default=0.0,
help="The weight on the sparsity regularizer (default=0.0)"
)
parser.add_argument(
"--parsimony_regularizer_weight",
type=float,
default=0.0,
help="The weight on the parsimony regularizer (default=0.0)"
)
parser.add_argument(
"--overlapping_regularizer_weight",
type=float,
default=0.0,
help="The weight on the overlapping regularizer (default=0.0)"
)
parser.add_argument(
"--enable_regularizer_after_epoch",
type=int,
default=0,
help="Epoch after which regularizer is enabled (default=10)"
)
parser.add_argument(
"--w1",
type=float,
default=0.005,
help="The weight on the first term of the sparsity regularizer (default=0.005)"
)
parser.add_argument(
"--w2",
type=float,
default=0.005,
help="The weight on the second term of the sparsity regularizer (default=0.005)"
)
def add_sq_mesh_sampler_parameters(parser):
parser.add_argument(
"--D_eta",
type=float,
default=0.05,
help="Step along the eta (default=0.05)"
)
parser.add_argument(
"--D_omega",
type=float,
default=0.05,
help="Step along the omega (default=0.05)"
)
parser.add_argument(
"--n_points_from_sq_mesh",
type=int,
default=180,
help="Number of points to sample from the mesh of the SQ (default=180)"
)
def add_gaussian_noise_layer_parameters(parser):
parser.add_argument(
"--add_gaussian_noise",
action="store_true",
help="Add Gaussian noise in the layers"
)
parser.add_argument(
"--mu",
type=float,
default=0.0,
help="Mean value of the Gaussian distribution"
)
parser.add_argument(
"--sigma",
type=float,
default=0.001,
help="Standard deviation of the Gaussian distribution"
)
def add_loss_parameters(parser):
parser.add_argument(
"--prim_to_pcl_loss_weight",
default=1.0,
type=float,
help=("The importance of the primitive-to-pointcloud loss in the "
"final loss (default = 1.0)")
)
parser.add_argument(
"--pcl_to_prim_loss_weight",
default=1.0,
type=float,
help=("The importance of the pointcloud-to-primitive loss in the "
"final loss (default = 1.0)")
)
def add_loss_options_parameters(parser):
parser.add_argument(
"--use_sq",
action="store_true",
help="Use Superquadrics as geometric primitives"
)
parser.add_argument(
"--use_cuboids",
action="store_true",
help="Use cuboids as geometric primitives"
)
parser.add_argument(
"--use_chamfer",
action="store_true",
help="Use the chamfer distance"
)
def voxelizer_shape(args):
if args.voxelizer_factory == "occupancy_grid":
return args.grid_shape
elif args.voxelizer_factory == "image":
return args.image_shape
elif args.voxelizer_factory == "image_rgbd": # Added for RGB-D
return args.image_rgbd_shape
elif args.voxelizer_factory == "tsdf_grid":
return (args.resolution,)*3
def get_loss_weights(args):
args = vars(args)
loss_weights = {
"pcl_to_prim_weight": args.get("pcl_to_prim_loss_weight", 1.0),
"prim_to_pcl_weight": args.get("prim_to_pcl_loss_weight", 1.0),
}
return loss_weights
def get_loss_options(args):
loss_weights = get_loss_weights(args)
args = vars(args)
# Create a dicitionary with the loss options based on the input arguments
loss_options = {
"use_sq": args.get("use_sq", False),
"use_cuboids": args.get("use_cuboids", False),
"use_chamfer": args.get("use_chamfer", False),
"loss_weights": loss_weights
}
return loss_options