chesscog.core.training package

Core training functionality.

Submodules

chesscog.core.training.create_configs module

chesscog.core.training.create_configs.create_configs(classifier: str, include_centercrop: bool = False)

Create the YAML configuration files for all registered models for a classifier.

Parameters
  • classifier (str) – the classifier (either “occupancy_classifier” or “piece_classifier”)

  • include_centercrop (bool, optional) – whether to create two configs per model, one including center crop and one not. Defaults to False.

chesscog.core.training.optimizer module

chesscog.core.training.optimizer.build_optimizer_from_config(optimizer_cfg: recap.config.CfgNode, params: Iterable) torch.optim.optimizer.Optimizer

Build an optimizer for neural network training from a configuration.

Parameters
  • optimizer_cfg (CN) – the optimizer part of the configuration object

  • params (typing.Iterable) – the parameters to optimize

Raises

NotImplementedError – if the desired optimizer is not implemented

Returns

the built optimizer

Return type

torch.optim.Optimizer

chesscog.core.training.train module

Main implementation of model training.

chesscog.core.training.train.train(cfg: recap.config.CfgNode, run_dir: pathlib.Path) torch.nn.modules.module.Module

Traing a model.

Parameters
  • cfg (CN) – the configuration object describing the model, dataset, etc.

  • run_dir (Path) – where to write tensorboard files, the active YAML file, and the chosen weights

Returns

the trained model

Return type

nn.Module

chesscog.core.training.train.train_model(cfg: recap.config.CfgNode, run_dir: pathlib.Path, model: torch.nn.modules.module.Module, is_inception: bool = False, model_name: Optional[str] = None, eval_on_train: bool = False) torch.nn.modules.module.Module

Train a model that has already been loaded.

Parameters
  • cfg (CN) – the configuration object describing the model, dataset, etc.

  • run_dir (Path) – where to write tensorboard files, the active YAML file, and the chosen weights

  • model (torch.nn.Module) – the loaded model

  • is_inception (bool, optional) – whether the model is InceptionV3. Defaults to False.

  • model_name (str, optional) – the name of the model (by default the last component of the run directory). Defaults to None.

  • eval_on_train (bool, optional) – whether to evaluate on the training set. Defaults to False.

Returns

the trained model

Return type

nn.Module

chesscog.core.training.train_classifier module

chesscog.core.training.train_classifier.train_classifier(name: str)

Set up CLI interface for training a classifier.

Parameters

name (str) – the name of the classifier (“occupancy_classifier” or “piece_classifier”)