otx.cli.cli#
CLI entrypoints.
Classes
|
OTX CLI entrypoint. |
- class otx.cli.cli.OTXCLI(args: list[str] | None = None, run: bool = True)[source]#
Bases:
object
OTX CLI entrypoint.
Initialize OTX CLI.
- add_subcommands() None [source]#
Adds subcommands to the CLI parser.
This method initializes and configures subcommands for the OTX CLI parser. It iterates over the available subcommands, adds arguments specific to each subcommand, and registers them with the parser.
- Returns:
None
- static engine_subcommand_parser(subcommand: str, **kwargs) tuple[ArgumentParser, list] [source]#
Creates an ArgumentParser object for the engine subcommand.
- Parameters:
**kwargs – Additional keyword arguments to be passed to the ArgumentParser constructor.
- Returns:
The created ArgumentParser object.
- Return type:
ArgumentParser
- static engine_subcommands() dict[str, set[str]] [source]#
Returns dictionary the subcommands of engine, and whose value is the argument to be skipped in the CLI.
This allows the CLI to skip duplicate keys when creating the Engine and when running the subcommand.
- Returns:
A dictionary where the keys are the subcommands and the values are sets of skipped arguments.
- get_config_value(config: Namespace, key: str, default: Any | None = None) Any [source]#
Retrieves the value of a configuration key from the given config object.
- Parameters:
config (Namespace) – The config object containing the configuration values.
key (str) – The key of the configuration value to retrieve.
default (Any, optional) – The default value to return if the key is not found. Defaults to None.
- Returns:
- The value of the configuration key, or the default value if the key is not found.
if the value is a Namespace, it is converted to a dictionary.
- Return type:
Any
- get_subcommand_parser(subcommand: str | None) ArgumentParser [source]#
Returns the argument parser for the specified subcommand.
- Parameters:
subcommand (str | None) – The name of the subcommand. If None, returns the main parser.
- Returns:
The argument parser for the specified subcommand.
- Return type:
ArgumentParser
- init_parser() ArgumentParser [source]#
Initialize the argument parser for the OTX CLI.
- Returns:
The initialized argument parser.
- Return type:
ArgumentParser
- instantiate_classes(instantiate_engine: bool = True) None [source]#
Instantiate the necessary classes based on the subcommand.
This method checks if the subcommand is one of the engine subcommands. If it is, it instantiates the necessary classes such as config, datamodule, model, and engine.
- Parameters:
instantiate_engine (bool, optional) – Whether to instantiate the engine. Defaults to True.
- instantiate_engine() Engine [source]#
Instantiate an Engine object with the specified parameters.
- Returns:
An instance of the Engine class.
- instantiate_model(model_config: Namespace) OTXModel [source]#
Instantiate the model based on the subcommand.
This method checks if the subcommand is one of the engine subcommands. If it is, it instantiates the model.
- Parameters:
model_config (Namespace) – The model configuration.
- Returns:
The model and optimizer and scheduler.
- Return type:
- prepare_subcommand_kwargs(subcommand: str) dict[str, Any] [source]#
Prepares the keyword arguments to pass to the subcommand to run.
- run() None [source]#
Executes the specified subcommand.
- Raises:
ValueError – If the subcommand is not recognized.
- save_config(work_dir: Path) None [source]#
Save the configuration for the specified subcommand.
- Parameters:
work_dir (Path) – The working directory where the configuration file will be saved.
The configuration is saved as a YAML file in the engine’s working directory.