power_cogs.base package — power_cogs 0.1.0 documentation

# power_cogs.base package

## Submodules

## power_cogs.base.base_torch_dataset module

class `power_cogs.base.base_torch_dataset.` `BaseTorchDataset`

  Bases: `torch.utils.data.dataset.Dataset`

  `sample`(batch_size: int) → Dict[str, Any]

    Random sample from dataset

    Args:
      batch_size (int): batch size to sample
    Returns:
      typing.Dict[str, typing.Any]: dict of outputs, ex: {“data”: subset, “targets”:targets}
  `to_device`(device: torch.device) → None

## power_cogs.base.base_torch_model module

class `power_cogs.base.base_torch_model.` `BaseTorchModel`

  Bases: `torch.nn.modules.module.Module`

  `summary`(input_shape)

## power_cogs.base.base_torch_trainer module

class `power_cogs.base.base_torch_trainer.` `BaseTorchTrainer`(name: Optional[str] = None, pretrained_path: Optional[str] = None, visualize_output: bool = False, use_cuda: bool = False, device_id: int = 0, early_stoppage: bool = False, loss_threshold: float = -inf, batch_size: int = 32, epochs: int = 100, checkpoint_interval: int = 100, num_samples: Optional[int] = None, model_config: Dict[str, Any] = {}, dataset_config: Dict[str, Any] = {}, optimizer_config: Dict[str, Any] = {}, scheduler_config: Dict[str, Any] = {}, logging_config: Dict[str, Any] = {}, dataloader_config: Dict[str, Any] = {}, tune_config: Dict[str, Any] = {}, config: Dict[str, Any] = {})

  Bases: `object`

  classmethod `from_config`(config_path: Optional[str] = None, config: Dict[str, Any] = {}) → power_cogs.base.base_torch_trainer.BaseTorchTrainer
  `load`(pretrained_path)
  `load_model`(checkpoint_path: str, load_optimizer_and_scheduler: bool = True)
  `log_epoch`(train_metrics, epoch)
  `make_checkpoint`(path: str)
  `post_dataset_setup`()
  `post_model_setup`()
  `post_optimizer_setup`()
  `post_setup`()
  `post_train`()
  `post_train_iter`(train_output: Dict[Any, Any])
  `pre_dataset_setup`()
  `pre_model_setup`()
  `pre_optimizer_setup`()
  `pre_train`()
  `pre_train_iter`()
  `save`(base_path: Optional[str] = None, step: Optional[int] = None, path_name: Optional[str] = None) → str
  `save_config`(path) → str
  `setup`()
  `setup_dataloader`()
  `setup_dataset`()
  `setup_device`()
  `setup_logging_and_checkpoints`()
  `setup_model`()
  `setup_optimizer`()
  `setup_trainer`()
  `to_device`(device)
  `train`(batch_size=None, epochs=None, checkpoint_interval=None, visualize=None) → Dict[str, Any]

    Main training function, should call train_iter

  `train_iter`(batch_size: int, iteration: Optional[int] = None) → Dict[Any, Any]

    Training iteration, specify learning process here

  `tune`(tune_config: Dict[str, Any] = {}, trainer_overrides: Dict[str, Any] = {})
  `visualize`(*args, **kwargs)

    Visualize output

## Module contents

class `power_cogs.base.` `BaseTorchDataset`

  Bases: `torch.utils.data.dataset.Dataset`

  `sample`(batch_size: int) → Dict[str, Any]

    Random sample from dataset

    Args:
      batch_size (int): batch size to sample
    Returns:
      typing.Dict[str, typing.Any]: dict of outputs, ex: {“data”: subset, “targets”:targets}
  `to_device`(device: torch.device) → None

class `power_cogs.base.` `BaseTorchModel`

  Bases: `torch.nn.modules.module.Module`

  `summary`(input_shape)

class `power_cogs.base.` `BaseTorchTrainer`(name: Optional[str] = None, pretrained_path: Optional[str] = None, visualize_output: bool = False, use_cuda: bool = False, device_id: int = 0, early_stoppage: bool = False, loss_threshold: float = -inf, batch_size: int = 32, epochs: int = 100, checkpoint_interval: int = 100, num_samples: Optional[int] = None, model_config: Dict[str, Any] = {}, dataset_config: Dict[str, Any] = {}, optimizer_config: Dict[str, Any] = {}, scheduler_config: Dict[str, Any] = {}, logging_config: Dict[str, Any] = {}, dataloader_config: Dict[str, Any] = {}, tune_config: Dict[str, Any] = {}, config: Dict[str, Any] = {})

  Bases: `object`

  classmethod `from_config`(config_path: Optional[str] = None, config: Dict[str, Any] = {}) → power_cogs.base.base_torch_trainer.BaseTorchTrainer
  `load`(pretrained_path)
  `load_model`(checkpoint_path: str, load_optimizer_and_scheduler: bool = True)
  `log_epoch`(train_metrics, epoch)
  `make_checkpoint`(path: str)
  `post_dataset_setup`()
  `post_model_setup`()
  `post_optimizer_setup`()
  `post_setup`()
  `post_train`()
  `post_train_iter`(train_output: Dict[Any, Any])
  `pre_dataset_setup`()
  `pre_model_setup`()
  `pre_optimizer_setup`()
  `pre_train`()
  `pre_train_iter`()
  `save`(base_path: Optional[str] = None, step: Optional[int] = None, path_name: Optional[str] = None) → str
  `save_config`(path) → str
  `setup`()
  `setup_dataloader`()
  `setup_dataset`()
  `setup_device`()
  `setup_logging_and_checkpoints`()
  `setup_model`()
  `setup_optimizer`()
  `setup_trainer`()
  `to_device`(device)
  `train`(batch_size=None, epochs=None, checkpoint_interval=None, visualize=None) → Dict[str, Any]

    Main training function, should call train_iter

  `train_iter`(batch_size: int, iteration: Optional[int] = None) → Dict[Any, Any]

    Training iteration, specify learning process here

  `tune`(tune_config: Dict[str, Any] = {}, trainer_overrides: Dict[str, Any] = {})
  `visualize`(*args, **kwargs)

    Visualize output