def main(config): """ Main code for training a classification/seg/classification+seg model. Args: config (dict): dictionary read from a yaml file i.e. script/configs/train.yml Returns: None """ # setting up the train/val split with filenames seed = config["io_params"]["split_seed"] seed_everything(seed) exp = TrainSegExperiment2D(config) output_key = "logits" print(f"Seed: {seed}") runner = SupervisedRunner(output_key=output_key) runner.train(model=exp.model, criterion=exp.criterion, optimizer=exp.opt, scheduler=exp.lr_scheduler, loaders=exp.loaders, callbacks=exp.cb_list, **config["runner_params"]) # Not saving plots if plot_params not specified in config if config.get("plot_params"): figs = plot_metrics(logdir=config["runner_params"]["logdir"], metrics=config["plot_params"]["metrics"]) save_figs(figs, save_dir=config["plot_params"]["save_dir"])
def main(config): """ Main code for training a classification model. Args: config (dict): dictionary read from a yaml file i.e. experiments/finetune_classification.yml Returns: None """ # setting up the train/val split with filenames seed = config["io_params"]["split_seed"] seed_everything(seed) dim = len(config["predict_3D_params"]["patch_size"]) mode = config["mode"].lower() assert mode in ["classification", "segmentation"], \ "The `mode` must be one of ['classification', 'segmentation']." if mode == "classification": raise NotImplementedError elif mode == "segmentation": if dim == 2: exp = SegmentationInferenceExperiment2D(config) elif dim == 3: exp = SegmentationInferenceExperiment(config) print(f"Seed: {seed}\nMode: {mode}") pred = Predictor(out_dir=config["out_dir"], checkpoint_path=config["checkpoint_path"], model=exp.model, test_loader=exp.loaders["test"], pred_3D_params=config["predict_3D_params"], pseudo_3D=config.get("pseudo_3D")) pred.run_3D_predictions()
def main(config): """ Main code for training a classification model. Args: config (dict): dictionary read from a yaml file i.e. experiments/finetune_classification.yml Returns: None """ # setting up the train/val split with filenames seed = config["io_params"]["split_seed"] seed_everything(seed) mode = config["mode"].lower() assert mode in ["classification", "segmentation", "both"], \ "The `mode` must be one of ['classification', 'segmentation', 'both']." if mode == "classification": raise NotImplementedError elif mode == "segmentation": if config["dim"] == 2: exp = TrainSegExperiment2D(config) elif config["dim"] == 3: exp = TrainSegExperiment(config) output_key = "logits" elif mode == "both": if config["dim"] == 2: exp = TrainClfSegExperiment2D(config) elif config["dim"] == 3: exp = TrainClfSegExperiment3D(config) output_key = ["seg_logits", "clf_logits"] print(f"Seed: {seed}\nMode: {mode}") runner = SupervisedRunner(output_key=output_key) runner.train(model=exp.model, criterion=exp.criterion, optimizer=exp.opt, scheduler=exp.lr_scheduler, loaders=exp.loaders, callbacks=exp.cb_list, **config["runner_params"]) # Not saving plots if plot_params not specified in config if not config.get("plot_params"): figs = plot_metrics(logdir=config["runner_params"]["logdir"], metrics=config["plot_params"]["metrics"]) save_figs(figs, save_dir=config["plot_params"]["save_dir"])
def main(config, out_path): """ Main code for training a classification model. Args: config (dict): dictionary read from a yaml file i.e. experiments/finetune_classification.yml Returns: None """ # setting up the train/val split with filenames seed = config["io_params"]["split_seed"] seed_everything(seed) exp = SegmentationInferenceExperiment2D(config) print(f"Seed: {seed}") test_ids = exp.test_dset.im_ids if not os.path.isdir(out_path): os.mkdir(out_path) print(f"Created {out_path}") print(f"Copying {len(test_ids)} test files to a {out_path}") copy_files(test_ids, out_path)
def main(config): """ Main code for training a classification model. Args: config (dict): dictionary read from a yaml file i.e. experiments/finetune_classification.yml Returns: None """ # setting up the train/val split with filenames seed = config["io_params"]["split_seed"] seed_everything(seed) exp = SegmentationInferenceExperiment2D(config) print(f"Seed: {seed}") pred = General3DPredictor(out_dir=config["out_dir"], model=exp.model, test_loader=exp.loaders["test"], pred_3D_params=config["predict_3D_params"], pseudo_3D=config.get("pseudo_3D")) pred.run_3D_predictions()