cascade.trainers#

class cascade.trainers.BasicTrainer(repo: Repo | str, *args: Any, **kwargs: Any)[source]#

The most common of concrete Trainers. Trains a model for a certain amount of epochs. Can start from checkpoint if model file exists.

__init__(repo: Repo | str, *args: Any, **kwargs: Any) None[source]#
Parameters:

repo (Union[Repo, str]) – Either repo or path to it

get_meta() List[Dict[Any, Any]][source]#
Returns:

meta – A list where first element is this object’s metadata. All other elements represent the other stages of pipeline if present.

Meta can be anything that is worth to document about the object and its properties.

Meta is a list (see Meta type alias) to allow the formation of pipelines.

Return type:

Meta

train(model: Model, train_data: Dataset[Any] | Iterable[Any] | None = None, test_data: Dataset[Any] | Iterable[Any] | None = None, train_kwargs: Dict[Any, Any] | None = None, test_kwargs: Dict[Any, Any] | None = None, epochs: int = 1, start_from: str | None = None, eval_strategy: int | None = None, save_strategy: int | None = None, save_meta_callback: bool = True) None[source]#

Trains, evaluates and saves given model. If specified, loads model from checkpoint.

Parameters:
  • model – Model a model to be trained or which to load from line specified in start_from

  • train_data – Iterable train data to be passed to model’s fit()

  • test_data – Iterable, optional test data to be passed to model’s evaluate()

  • train_kwargs – Dict, optional arguments for fit()

  • test_kwargs – Dict, optional arguments for evaluate() - the most common is the dict of metrics

  • epochs – int, optional how many times to repeat training on data

  • start_from – str, optional name or index of line from which to start starts from the latest model in line

  • eval_strategy – int, optional Evaluation will take place every eval_strategy epochs. If None - the strategy is no evaluation.

  • save_strategy – int, optional Saving will take place every save_strategy epochs. Meta will be saved anyway. If None - the strategy is ‘save only meta’.

  • save_meta_callback – bool, optional By default True - adds line.save(model, only_meta=True) as a callback when model.log() is called

class cascade.trainers.Trainer(repo: Repo | str, *args: Any, **kwargs: Any)[source]#

A class that encapsulates training, evaluation and saving of models.

__init__(repo: Repo | str, *args: Any, **kwargs: Any) None[source]#
Parameters:

repo (Union[Repo, str]) – Either repo or path to it

get_meta() List[Dict[Any, Any]][source]#
Returns:

meta – A list where first element is this object’s metadata. All other elements represent the other stages of pipeline if present.

Meta can be anything that is worth to document about the object and its properties.

Meta is a list (see Meta type alias) to allow the formation of pipelines.

Return type:

Meta

train(model: Model, *args: Any, **kwargs: Any) None[source]#