API Reference

class corgi.apps.Corgi

corgi - Classifier for ORganelle Genomes Inter alia

activation()

The activation for the last layer. If None, then fastai will use the default activiation of the loss if it exists.

assert_initialized()

Asserts that this app has been initialized.

All sub-classes of TorchApp need to call super().__init__() if overriding the __init__() function.

Raises:

TorchAppInitializationError – If the app has not been properly initialized.

cache_dir() Path

Returns a path to a directory where data files for this app can be cached.

callbacks(project_name: str = <torchapp.params.Param object>, run_name: str = <torchapp.params.Param object>, run_id: str = <torchapp.params.Param object>, notes: str = <torchapp.params.Param object>, tag: ~typing.List[str] = <torchapp.params.Param object>, wandb: bool = <torchapp.params.Param object>, wandb_mode: str = <torchapp.params.Param object>, wandb_dir: ~pathlib.Path = <torchapp.params.Param object>, wandb_entity: str = <torchapp.params.Param object>, wandb_group: str = <torchapp.params.Param object>, wandb_job_type: str = <torchapp.params.Param object>, mlflow: bool = <torchapp.params.Param object>, **kwargs) List

The list of callbacks to use with this app in the fastai training loop.

Parameters:

project_name (str) – The name for this project for logging purposes. If no name is given then the name of the app is used.

Returns:

The list of callbacks.

Return type:

list

cli(inference_only: bool = False)

Returns a ‘Click’ object which defines the command-line interface of the app.

classmethod click(inference_only: bool = False)

Creates an instance of this class and returns the click object for the command-line interface.

dataloaders(csv: ~pathlib.Path = <torchapp.params.Param object>, base_dir: ~pathlib.Path = <torchapp.params.Param object>, batch_size: int = <torchapp.params.Param object>, dataloader_type: ~corgi.dataloaders.DataloaderType = <torchapp.params.Param object>, validation_seq_length: int = 1000, deform_lambda: float = <torchapp.params.Param object>) DataLoaders

Creates a FastAI DataLoaders object which Corgi uses in training and prediction.

Parameters:
  • inputs (Path) – The input file.

  • batch_size (int) – The number of elements to use in a batch for training and prediction. Defaults to 32.

export(model_path: Path, **kwargs)

Generates a learner, saves model weights from a file and exports the learner so that it can be used for inference.

This is useful if a run has not reached completion but the model weights have still been saved.

goal() str

Sets the optimality direction when evaluating the metric from monitor.

By default it produces the same behaviour as fastai callbacks (fastai.callback.tracker) ie. it is set to “minimize” if the monitor metric has the string ‘loss’ or ‘err’ otherwise it is “maximize”.

If the monitor is empty then this function returns None.

classmethod inference_only_click()

Creates an instance of this class and returns the click object for the command-line interface.

classmethod inference_only_main()

Creates an instance of this class and runs the command-line interface for only the inference command.

learner(fp16: bool = <torchapp.params.Param object>, **kwargs) Learner

Creates a fastai learner object.

loss_func(**kwargs)

The loss function. If None, then fastai will use the default loss function if it exists for this model.

classmethod main(inference_only: bool = False)

Creates an instance of this class and runs the command-line interface.

metrics()

The list of metrics to use with this app.

By default this list is empty. This method should be subclassed to add metrics in child classes of TorchApp.

Returns:

The list of metrics.

Return type:

List

model(embedding_dim: int = <torchapp.params.Param object>, filters: int = <torchapp.params.Param object>, cnn_layers: int = <torchapp.params.Param object>, kernel_size_maxpool: int = <torchapp.params.Param object>, lstm_dims: int = <torchapp.params.Param object>, final_layer_dims: int = <torchapp.params.Param object>, dropout: float = <torchapp.params.Param object>, final_bias: bool = <torchapp.params.Param object>, cnn_only: bool = True, kernel_size: int = <torchapp.params.Param object>, cnn_dims_start: int = <torchapp.params.Param object>, factor: float = <torchapp.params.Param object>, penultimate_dims: int = <torchapp.params.Param object>, include_length: bool = False, transformer_heads: int = <torchapp.params.Param object>, transformer_layers: int = <torchapp.params.Param object>, macc: int = <torchapp.params.Param object>) Module

Creates a deep learning model for the Corgi to use.

Returns:

The created model.

Return type:

nn.Module

monitor()

The metric to optimize for when performing hyperparameter tuning.

By default it returns ‘valid_loss’.

pretrained_local_path(pretrained: str = <torchapp.params.Param object>, reload: bool = <torchapp.params.Param object>, **kwargs) Path

The local path of the pretrained model.

If it is a URL, then it is downloaded. If it is a relative path, then this method returns the absolute path to it.

Parameters:
  • pretrained (str, optional) – The location (URL or filepath) of a pretrained model. If it is a relative path, then it is relative to the current working directory. Defaults to using the result of the pretrained_location method.

  • reload (bool, optional) – Should the pretrained model be downloaded again if it is online and already present locally. Defaults to False.

Raises:

FileNotFoundError – If the file cannot be located in the local environment.

Returns:

The absolute path to the model on the local filesystem.

Return type:

Path

pretrained_location() str

The location of a pretrained model.

It can be a URL, in which case it will need to be downloaded. Or it can be part of the package bundle in which case, it needs to be a relative path from directory which contains the code which defines the app.

This function by default returns an empty string. Inherited classes need to override this method to use pretrained models.

Returns:

The location of the pretrained model.

Return type:

Union[str, Path]

project_name() str

The name to use for a project for logging purposes.

The default is to use the class name.

train(distributed: bool = <torchapp.params.Param object>, **kwargs) Learner

Trains a model for this app.

Parameters:

distributed (bool, optional) – If the learner is distributed. Defaults to Param(default=False, help=”If the learner is distributed.”).

Returns:

The fastai Learner object created for training.

Return type:

Learner

version(verbose: bool = False)

Prints the version of the package that defines this app.

Used in the command-line interface.

Parameters:

verbose (bool, optional) – Whether or not to print to stdout. Defaults to False.

Raises:

Exception – If it cannot find the package.