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

add --log-file par to cli commands #19

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions GANDLF/entrypoints/anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from GANDLF.anonymize import run_anonymizer
from GANDLF.cli import copyrightMessage
from GANDLF.entrypoints import append_copyright_to_help
from GANDLF.utils.gandlf_logging import logger_setup
from GANDLF.utils import logger_setup


def _anonymize_images(
Expand Down Expand Up @@ -63,9 +63,17 @@ def _anonymize_images(
type=click.Path(),
help="Output directory or file which will contain the image(s) after anonymization.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(input_dir, config, modality, output_file):
def new_way(input_dir, config, modality, output_file, log_file):
"""Anonymize images/scans in the data directory."""
if log_file is not None:
logger_setup(log_file)
_anonymize_images(input_dir, output_file, config, modality)


Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ def _generate_config(config: str, strategy: str, output: str):
type=click.Path(file_okay=False, dir_okay=True),
help="Path to output directory.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(config, strategy, output):
def new_way(config, strategy, output, log_file):
"""Generate multiple GaNDLF configurations based on a single baseline GaNDLF for experimentation."""
if log_file is not None:
logger_setup(log_file)
_generate_config(config, strategy, output)


Expand Down
9 changes: 9 additions & 0 deletions GANDLF/entrypoints/construct_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,24 @@ def _construct_csv(
help="If True, paths in the output data CSV will always be relative to the location"
" of the output data CSV itself.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
input_dir: str,
channels_id: str,
label_id: Optional[str],
output_file: str,
relativize_paths: bool,
log_file: str,
):
"""Generate training/inference CSV from data directory."""
if log_file is not None:
logger_setup(log_file)
_construct_csv(
input_dir=input_dir,
channels_id=channels_id,
Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ def _debug_info():


@click.command()
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way():
def new_way(log_file):
"""Displays detailed info about system environment: library versions, settings, etc."""
if log_file is not None:
logger_setup(log_file)
_debug_info()


Expand Down
9 changes: 9 additions & 0 deletions GANDLF/entrypoints/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def _deploy(
help="An optional custom python entrypoint script to use instead of the default specified in mlcube.yaml."
" (Only for inference and metrics)",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
model: Optional[str],
Expand All @@ -136,8 +142,11 @@ def new_way(
output_dir: str,
requires_gpu: bool,
entrypoint: Optional[str],
log_file: str,
):
"""Generate frozen/deployable versions of trained GaNDLF models."""
if log_file is not None:
logger_setup(log_file)
_deploy(
model=model,
config=config,
Expand Down
9 changes: 9 additions & 0 deletions GANDLF/entrypoints/generate_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,24 @@ def _generate_metrics(
help="The value to use for missing predictions as penalty; if `-1`, this does not get added. This is only used in the case where the targets and predictions are passed independently.",
)
@click.option("--raw-input", hidden=True)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
config: str,
input_data: str,
output_file: Optional[str],
missing_prediction: int,
raw_input: str,
log_file: str,
):
"""Metrics calculator."""
if log_file is not None:
logger_setup(log_file)
_generate_metrics(
input_data=input_data,
config=config,
Expand Down
13 changes: 12 additions & 1 deletion GANDLF/entrypoints/optimize_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,22 @@ def _optimize_model(
required=False,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
model: str, config: Optional[str] = None, output_path: Optional[str] = None
model: str,
log_file: str,
config: Optional[str] = None,
output_path: Optional[str] = None,
):
"""Generate optimized versions of trained GaNDLF models."""
if log_file is not None:
logger_setup(log_file)
_optimize_model(model=model, config=config, output_path=output_path)


Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/patch_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ def _mine_patches(input_path: str, output_dir: str, config: Optional[str]):
help="config (in YAML) for running the patch miner. Needs 'scale' and 'patch_size' to be defined, "
"otherwise defaults to 16 and (256, 256), respectively.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(input_csv: str, output_dir: str, config: Optional[str]):
def new_way(input_csv: str, output_dir: str, config: Optional[str], log_file):
"""Construct patches from whole slide image(s)."""
if log_file is not None:
logger_setup(log_file)
_mine_patches(input_path=input_csv, output_dir=output_dir, config=config)


Expand Down
9 changes: 9 additions & 0 deletions GANDLF/entrypoints/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def _preprocess(
is_flag=True,
help="If passed, applies zero cropping during output creation.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
config: str,
Expand All @@ -89,8 +95,11 @@ def new_way(
label_pad: str,
apply_augs: bool,
crop_zero: bool,
log_file: str,
):
"""Generate training/inference data which are preprocessed to reduce resource footprint during computation."""
if log_file is not None:
logger_setup(log_file)
_preprocess(
config=config,
input_data=input_data,
Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/recover_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ def _recover_config(model_dir: Optional[str], mlcube: bool, output_file: str):
type=click.Path(file_okay=True, dir_okay=False),
help="Path to an output file where the config will be written.",
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(model_dir, mlcube, output_file):
def new_way(model_dir, mlcube, output_file, log_file):
"""Recovers a config file from a GaNDLF model. If used from within a deployed GaNDLF MLCube,
attempts to extract the config from the embedded model."""
if log_file is not None:
logger_setup(log_file)
_recover_config(model_dir=model_dir, mlcube=mlcube, output_file=output_file)


Expand Down
9 changes: 9 additions & 0 deletions GANDLF/entrypoints/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ def _run(
help="Location to save the output of the inference session. Not used for training.",
)
@click.option("--raw-input", hidden=True)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(
config: str,
Expand All @@ -157,8 +163,11 @@ def new_way(
resume: bool,
output_path: str,
raw_input: str,
log_file: str,
):
"""Semantic segmentation, regression, and classification for medical images using Deep Learning."""
if log_file is not None:
logger_setup(log_file)
_run(
config=config,
input_data=input_data,
Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/split_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ def _split_csv(input_csv: str, output_dir: str, config_path: Optional[str]):
help="The GaNDLF config (in YAML) with the `nested_training` key specified to the folds needed.",
type=click.Path(exists=True, file_okay=True, dir_okay=False),
)
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way(input_csv: str, output_dir: str, config: Optional[str]):
def new_way(input_csv: str, output_dir: str, config: Optional[str], log_file: str):
"""Split the data into training, validation, and testing sets and save them as csvs in the output directory."""
if log_file is not None:
logger_setup(log_file)
_split_csv(input_csv, output_dir, config)


Expand Down
10 changes: 9 additions & 1 deletion GANDLF/entrypoints/verify_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ def _verify_install():


@click.command()
@click.option(
"--log-file",
type=click.Path(),
default=None,
help="Output file which will contain the logs.",
)
@append_copyright_to_help
def new_way():
def new_way(log_file):
"""Verify GaNDLF installation."""
if log_file is not None:
logger_setup(log_file)
_verify_install()


Expand Down
Loading