Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding to remove info, but the ordering is not preserved. #58

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions terratorch/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,31 @@ 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]):
def clean_config_for_deployment_and_dump(config: dict[str, Any], clean:bool=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird spacing in the keyword arguments

deploy_config = deepcopy(config)
## General
# drop ckpt_path
deploy_config.pop("ckpt_path", None)
# drop checkpoints
deploy_config.pop("ModelCheckpoint", None)
deploy_config.pop("StateDictModelCheckpoint", None)
# drop optimizer and lr sheduler
deploy_config.pop("optimizer", None)
deploy_config.pop("lr_scheduler", None)
## Trainer
# remove logging
deploy_config["trainer"]["logger"] = False
# remove callbacks
deploy_config["trainer"].pop("callbacks", None)
# remove default_root_dir
deploy_config["trainer"].pop("default_root_dir", None)
# set mixed precision by default for inference
deploy_config["trainer"]["precision"] = "16-mixed"
## Model
# set pretrained to false
if "model_args" in deploy_config["model"]["init_args"]:
deploy_config["model"]["init_args"]["model_args"]["pretrained"] = False
if clean:
## General
# drop ckpt_path
deploy_config.pop("ckpt_path", None)
# drop checkpoints
deploy_config.pop("ModelCheckpoint", None)
deploy_config.pop("StateDictModelCheckpoint", None)
# drop optimizer and lr sheduler
deploy_config.pop("optimizer", None)
deploy_config.pop("lr_scheduler", None)
## Trainer
# remove logging
deploy_config["trainer"]["logger"] = False
# remove callbacks
deploy_config["trainer"].pop("callbacks", None)
# remove default_root_dir
deploy_config["trainer"].pop("default_root_dir", None)
# set mixed precision by default for inference
deploy_config["trainer"]["precision"] = "16-mixed"
## Model
# set pretrained to false
if "model_args" in deploy_config["model"]["init_args"]:
deploy_config["model"]["init_args"]["model_args"]["pretrained"] = False

return yaml.safe_dump(deploy_config)

Expand Down
Loading