-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.py
executable file
·321 lines (247 loc) · 11.4 KB
/
config.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
#
#
# 0=================================0
# | Kernel Point Convolutions |
# 0=================================0
#
#
# ----------------------------------------------------------------------------------------------------------------------
#
# Configuration class
#
# ----------------------------------------------------------------------------------------------------------------------
#
# Hugues THOMAS - 11/06/2018
#
from os.path import join
class Config:
"""
Class containing the parameters you want to modify for this dataset
"""
##################
# Input parameters
##################
# Dataset name
dataset = ''
# Type of network model
network_model = 'segmentation'
# Number of classes in the dataset
num_classes = 0
# Dimension of input points
in_points_dim = 3
# determines used features (Boolean)
color_info = False
intensity_info = False
# Dimension of input features
if color_info and intensity_info:
in_features_dim = 8
elif color_info:
in_features_dim = 7
elif intensity_info:
in_features_dim = 5
else:
in_features_dim = 4
# Radius of the input sphere (ignored for models, only used for point clouds)
in_radius = 1.000
# Number of CPU threads for the input pipeline
input_threads = 8
##################
# Model parameters
##################
# Architecture definition. List of blocks
architecture = []
# Dimension of the first feature maps
first_features_dim = 64
# Batch normalization parameters
use_batch_norm = True
batch_norm_momentum = 0.99
# For segmentation models : ratio between the segmented area and the input area
segmentation_ratio = 1.0
###################
# KPConv parameters
###################
# First size of grid used for subsampling
first_subsampling_dl = 0.05
# Radius of the kernels in the first layer (deprecated)
first_kernel_radius = 0.1
# Number of points in the kernels
num_kernel_points = 15
# density of neighbors in kernel range
# For each layer, support points are subsampled on a grid with dl = kernel_radius / density_parameter
density_parameter = 3.0
# Kernel point influence radius
KP_extent = 1.000
# Influence function when d < KP_extent. ('constant', 'linear', 'gaussian') When d > KP_extent, always zero
KP_influence = 'gaussian'
# Behavior of convolutions in ('closest', 'sum')
# Decide if you sum all kernel point influences, or if you only take the influence of the closest KP
convolution_mode = 'closest'
# Fixed points in the kernel : 'none', 'center' or 'verticals'
fixed_kernel_points = 'center'
# Can the network learn kernel dispositions (deprecated)
trainable_positions = False
# Use modulateion in deformable convolutions
modulated = False
#####################
# Training parameters
#####################
# Network optimizer parameters (learning rate and momentum)
learning_rate = 1e-4
momentum = 0.9
# Learning rate decays. Dictionary of all decay values with their epoch {epoch: decay}.
lr_decays = {200: 0.2, 300: 0.2}
# Gradient clipping value (negative means no clipping)
grad_clip_norm = 100.0
# Augmentation parameters
augment_scale_anisotropic = True
augment_scale_min = 0.9
augment_scale_max = 1.1
augment_symmetries = [False, False, False]
augment_rotation = 'vertical'
augment_noise = 0.005
augment_occlusion = 'planar'
augment_occlusion_ratio = 0.2
augment_occlusion_num = 1
augment_color = 0.7
# Regularization loss importance
weights_decay = 1e-3
# Gaussian loss
gaussian_decay = 1e-3
# Type of output loss with regard to batches when segmentation
batch_averaged_loss = False
# Point loss DPRECATED
points_loss = ''
points_decay = 1e-2
# Offset regularization loss
offsets_loss = 'permissive'
offsets_decay = 1e-2
# Number of batch
batch_num = 10
# Maximal number of epochs
max_epoch = 1000
# Number of steps per epochs
epoch_steps = 1000
# Number of validation examples per epoch
validation_size = 100
# Number of epoch between each snapshot
snapshot_gap = 50
# Do we nee to save convergence
saving = True
saving_path = None
def __init__(self):
"""
Class Initialyser
"""
# Number of layers
self.num_layers = len([block for block in self.architecture if 'pool' in block or 'strided' in block]) + 1
def load(self, path):
filename = join(path, 'parameters.txt')
with open(filename, 'r') as f:
lines = f.readlines()
# Class variable dictionary
for line in lines:
line_info = line.split()
if len(line_info) > 1 and line_info[0] != '#':
if line_info[2] == 'None':
setattr(self, line_info[0], None)
elif line_info[0] == 'lr_decay_epochs':
self.lr_decays = {int(b.split(':')[0]): float(b.split(':')[1]) for b in line_info[2:]}
elif line_info[0] == 'architecture':
self.architecture = [b for b in line_info[2:]]
elif line_info[0] == 'augment_symmetries':
self.augment_symmetries = [bool(int(b)) for b in line_info[2:]]
elif line_info[0] == 'num_classes':
if len(line_info) > 3:
self.num_classes = [int(c) for c in line_info[2:]]
else:
self.num_classes = int(line_info[2])
else:
attr_type = type(getattr(self, line_info[0]))
if attr_type == bool:
setattr(self, line_info[0], attr_type(int(line_info[2])))
else:
setattr(self, line_info[0], attr_type(line_info[2]))
self.saving = True
self.saving_path = path
self.__init__()
def save(self, path):
with open(join(path, 'parameters.txt'), "w") as text_file:
text_file.write('# -----------------------------------#\n')
text_file.write('# Parameters of the training session #\n')
text_file.write('# -----------------------------------#\n\n')
# Input parameters
text_file.write('# Input parameters\n')
text_file.write('# ****************\n\n')
text_file.write('dataset = {:s}\n'.format(self.dataset))
text_file.write('network_model = {:s}\n'.format(self.network_model))
if type(self.num_classes) is list:
text_file.write('num_classes =')
for n in self.num_classes:
text_file.write(' {:d}'.format(n))
text_file.write('\n')
else:
text_file.write('num_classes = {:d}\n'.format(self.num_classes))
text_file.write('in_points_dim = {:d}\n'.format(self.in_points_dim))
text_file.write('in_features_dim = {:d}\n'.format(self.in_features_dim))
text_file.write('in_radius = {:.3f}\n'.format(self.in_radius))
text_file.write('input_threads = {:d}\n\n'.format(self.input_threads))
# Model parameters
text_file.write('# Model parameters\n')
text_file.write('# ****************\n\n')
text_file.write('architecture =')
for a in self.architecture:
text_file.write(' {:s}'.format(a))
text_file.write('\n')
text_file.write('num_layers = {:d}\n'.format(self.num_layers))
text_file.write('first_features_dim = {:d}\n'.format(self.first_features_dim))
text_file.write('use_batch_norm = {:d}\n'.format(int(self.use_batch_norm)))
text_file.write('batch_norm_momentum = {:.3f}\n\n'.format(self.batch_norm_momentum))
text_file.write('segmentation_ratio = {:.3f}\n\n'.format(self.segmentation_ratio))
# KPConv parameters
text_file.write('# KPConv parameters\n')
text_file.write('# *****************\n\n')
text_file.write('first_subsampling_dl = {:.3f}\n'.format(self.first_subsampling_dl))
text_file.write('num_kernel_points = {:d}\n'.format(self.num_kernel_points))
text_file.write('density_parameter = {:.3f}\n'.format(self.density_parameter))
text_file.write('fixed_kernel_points = {:s}\n'.format(self.fixed_kernel_points))
text_file.write('KP_extent = {:.3f}\n'.format(self.KP_extent))
text_file.write('KP_influence = {:s}\n'.format(self.KP_influence))
text_file.write('convolution_mode = {:s}\n'.format(self.convolution_mode))
text_file.write('trainable_positions = {:d}\n\n'.format(int(self.trainable_positions)))
text_file.write('modulated = {:d}\n\n'.format(int(self.modulated)))
# Training parameters
text_file.write('# Training parameters\n')
text_file.write('# *******************\n\n')
text_file.write('learning_rate = {:f}\n'.format(self.learning_rate))
text_file.write('momentum = {:f}\n'.format(self.momentum))
text_file.write('lr_decay_epochs =')
for e, d in self.lr_decays.items():
text_file.write(' {:d}:{:f}'.format(e, d))
text_file.write('\n')
text_file.write('grad_clip_norm = {:f}\n\n'.format(self.grad_clip_norm))
text_file.write('augment_symmetries =')
for a in self.augment_symmetries:
text_file.write(' {:d}'.format(int(a)))
text_file.write('\n')
text_file.write('augment_rotation = {:s}\n'.format(self.augment_rotation))
text_file.write('augment_noise = {:f}\n'.format(self.augment_noise))
text_file.write('augment_occlusion = {:s}\n'.format(self.augment_occlusion))
text_file.write('augment_occlusion_ratio = {:.3f}\n'.format(self.augment_occlusion_ratio))
text_file.write('augment_occlusion_num = {:d}\n'.format(self.augment_occlusion_num))
text_file.write('augment_scale_anisotropic = {:d}\n'.format(int(self.augment_scale_anisotropic)))
text_file.write('augment_scale_min = {:.3f}\n'.format(self.augment_scale_min))
text_file.write('augment_scale_max = {:.3f}\n'.format(self.augment_scale_max))
text_file.write('augment_color = {:.3f}\n\n'.format(self.augment_color))
text_file.write('weights_decay = {:f}\n'.format(self.weights_decay))
text_file.write('gaussian_decay = {:f}\n'.format(self.gaussian_decay))
text_file.write('batch_averaged_loss = {:d}\n'.format(int(self.batch_averaged_loss)))
text_file.write('offsets_loss = {:s}\n'.format(self.offsets_loss))
text_file.write('offsets_decay = {:f}\n'.format(self.offsets_decay))
text_file.write('batch_num = {:d}\n'.format(self.batch_num))
text_file.write('max_epoch = {:d}\n'.format(self.max_epoch))
if self.epoch_steps is None:
text_file.write('epoch_steps = None\n')
else:
text_file.write('epoch_steps = {:d}\n'.format(self.epoch_steps))
text_file.write('validation_size = {:d}\n'.format(self.validation_size))
text_file.write('snapshot_gap = {:d}\n'.format(self.snapshot_gap))