diff --git a/datasets/SemanticKitti.py b/datasets/SemanticKitti.py index 59d921e..94c677f 100644 --- a/datasets/SemanticKitti.py +++ b/datasets/SemanticKitti.py @@ -853,7 +853,7 @@ class SemanticKittiSampler(Sampler): """ 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. 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)') t0 = time.time() - redo = False + redo = force_redo # Batch limit # *********** @@ -890,7 +890,7 @@ class SemanticKittiSampler(Sampler): key = '{:s}_{:.3f}_{:.3f}'.format(sampler_method, self.dataset.in_R, 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] else: redo = True @@ -956,6 +956,7 @@ class SemanticKittiSampler(Sampler): a = 1 # 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 with open(max_in_lim_file, 'wb') as 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)) 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. 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)') t0 = time.time() - redo = False + redo = force_redo # Batch limit # *********** @@ -1008,7 +1009,7 @@ class SemanticKittiSampler(Sampler): self.dataset.config.first_subsampling_dl, self.dataset.batch_num, 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] else: redo = True @@ -1049,7 +1050,7 @@ class SemanticKittiSampler(Sampler): if key in neighb_lim_dict: 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 else: redo = True @@ -1114,6 +1115,8 @@ class SemanticKittiSampler(Sampler): # Perform calibration ##################### + self.dataset.batch_limit = self.dataset.max_in_p * (self.dataset.batch_num - 1) + for epoch in range(10): for batch_i, batch in enumerate(dataloader): diff --git a/test_models.py b/test_models.py index c89236f..7906c6f 100644 --- a/test_models.py +++ b/test_models.py @@ -95,10 +95,10 @@ if __name__ == '__main__': # > '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 - 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) - chkp_idx = None + chkp_idx = -1 # Choose to test on validation or test split on_val = True @@ -111,7 +111,7 @@ if __name__ == '__main__': ############################ # Set which gpu is going to be used - GPU_ID = '3' + GPU_ID = '1' # Set GPU visible device os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID @@ -146,7 +146,7 @@ if __name__ == '__main__': #config.batch_num = 3 #config.in_radius = 4 config.validation_size = 200 - config.input_threads = 0 + config.input_threads = 10 ############## # Prepare Data diff --git a/train_SemanticKitti.py b/train_SemanticKitti.py index 5d15dd9..61f5414 100644 --- a/train_SemanticKitti.py +++ b/train_SemanticKitti.py @@ -103,8 +103,8 @@ class SemanticKittiConfig(Config): in_radius = 10.0 val_radius = 51.0 n_frames = 1 - max_in_points = 10000 - max_val_points = 50000 + max_in_points = 100000 + max_val_points = 100000 # Number of batch batch_num = 10 @@ -153,7 +153,7 @@ class SemanticKittiConfig(Config): ##################### # Maximal number of epochs - max_epoch = 500 + max_epoch = 800 # Learning rate management learning_rate = 1e-2 @@ -165,7 +165,7 @@ class SemanticKittiConfig(Config): epoch_steps = 500 # Number of validation examples per epoch - validation_size = 50 + validation_size = 200 # Number of epoch between each checkpoint checkpoint_gap = 50 @@ -185,18 +185,13 @@ class SemanticKittiConfig(Config): # # - # Inverse of proportion * 20 - # class_w = [0.409, 40.000, 18.182, 3.571, 5.556, 28.571, 33.333, 22.222, 0.104, - # 1.130, 0.157, 2.985, 0.151, 0.292, 0.070, 2.857, 0.255, 6.061, 25.000] + # sqrt(Inverse of proportion * 100) + # class_w = [1.430, 14.142, 9.535, 4.226, 5.270, 11.952, 12.910, 10.541, 0.719, + # 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) - # class_w = [0.409, 10.000, 10.000, 3.571, 5.556, 10.000, 10.000, 10.000, 0.104, - # 1.130, 0.157, 2.985, 0.151, 0.292, 0.100, 2.857, 0.255, 6.061, 10.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] + # sqrt(Inverse of proportion * 100) capped (0.5 < X < 5) + class_w = [1.430, 5.000, 5.000, 4.226, 5.000, 5.000, 5.000, 5.000, 0.719, 2.377, + 0.886, 3.863, 0.869, 1.209, 0.594, 3.780, 1.129, 5.000, 5.000] # Do we nee to save convergence @@ -217,7 +212,7 @@ if __name__ == '__main__': ############################ # Set which gpu is going to be used - GPU_ID = '2' + GPU_ID = '3' # Set GPU visible device os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID @@ -291,8 +286,8 @@ if __name__ == '__main__': pin_memory=True) # Calibrate max_in_point value - training_sampler.calib_max_in(config, training_loader, verbose=False) - test_sampler.calib_max_in(config, test_loader, verbose=False) + training_sampler.calib_max_in(config, training_loader, verbose=True) + test_sampler.calib_max_in(config, test_loader, verbose=True) # Calibrate samplers training_sampler.calibration(training_loader, verbose=True) diff --git a/utils/tester.py b/utils/tester.py index a5eb2b9..ca13d2e 100644 --- a/utils/tester.py +++ b/utils/tester.py @@ -91,7 +91,8 @@ class ModelTester: ############ # 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) # Number of classes including ignored labels @@ -162,6 +163,7 @@ class ModelTester: # Get probs and labels stacked_probs = softmax(outputs).cpu().detach().numpy() + s_points = batch.points[0].cpu().numpy() lengths = batch.lengths[0].cpu().numpy() in_inds = batch.input_inds.cpu().numpy() cloud_inds = batch.cloud_inds.cpu().numpy() @@ -174,10 +176,16 @@ class ModelTester: for b_i, length in enumerate(lengths): # Get prediction + points = s_points[i0:i0 + length] probs = stacked_probs[i0:i0 + length] inds = in_inds[i0:i0 + length] 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 self.test_probs[c_i][inds] = test_smooth * self.test_probs[c_i][inds] + (1 - test_smooth) * probs i0 += length @@ -373,7 +381,7 @@ class ModelTester: ############ # Choose validation smoothing parameter (0 for no smothing, 0.99 for big smoothing) - test_smooth = 0 + test_smooth = 0.5 last_min = -0.5 softmax = torch.nn.Softmax(1)