Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: CLI work in progress (#130)
### Description Adding a CAREamics CLI ! Full functionality will include training, prediction and configuration building from the command line. Currently the prediction command is not implemented. - **What**: Added an entrypoint for the careamics command in the pyproject.toml file. Added functions to wrap existing CAREamics functionality that will be called with console commands. - **Why**: A CLI will be useful for benchmarking, running on the HPC, pipelines and convenience. - **How**: - For convenience and readability the CLI has been built using third party package Typer. Typer makes it easy to manage arguments, options, commands and subcommands. - The `train` command creates a `CAREamist` object from a given config file and then runs the `CAREamist.train` method on given training and optional validation files. - The `conf` subcommands (`care`, `n2n`, `n2v`) are wrappers for the existing configuration building convenience functions in *src/careamics/config/configuration_factory.py*. The conf subcommands have the additional functionality of saving the created configuration to a *.yaml* file. ### Changes Made **Added**: - *src/careamics/cli/main.py* - Creates the main `typer.Typer` object and a function to run it. - Contains `train` and `predict` commands. - *src/careamics/cli/conf.py* - Contains configuration builder `conf` sub `typer.Typer` object. - Contains subcommands `care`, `n2n` and `n2v`. - *src/careamics/cli/\_\_init\_\_.py* - *tests/cli/test_main.py* - *tests/cli/test_conf.py* - *tests/cli/\_\_init\_\_.py* **Modified**: - *pyproject.toml*: - added careamics cli entrypoint (under [project.scripts]) - added typer dependency. ### Additional Notes and Examples The --help flag can be run on all commands and subcommands. This is helpfully managed by Typer. ```console (careamics) [~]melisande.croft@lin-imganf-m-01$ careamics --help Usage: careamics [OPTIONS] COMMAND [ARGS]... Run CAREamics algorithms from the command line, including Noise2Void and its many variants and cousins ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy │ │ it or customize the installation. │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ │ conf Build and save CAREamics configuration files. │ │ predict Create and save predictions from CAREamics models. │ │ train Train CAREamics models. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ``` ```console (careamics) [~]melisande.croft@lin-imganf-m-01$ careamics train --help Usage: careamics train [OPTIONS] SOURCE Train CAREamics models. ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * source FILE Path to a configuration file or a trained model. │ │ [default: None] │ │ [required] │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ * --train-source -ts PATH Path to the │ │ training data. │ │ [default: None] │ │ [required] │ │ --train-target -tt PATH Path to train │ │ target data. │ │ [default: None] │ │ --val-source -vs PATH Path to │ │ validation data. │ │ [default: None] │ │ --val-target -vt PATH Path to │ │ validation target │ │ data. │ │ [default: None] │ │ --use-in-memory -m --not-in-memory -M Use in memory │ │ dataset if │ │ possible. │ │ [default: │ │ use-in-memory] │ │ --val-percentage FLOAT Percentage of │ │ files to use for │ │ validation. │ │ [default: 0.1] │ │ --val-minimum-sp… INTEGER Minimum number of │ │ files to use for │ │ validation, │ │ [default: 1] │ │ --work-dir -wd DIRECTORY Path to working │ │ directory in │ │ which to save │ │ checkpoints and │ │ logs │ │ [default: None] │ │ --help Show this message │ │ and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ``` As you can see from the help output above, I have decided on the design choice, for the `train` command, the the config file is an argument and everything else is passed as an option. So to train with a `<CONFIG FILE>` and `<TRAIN SOURCE>` the syntax would be: ```console careamics train <CONFIG FILE> -ts <TRAIN SOURCE> ``` --- - [x] Code builds and passes tests locally, including doctests - [x] New tests have been added (for bug fixes/features) - [x] Pre-commit passes - [ ] PR to the documentation exists (for bug fixes / features) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information