Initial commit

This commit is contained in:
HuguesTHOMAS 2020-04-11 15:15:46 -04:00
parent 44a52bef7c
commit 46e2f7d3e6
4 changed files with 37 additions and 31 deletions

View file

@ -853,7 +853,7 @@ class SemanticKittiSampler(Sampler):
""" """
return self.N return self.N
def calib_max_in(self, config, dataloader, untouched_ratio=0.8, verbose=True): def calib_max_in(self, config, dataloader, untouched_ratio=0.8, verbose=True, force_redo=False):
""" """
Method performing batch and neighbors calibration. Method performing batch and neighbors calibration.
Batch calibration: Set "batch_limit" (the maximum number of points allowed in every batch) so that the Batch calibration: Set "batch_limit" (the maximum number of points allowed in every batch) so that the
@ -869,7 +869,7 @@ class SemanticKittiSampler(Sampler):
print('\nStarting Calibration of max_in_points value (use verbose=True for more details)') print('\nStarting Calibration of max_in_points value (use verbose=True for more details)')
t0 = time.time() t0 = time.time()
redo = False redo = force_redo
# Batch limit # Batch limit
# *********** # ***********
@ -890,7 +890,7 @@ class SemanticKittiSampler(Sampler):
key = '{:s}_{:.3f}_{:.3f}'.format(sampler_method, key = '{:s}_{:.3f}_{:.3f}'.format(sampler_method,
self.dataset.in_R, self.dataset.in_R,
self.dataset.config.first_subsampling_dl) self.dataset.config.first_subsampling_dl)
if key in max_in_lim_dict: if not redo and key in max_in_lim_dict:
self.dataset.max_in_p = max_in_lim_dict[key] self.dataset.max_in_p = max_in_lim_dict[key]
else: else:
redo = True redo = True
@ -956,6 +956,7 @@ class SemanticKittiSampler(Sampler):
a = 1 a = 1
# Save max_in_limit dictionary # Save max_in_limit dictionary
print('New max_in_p = ', self.dataset.max_in_p)
max_in_lim_dict[key] = self.dataset.max_in_p max_in_lim_dict[key] = self.dataset.max_in_p
with open(max_in_lim_file, 'wb') as file: with open(max_in_lim_file, 'wb') as file:
pickle.dump(max_in_lim_dict, file) pickle.dump(max_in_lim_dict, file)
@ -969,7 +970,7 @@ class SemanticKittiSampler(Sampler):
print('Calibration done in {:.1f}s\n'.format(time.time() - t0)) print('Calibration done in {:.1f}s\n'.format(time.time() - t0))
return return
def calibration(self, dataloader, untouched_ratio=0.9, verbose=False): def calibration(self, dataloader, untouched_ratio=0.9, verbose=False, force_redo=False):
""" """
Method performing batch and neighbors calibration. Method performing batch and neighbors calibration.
Batch calibration: Set "batch_limit" (the maximum number of points allowed in every batch) so that the Batch calibration: Set "batch_limit" (the maximum number of points allowed in every batch) so that the
@ -985,7 +986,7 @@ class SemanticKittiSampler(Sampler):
print('\nStarting Calibration (use verbose=True for more details)') print('\nStarting Calibration (use verbose=True for more details)')
t0 = time.time() t0 = time.time()
redo = False redo = force_redo
# Batch limit # Batch limit
# *********** # ***********
@ -1008,7 +1009,7 @@ class SemanticKittiSampler(Sampler):
self.dataset.config.first_subsampling_dl, self.dataset.config.first_subsampling_dl,
self.dataset.batch_num, self.dataset.batch_num,
self.dataset.max_in_p) self.dataset.max_in_p)
if key in batch_lim_dict: if not redo and key in batch_lim_dict:
self.dataset.batch_limit[0] = batch_lim_dict[key] self.dataset.batch_limit[0] = batch_lim_dict[key]
else: else:
redo = True redo = True
@ -1049,7 +1050,7 @@ class SemanticKittiSampler(Sampler):
if key in neighb_lim_dict: if key in neighb_lim_dict:
neighb_limits += [neighb_lim_dict[key]] neighb_limits += [neighb_lim_dict[key]]
if len(neighb_limits) == self.dataset.config.num_layers: if not redo and len(neighb_limits) == self.dataset.config.num_layers:
self.dataset.neighborhood_limits = neighb_limits self.dataset.neighborhood_limits = neighb_limits
else: else:
redo = True redo = True
@ -1114,6 +1115,8 @@ class SemanticKittiSampler(Sampler):
# Perform calibration # Perform calibration
##################### #####################
self.dataset.batch_limit = self.dataset.max_in_p * (self.dataset.batch_num - 1)
for epoch in range(10): for epoch in range(10):
for batch_i, batch in enumerate(dataloader): for batch_i, batch in enumerate(dataloader):

