(args)
| 303 | |
| 304 | |
| 305 | def main(args): |
| 306 | |
| 307 | # Set random seed for some degree of reproducibility. See PyTorch docs on this topic for caveats. |
| 308 | # https://pytorch.org/docs/stable/notes/randomness.html#reproducibility |
| 309 | set_seed() |
| 310 | |
| 311 | if not torch.cuda.is_available(): |
| 312 | raise Exception( |
| 313 | "No CUDA device available. Training without one is not feasible." |
| 314 | ) |
| 315 | |
| 316 | git_sha = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8") |
| 317 | train_run_id = f"{git_sha}_hp{args.hp}_{time.strftime('%Y%m%d-%H%M')}" |
| 318 | |
| 319 | train_split, val_split, train_BS, test_BS, bins_values, stage_taxonomy = prepare_datasets(args) |
| 320 | |
| 321 | print(f"=> Run ID {train_run_id}") |
| 322 | print(f"=> Training on {len(train_split)} samples") |
| 323 | print(f"=> Validating on {len(val_split)} samples") |
| 324 | |
| 325 | base_hparams = dict( |
| 326 | # Preprocessing settings. This should be changed with the dataset called accordingly. |
| 327 | # Storing values here for readibility. |
| 328 | n_bins=args.n_bins, # Partion on the continuous time scale. |
| 329 | bins_values=bins_values, |
| 330 | input_feature_size=args.input_feature_size, |
| 331 | features_extraction=os.path.dirname(args.data_dir), |
| 332 | |
| 333 | # Settings that be changed in the loop: |
| 334 | # Training. |
| 335 | sampling_method="random", |
| 336 | max_epochs=100, |
| 337 | earlystop_warmup=0, |
| 338 | earlystop_patience=30, |
| 339 | earlystop_min_epochs=30, |
| 340 | |
| 341 | # Loss. |
| 342 | alpha_surv = 0.0, |
| 343 | |
| 344 | # Optimizer. |
| 345 | initial_lr=0.00003, |
| 346 | milestones="2, 5, 15, 25", |
| 347 | gamma_lr=0.1, |
| 348 | weight_decay=0.00001, |
| 349 | |
| 350 | # Model architecture parameters. See model class for details. |
| 351 | precompression_layer=True, |
| 352 | feature_size_comp=512, |
| 353 | feature_size_attn=256, |
| 354 | postcompression_layer=True, |
| 355 | feature_size_comp_post=128, |
| 356 | p_dropout_fc=0.25, |
| 357 | p_dropout_atn=0.25, |
| 358 | |
| 359 | # Model of molecular classification. In our case only inference is used. |
| 360 | n_classes_molecular=args.n_classes_molecular, |
| 361 | feature_size_comp_molecular=args.feature_size_comp_molecular, |
| 362 | feature_size_attn_molecular=args.feature_size_attn_molecular, |
no test coverage detected