Skip to content

Commit

Permalink
The input argument --clean_config allows to control if the outputtd c…
Browse files Browse the repository at this point in the history
…onfig files will be more or less verbose

Signed-off-by: João Lucas de Sousa Almeida <[email protected]>
  • Loading branch information
Joao-L-S-Almeida committed Jul 25, 2024
1 parent dce5152 commit cd319cb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions terratorch/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ def write_on_epoch_end(self, trainer, pl_module, predictions, batch_indices): #
save_prediction(prediction, file_name, output_dir, dtype=trainer.out_dtype)


def clean_config_for_deployment_and_dump(config: dict[str, Any], clean:bool=False):
def clean_config_for_deployment_and_dump(config: dict[str, Any]):
deploy_config = deepcopy(config)
if clean:

if config["clean_config"]:
## General
# drop ckpt_path
deploy_config.pop("ckpt_path", None)
Expand Down Expand Up @@ -176,7 +177,7 @@ def __init__(
):
super().__init__(parser, config, config_filename, overwrite, multifile, save_to_log_dir)
set_dumper("deploy_config", clean_config_for_deployment_and_dump)

def setup(self, trainer: Trainer, pl_module: LightningModule, stage: str) -> None:
if self.already_saved:
return
Expand Down Expand Up @@ -285,6 +286,7 @@ class MyLightningCLI(LightningCLI):
def add_arguments_to_parser(self, parser: LightningArgumentParser) -> None:
parser.add_argument("--predict_output_dir", default=None)
parser.add_argument("--out_dtype", default="int16")
parser.add_argument("--clean_config", type=bool, default=False)

# parser.set_defaults({"trainer.enable_checkpointing": False})

Expand Down Expand Up @@ -315,6 +317,9 @@ def instantiate_classes(self) -> None:
if hasattr(config, "out_dtype"):
self.trainer.out_dtype = config.out_dtype

if hasattr(config, "clean_config"):
self.trainer.clean_config = config.clean_config

def build_lightning_cli(
args: ArgsType = None,
run=True, # noqa: FBT002
Expand Down

0 comments on commit cd319cb

Please sign in to comment.