|
| 1 | +import configargparse |
| 2 | +import numpy as np |
| 3 | +import os |
| 4 | + |
| 5 | + |
| 6 | +def config_parser(): |
| 7 | + parser = configargparse.ArgumentParser() |
| 8 | + |
| 9 | + # Experiment Setup |
| 10 | + parser.add_argument('--config', is_config_file=True, default='configs/syn.txt', |
| 11 | + help='config file path') |
| 12 | + parser.add_argument("--exp_name", type=str, default=None, |
| 13 | + help='Experiment name, used as folder name for the experiment. If left blank, a \ |
| 14 | + name will be auto generated based on the configuration settings.') |
| 15 | + parser.add_argument("--log_dir", type=str, default=None, |
| 16 | + help='start time') |
| 17 | + parser.add_argument("--data_dir", type=str, |
| 18 | + help='input data directory') |
| 19 | + parser.add_argument("--raw_data_dir", type=str, |
| 20 | + help='raw data directory') |
| 21 | + parser.add_argument("--input_data_glob", type=str, |
| 22 | + help='glob expression to find raw input files') |
| 23 | + parser.add_argument("--split_file", type=str, |
| 24 | + help='Path to read and write the data split file. Needs to end with ".npz"') |
| 25 | + |
| 26 | + # Training Data Parameters |
| 27 | + parser.add_argument("--sample_std_dev", action='append', type=float, |
| 28 | + help='Standard deviations of gaussian samples. \ |
| 29 | + Used for displacing surface points to sample the distance field.') |
| 30 | + parser.add_argument("--sample_ratio", action='append', type=float, |
| 31 | + help='Ratio of standard deviations for samples used for training. \ |
| 32 | + Needs to have the same len as sample_std with floats between 0-1 \ |
| 33 | + and summing to 1.') |
| 34 | + parser.add_argument("--bb_min", default=-0.5, type=float, |
| 35 | + help='Training and testing shapes are normalized to be in a common bounding box.\ |
| 36 | + This value defines the min value in x,y and z for the bounding box.') |
| 37 | + parser.add_argument("--bb_max", default=0.5, type=float, |
| 38 | + help='Training and testing shapes are normalized to be in a common bounding box.\ |
| 39 | + This value defines the max value in x,y and z for the bounding box.') |
| 40 | + parser.add_argument("--input_res", type=int, default=256, |
| 41 | + help='Training and testing shapes are normalized to be in a common bounding box.\ |
| 42 | + This value defines the max value in x,y and z for the bounding box.') |
| 43 | + parser.add_argument("--num_points", type=int, default=10000, |
| 44 | + help='Number of points sampled from each ground truth shape.') |
| 45 | + |
| 46 | + # Preprocessing - Multiprocessing |
| 47 | + parser.add_argument("--num_chunks", type=int, default=1, |
| 48 | + help='The preprocessing can be distributed over num_chunks multiple machines.\ |
| 49 | + For this the raw files are split into num_chunks chunks. \ |
| 50 | + Default is preprocessing on a single machine.') |
| 51 | + parser.add_argument("--current_chunk", type=int, default=0, |
| 52 | + help='Tells the script which chunk it should process. \ |
| 53 | + Value between 0 till num_chunks-1.') |
| 54 | + parser.add_argument("--num_cpus", type=int, default=-1, |
| 55 | + help='Number of cpu cores to use for running the script. \ |
| 56 | + Default is -1, that is, using all available cpus.') |
| 57 | + parser.add_argument("--res", type=int, default=128) |
| 58 | + |
| 59 | + # Creating a data test/train/validation split |
| 60 | + parser.add_argument('--class_folders', type=str, default=None, |
| 61 | + help='If set to None, the split is created by creating a random sample from all input files. ' |
| 62 | + 'If not None, the split is created per class of objects. Objects of the same class need to ' |
| 63 | + 'be in a common parent folder for this. Variable class_folder is interpreted as glob ' |
| 64 | + 'pattern, suffix of data_dir - i.e. data_dir + class_folder, e.g. class_folder="/*/".') |
| 65 | + |
| 66 | + parser_nval = parser.add_mutually_exclusive_group() |
| 67 | + parser_nval.add_argument('--n_val', type=int, |
| 68 | + help='Size of validation set.') |
| 69 | + parser_nval.add_argument('--r_val', type=float, default=0.1, |
| 70 | + help='Relative size of validation set.') |
| 71 | + |
| 72 | + parser_ntest = parser.add_mutually_exclusive_group() |
| 73 | + parser_ntest.add_argument('--n_test', type=int, |
| 74 | + help='Size of test set.') |
| 75 | + parser_ntest.add_argument('--r_test', type=float, default=0.2, |
| 76 | + help='Relative size of test set.') |
| 77 | + |
| 78 | + # Generation |
| 79 | + parser.add_argument("--num_sample_points_generation", type=int, default=50000, |
| 80 | + help='Number of point samples per object provided to the RangeUDF network during generation.\ |
| 81 | + Influences generation speed (larger batches result in faster generation) but also GPU \ |
| 82 | + memory usage (higher values need more memory). Tip: choose largest possible value on GPU.') |
| 83 | + |
| 84 | + # Network |
| 85 | + parser.add_argument("--label_mode", type=str, default='full', |
| 86 | + help='loss join type') |
| 87 | + parser.add_argument("--joint_mode", type=str, default='naive') |
| 88 | + parser.add_argument("--in_dim", type=int, default=3, |
| 89 | + help='Number of layers') |
| 90 | + parser.add_argument("--concat", type=int, default=3, |
| 91 | + help='Number of layers') |
| 92 | + parser.add_argument("--rotate", type=int, default=1) |
| 93 | + parser.add_argument("--num_layers", type=int, default=4, |
| 94 | + help='Number of layers') |
| 95 | + parser.add_argument("--sub_sampling_ratio", nargs='+', type=int) |
| 96 | + parser.add_argument("--d_out", nargs='+', type=int,help="encoder dims") |
| 97 | + parser.add_argument("--num_neighbors", type=int, default=8, |
| 98 | + help='Number of neighbors for encoder') |
| 99 | + parser.add_argument("--num_interp", type=int, default=8, |
| 100 | + help='Number of neighbors for interpolation') |
| 101 | + parser.add_argument("--dropout", action='store_true') |
| 102 | + parser.add_argument("--fixed_input", action='store_true') |
| 103 | + parser.add_argument("--fixed_random_seed", action='store_true') |
| 104 | + parser.add_argument("--fixed_cudnn", action='store_true') |
| 105 | + |
| 106 | + parser.add_argument("--rec_loss", type=int, default=1) |
| 107 | + parser.add_argument("--sem_loss", type=str, default='ori') |
| 108 | + parser.add_argument("--reg_term", type=str, default='on') |
| 109 | + parser.add_argument("--reg_coef", type=float, default=0) |
| 110 | + parser.add_argument("--sem_term", type=str, default='off') |
| 111 | + parser.add_argument("--sem_coef", type=float, default=0) |
| 112 | + parser.add_argument("--hidden_dim", type=int,default=512) |
| 113 | + parser.add_argument("--rec_hidden_dims", nargs='+',type=int) |
| 114 | + parser.add_argument("--sem_hidden_dims", nargs='+',type=int) |
| 115 | + parser.add_argument("--rec_hidden_layers", type=int,default=1) |
| 116 | + parser.add_argument("--sem_hidden_layers", type=int,default=1) |
| 117 | + parser.add_argument("--task", type=str,default='rec') #rec,sem,joint |
| 118 | + parser.add_argument("--distance", action='store_false')#attention pooling with or without distance |
| 119 | + |
| 120 | + # Training |
| 121 | + parser.add_argument("--ckpt", type=str, default=None, help='which split to train on?') |
| 122 | + parser.add_argument("--num_sample_points_training", type=int, default=50000, |
| 123 | + help='Number of point samples per object provided to the RangeUDF network during training.\ |
| 124 | + Influences training speed (larger batches result in shorter epochs) but also GPU \ |
| 125 | + memory usage (higher values need more memory). Needs to be balanced with batch_size.') |
| 126 | + |
| 127 | + parser.add_argument("--batch_size", type=int, default=4, |
| 128 | + help='Number of objects provided to the RangeUDF network in one batch during training.\ |
| 129 | + Influences training speed (larger batches result in shorter epochs) but also GPU \ |
| 130 | + memory usage (higher values need more memory). Needs to be balanced with \ |
| 131 | + num_sample_points_training') |
| 132 | + parser.add_argument("--num_epochs", type=int, default=1000, |
| 133 | + help='Stopping citron for duration of training. Model converges much earlier: model convergence\ |
| 134 | + can be checked via tensorboard and is logged within the experiment folder.') |
| 135 | + parser.add_argument("--lr", type=float, default=1e-3, |
| 136 | + help='Learning rate used during training.') |
| 137 | + parser.add_argument("--gamma", type=float, default=1, |
| 138 | + help='Learning rate used during training.') |
| 139 | + parser.add_argument("--optimizer", type=str, default='Adam', |
| 140 | + help='Optimizer used during training.') |
| 141 | + parser.add_argument("--max_dist", type=float, default=0.1, |
| 142 | + help='max_distance for calculate rec loss') |
| 143 | + |
| 144 | + return parser |
| 145 | + |
| 146 | + |
| 147 | +def get_config(): |
| 148 | + parser = config_parser() |
| 149 | + cfg = parser.parse_args() |
| 150 | + args = vars(cfg) |
| 151 | + print('------------ Options -------------') |
| 152 | + for k, v in sorted(args.items()): |
| 153 | + print('%s: %s' % (str(k), str(v))) |
| 154 | + print('-------------- End ---------------') |
| 155 | + |
| 156 | + |
| 157 | + cfg.sample_ratio = np.array(cfg.sample_ratio) |
| 158 | + cfg.sample_std_dev = np.array(cfg.sample_std_dev) |
| 159 | + |
| 160 | + assert np.sum(cfg.sample_ratio) == 1 |
| 161 | + assert np.any(cfg.sample_ratio < 0) == False |
| 162 | + assert len(cfg.sample_ratio) == len(cfg.sample_std_dev) |
| 163 | + |
| 164 | + if cfg.exp_name is None: |
| 165 | + cfg.exp_name = 'data-{}dist-{}sigmas-{}res-{}'.format( |
| 166 | + os.path.basename(cfg.data_dir), |
| 167 | + ''.join(str(e) + '_' for e in cfg.sample_ratio), |
| 168 | + ''.join(str(e) + '_' for e in cfg.sample_std_dev), |
| 169 | + cfg.input_res) |
| 170 | + |
| 171 | + return cfg |
0 commit comments