View file

@ -95,10 +95,10 @@ if __name__ == '__main__':
# > 'last_XXX': Automatically retrieve the last trained model on dataset XXX # > 'last_XXX': Automatically retrieve the last trained model on dataset XXX
# > '(old_)results/Log_YYYY-MM-DD_HH-MM-SS': Directly provide the path of a trained model # > '(old_)results/Log_YYYY-MM-DD_HH-MM-SS': Directly provide the path of a trained model
chosen_log = 'results/Log_2020-04-07_18-22-18' # => ModelNet40 chosen_log = 'results/Log_2020-04-05_19-19-20' # => ModelNet40
# You can also choose the index of the snapshot to load (last by default) # You can also choose the index of the snapshot to load (last by default)
chkp_idx = None chkp_idx = -1
# Choose to test on validation or test split # Choose to test on validation or test split
on_val = True on_val = True
@ -111,7 +111,7 @@ if __name__ == '__main__':
############################ ############################
# Set which gpu is going to be used # Set which gpu is going to be used
GPU_ID = '3' GPU_ID = '1'
# Set GPU visible device # Set GPU visible device
os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID
@ -146,7 +146,7 @@ if __name__ == '__main__':
#config.batch_num = 3 #config.batch_num = 3
#config.in_radius = 4 #config.in_radius = 4
config.validation_size = 200 config.validation_size = 200
config.input_threads = 0 config.input_threads = 10
############## ##############
# Prepare Data # Prepare Data

View file

@ -103,8 +103,8 @@ class SemanticKittiConfig(Config):
in_radius = 10.0 in_radius = 10.0
val_radius = 51.0 val_radius = 51.0
n_frames = 1 n_frames = 1
max_in_points = 10000 max_in_points = 100000
max_val_points = 50000 max_val_points = 100000
# Number of batch # Number of batch
batch_num = 10 batch_num = 10
@ -153,7 +153,7 @@ class SemanticKittiConfig(Config):
##################### #####################
# Maximal number of epochs # Maximal number of epochs
max_epoch = 500 max_epoch = 800
# Learning rate management # Learning rate management
learning_rate = 1e-2 learning_rate = 1e-2
@ -165,7 +165,7 @@ class SemanticKittiConfig(Config):
epoch_steps = 500 epoch_steps = 500
# Number of validation examples per epoch # Number of validation examples per epoch
validation_size = 50 validation_size = 200
# Number of epoch between each checkpoint # Number of epoch between each checkpoint
checkpoint_gap = 50 checkpoint_gap = 50
@ -185,18 +185,13 @@ class SemanticKittiConfig(Config):
# #
# #
# Inverse of proportion * 20 # sqrt(Inverse of proportion * 100)
# class_w = [0.409, 40.000, 18.182, 3.571, 5.556, 28.571, 33.333, 22.222, 0.104, # class_w = [1.430, 14.142, 9.535, 4.226, 5.270, 11.952, 12.910, 10.541, 0.719,
# 1.130, 0.157, 2.985, 0.151, 0.292, 0.070, 2.857, 0.255, 6.061, 25.000] # 2.377, 0.886, 3.863, 0.869, 1.209, 0.594, 3.780, 1.129, 5.505, 11.180]
# Inverse of proportion *20 capped (0.1 < X < 10) # sqrt(Inverse of proportion * 100) capped (0.5 < X < 5)
# class_w = [0.409, 10.000, 10.000, 3.571, 5.556, 10.000, 10.000, 10.000, 0.104, class_w = [1.430, 5.000, 5.000, 4.226, 5.000, 5.000, 5.000, 5.000, 0.719, 2.377,
# 1.130, 0.157, 2.985, 0.151, 0.292, 0.100, 2.857, 0.255, 6.061, 10.000] 0.886, 3.863, 0.869, 1.209, 0.594, 3.780, 1.129, 5.000, 5.000]
# Inverse of proportion *20 then sqrt
class_w = [0.639529479, 6.32455532, 4.264014327, 1.889822365, 2.357022604, 5.345224838,
5.773502692, 4.714045208, 0.321744726, 1.062988007, 0.396214426, 1.727736851,
0.388807896, 0.54073807, 0.265465937, 1.690308509, 0.504754465, 2.46182982, 5]
# Do we nee to save convergence # Do we nee to save convergence
@ -217,7 +212,7 @@ if __name__ == '__main__':
############################ ############################
# Set which gpu is going to be used # Set which gpu is going to be used
GPU_ID = '2' GPU_ID = '3'
# Set GPU visible device # Set GPU visible device
os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID
@ -291,8 +286,8 @@ if __name__ == '__main__':
pin_memory=True) pin_memory=True)
# Calibrate max_in_point value # Calibrate max_in_point value
training_sampler.calib_max_in(config, training_loader, verbose=False) training_sampler.calib_max_in(config, training_loader, verbose=True)
test_sampler.calib_max_in(config, test_loader, verbose=False) test_sampler.calib_max_in(config, test_loader, verbose=True)
# Calibrate samplers # Calibrate samplers
training_sampler.calibration(training_loader, verbose=True) training_sampler.calibration(training_loader, verbose=True)

