docstr: Train a DNN using given preprocessing, weights, and data
  
  The purpose of the Trainer is handle a default training mechanism.
  As required input it expects a `dataset` and hyperparameters (`checkpoint_params`).
  
  The steps are
      1. Loading and preprocessing of the dataset
      2. Computation of the codec
      3. Construction of the DNN in the desired Deep Learning Framework
      4. Launch of the training
  
  During the training the Trainer will perform validation checks if a `validation_dataset` is given
  to determine the best model.
  Furthermore, the current status is printet and checkpoints are written.
docstr_tok: ["Train","a","DNN","using","given","preprocessing",",","weights",",","and","data","The","purpose","of","the","Trainer","is","handle","a","default","training","mechanism",".","As","required","input","it","expects","a","`","dataset","`","and","hyperparameters","(","`","checkpoint_params","`",")",".","The","steps","are","1",".","Loading","and","preprocessing","of","the","dataset","2",".","Computation","of","the","codec","3",".","Construction","of","the","DNN","in","the","desired","Deep","Learning","Framework","4",".","Launch","of","the","training","During","the","training","the","Trainer","will","perform","validation","checks","if","a","`","validation_dataset","`","is","given","to","determine","the","best","model",".","Furthermore",",","the","current","status","is","printet","and","checkpoints","are","written","."]
code: def __init__(self, params: TrainerParams, scenario, restore=False):
      """Train a DNN using given preprocessing, weights, and data
  
      The purpose of the Trainer is handle a default training mechanism.
      As required input it expects a `dataset` and hyperparameters (`checkpoint_params`).
  
      The steps are
          1. Loading and preprocessing of the dataset
          2. Computation of the codec
          3. Construction of the DNN in the desired Deep Learning Framework
          4. Launch of the training
  
      During the training the Trainer will perform validation checks if a `validation_dataset` is given
      to determine the best model.
      Furthermore, the current status is printet and checkpoints are written.
      """
      super(Trainer, self).__init__(params, scenario, restore)
      self._params: TrainerParams = params
      if (
          not isinstance(self._params.checkpoint_save_freq, str)
          and self._params.checkpoint_save_freq < 0
      ):
          self._params.checkpoint_save_freq = (
              self._params.early_stopping_params.frequency
          )
      self._params.warmstart.model = (
          checkpoint_path(self._params.warmstart.model)
          if self._params.warmstart.model
          else None
      )
      self.checkpoint = None
      if self._params.warmstart.model:
          # Manually handle loading
          self.checkpoint = SavedCalamariModel(
              self._params.warmstart.model,
              auto_update=self._params.auto_upgrade_checkpoints,
          )
          self._params.warmstart.model = self.checkpoint.ckpt_path
          self._params.warmstart.trim_graph_name = False
          network = self.checkpoint.trainer_params.network
          if self._params.network != network:
              self._params.network = network
              network_str = "def" if network is None else network
              logger.warning(
                  f"Changing the network structure is not supported. Keeping existing network ({network_str})."
              )
  
      self._codec_changes = None
      data_aug = self._params.scenario.data.pre_proc.processors_of_type(
          AugmentationProcessorParams
      )
      self._retrain_on_original = (
          self._params.data_aug_retrain_on_original
          and len(data_aug) > 0
          and any(p.n_augmentations != 0 for p in data_aug)
      )
  
imports: import logging
  import os
  from typing import Type
  from tfaip.data.pipeline.datapipeline import RawDataPipeline
  from tfaip.data.pipeline.definitions import PipelineMode
  from tfaip.trainer.callbacks.logger_callback import LoggerCallback
  from tfaip.trainer.callbacks.tensor_board_callback import TensorBoardCallback
  from tfaip.trainer.callbacks.train_params_logger import TrainerCheckpointsCallback
  from tfaip.trainer.trainer import Trainer
  from tfaip.trainer.warmstart.warmstarter import WarmStarter
  from calamari_ocr.ocr import Codec, SavedCalamariModel
  from calamari_ocr.ocr.dataset.data import Data
  from calamari_ocr.ocr.dataset.imageprocessors.augmentation import AugmentationProcessorParams
  from calamari_ocr.ocr.model.params import ModelParams
  from calamari_ocr.ocr.training.params import TrainerParams
  from calamari_ocr.ocr.training.pipeline_params import CalamariTrainOnlyPipelineParams
  from calamari_ocr.ocr.training.warmstart import WarmStarterWithCodecAdaption
  from calamari_ocr.utils import checkpoint_path
label_desc: Use image node_id 3 to create a new Trainer object from inherited base classes: AIPTrainer with example: obj = Trainer(params, scenario, restore)