View file

@ -91,7 +91,8 @@ class ModelTester:
############ ############
# Choose test smoothing parameter (0 for no smothing, 0.99 for big smoothing) # Choose test smoothing parameter (0 for no smothing, 0.99 for big smoothing)
test_smooth = 0.98 test_smooth = 0.95
test_radius_ratio = 0.7
softmax = torch.nn.Softmax(1) softmax = torch.nn.Softmax(1)
# Number of classes including ignored labels # Number of classes including ignored labels
@ -162,6 +163,7 @@ class ModelTester:
# Get probs and labels # Get probs and labels
stacked_probs = softmax(outputs).cpu().detach().numpy() stacked_probs = softmax(outputs).cpu().detach().numpy()
s_points = batch.points[0].cpu().numpy()
lengths = batch.lengths[0].cpu().numpy() lengths = batch.lengths[0].cpu().numpy()
in_inds = batch.input_inds.cpu().numpy() in_inds = batch.input_inds.cpu().numpy()
cloud_inds = batch.cloud_inds.cpu().numpy() cloud_inds = batch.cloud_inds.cpu().numpy()
@ -174,10 +176,16 @@ class ModelTester:
for b_i, length in enumerate(lengths): for b_i, length in enumerate(lengths):
# Get prediction # Get prediction
points = s_points[i0:i0 + length]
probs = stacked_probs[i0:i0 + length] probs = stacked_probs[i0:i0 + length]
inds = in_inds[i0:i0 + length] inds = in_inds[i0:i0 + length]
c_i = cloud_inds[b_i] c_i = cloud_inds[b_i]
if test_radius_ratio < 0.99:
mask = np.sum(points ** 2, axis=1) < (test_radius_ratio * config.in_radius) ** 2
inds = inds[mask]
probs = probs[mask]
# Update current probs in whole cloud # Update current probs in whole cloud
self.test_probs[c_i][inds] = test_smooth * self.test_probs[c_i][inds] + (1 - test_smooth) * probs self.test_probs[c_i][inds] = test_smooth * self.test_probs[c_i][inds] + (1 - test_smooth) * probs
i0 += length i0 += length
@ -373,7 +381,7 @@ class ModelTester:
############ ############
# Choose validation smoothing parameter (0 for no smothing, 0.99 for big smoothing) # Choose validation smoothing parameter (0 for no smothing, 0.99 for big smoothing)
test_smooth = 0 test_smooth = 0.5
last_min = -0.5 last_min = -0.5
softmax = torch.nn.Softmax(1) softmax = torch.nn.Softmax(1)