class_docstr: The :class:`~poutyne.ModelBundle` class provides a straightforward experimentation tool for efficient and entirely
  customizable finetuning of the whole neural network training procedure with PyTorch. The
  :class:`~poutyne.ModelBundle` object takes care of the training and testing processes while also managing to keep
  traces of all pertinent information via the automatic logging option.
  
  Use ``ModelBundle.from_*`` methods to instanciate a :class:`~poutyne.ModelBundle`.
class_docstr_tok: ["The",":","class",":","`","~poutyne.ModelBundle","`","class","provides","a","straightforward","experimentation","tool","for","efficient","and","entirely","customizable","finetuning","of","the","whole","neural","network","training","procedure","with","PyTorch",".","The",":","class",":","`","~poutyne.ModelBundle","`","object","takes","care","of","the","training","and","testing","processes","while","also","managing","to","keep","traces","of","all","pertinent","information","via","the","automatic","logging","option",".","Use","``","ModelBundle.from_","*","``","methods","to","instanciate","a",":","class",":","`","~poutyne.ModelBundle","`","."]
docstr: Trains or finetunes the model on a dataset using a generator. If a previous training already occurred
  and lasted a total of `n_previous` epochs, then the model's weights will be set to the last checkpoint and the
  training will be resumed for epochs range (`n_previous`, `epochs`].
  
  If the ModelBundle has logging enabled (i.e. self.logging is True), numerous callbacks will be automatically
  included. Notably, two :class:`~poutyne.ModelCheckpoint` objects will take care of saving the last and every
  new best (according to monitor mode) model weights in appropriate checkpoint files.
  :class:`~poutyne.OptimizerCheckpoint` and :class:`~poutyne.LRSchedulerCheckpoint` will also respectively
  handle the saving of the optimizer and LR scheduler's respective states for future retrieval. Moreover, a
  :class:`~poutyne.AtomicCSVLogger` will save all available epoch statistics in an output .tsv file. Lastly, a
  :class:`~poutyne.TensorBoardLogger` handles automatic TensorBoard logging of various neural network
  statistics.
  
  Args:
      train_generator: Generator-like object for the training set. See :func:`~Model.fit_generator()`
          for details on the types of generators supported.
      valid_generator (optional): Generator-like object for the validation set. See
          :func:`~Model.fit_generator()` for details on the types of generators supported.
          (Default value = None)
      callbacks (List[~poutyne.Callback]): List of callbacks that will be called during
          training. These callbacks are added after those used in this method (see above). This allows to assume
          that they are called after those.
          (Default value = None)
      lr_schedulers: List of learning rate schedulers. (Default value = None)
      keep_only_last_best (bool): Whether only the last saved best checkpoint is kept. Applies only when
           `save_every_epoch` is false.
           (Default value = False)
      save_every_epoch (bool, optional): Whether or not to save the model bundle's model's weights after
          every epoch.
          (Default value = False)
      disable_tensorboard (bool, optional): Whether or not to disable the automatic tensorboard logging
          callbacks.
          (Default value = False)
      seed (int, optional): Seed used to make the sampling deterministic.
          (Default value = 42)
      kwargs: Any keyword arguments to pass to :func:`~Model.fit_generator()`.
  
  Returns:
      List of dict containing the history of each epoch.
docstr_tok: ["Trains","or","finetunes","the","model","on","a","dataset","using","a","generator",".","If","a","previous","training","already","occurred","and","lasted","a","total","of","`","n_previous","`","epochs",",","then","the","model","'s","weights","will","be","set","to","the","last","checkpoint","and","the","training","will","be","resumed","for","epochs","range","(","`","n_previous","`",",","`","epochs","`","]",".","If","the","ModelBundle","has","logging","enabled","(","i.e",".","self.logging","is","True",")",",","numerous","callbacks","will","be","automatically","included",".","Notably",",","two",":","class",":","`","~poutyne.ModelCheckpoint","`","objects","will","take","care","of","saving","the","last","and","every","new","best","(","according","to","monitor","mode",")","model","weights","in","appropriate","checkpoint","files",".",":","class",":","`","~poutyne.OptimizerCheckpoint","`","and",":","class",":","`","~poutyne.LRSchedulerCheckpoint","`","will","also","respectively","handle","the","saving","of","the","optimizer","and","LR","scheduler","'s","respective","states","for","future","retrieval",".","Moreover",",","a",":","class",":","`","~poutyne.AtomicCSVLogger","`","will","save","all","available","epoch","statistics","in","an","output",".tsv","file",".","Lastly",",","a",":","class",":","`","~poutyne.TensorBoardLogger","`","handles","automatic","TensorBoard","logging","of","various","neural","network","statistics",".","Args",":","train_generator",":","Generator-like","object","for","the","training","set",".","See",":","func",":","`","~Model.fit_generator","(",")","`","for","details","on","the","types","of","generators","supported",".","valid_generator","(","optional",")",":","Generator-like","object","for","the","validation","set",".","See",":","func",":","`","~Model.fit_generator","(",")","`","for","details","on","the","types","of","generators","supported",".","(","Default","value","=","None",")","callbacks","(","List","[","~poutyne.Callback","]",")",":","List","of","callbacks","that","will","be","called","during","training",".","These","callbacks","are","added","after","those","used","in","this","method","(","see","above",")",".","This","allows","to","assume","that","they","are","called","after","those",".","(","Default","value","=","None",")","lr_schedulers",":","List","of","learning","rate","schedulers",".","(","Default","value","=","None",")","keep_only_last_best","(","bool",")",":","Whether","only","the","last","saved","best","checkpoint","is","kept",".","Applies","only","when","`","save_every_epoch","`","is","false",".","(","Default","value","=","False",")","save_every_epoch","(","bool",",","optional",")",":","Whether","or","not","to","save","the","model","bundle","'s","model","'s","weights","after","every","epoch",".","(","Default","value","=","False",")","disable_tensorboard","(","bool",",","optional",")",":","Whether","or","not","to","disable","the","automatic","tensorboard","logging","callbacks",".","(","Default","value","=","False",")","seed","(","int",",","optional",")",":","Seed","used","to","make","the","sampling","deterministic",".","(","Default","value","=","42",")","kwargs",":","Any","keyword","arguments","to","pass","to",":","func",":","`","~Model.fit_generator","(",")","`",".","Returns",":","List","of","dict","containing","the","history","of","each","epoch","."]
code: def train(
      self, train_generator, valid_generator=None, **kwargs
  ) -> List[Dict]:
      """
      Trains or finetunes the model on a dataset using a generator. If a previous training already occurred
      and lasted a total of `n_previous` epochs, then the model's weights will be set to the last checkpoint and the
      training will be resumed for epochs range (`n_previous`, `epochs`].
  
      If the ModelBundle has logging enabled (i.e. self.logging is True), numerous callbacks will be automatically
      included. Notably, two :class:`~poutyne.ModelCheckpoint` objects will take care of saving the last and every
      new best (according to monitor mode) model weights in appropriate checkpoint files.
      :class:`~poutyne.OptimizerCheckpoint` and :class:`~poutyne.LRSchedulerCheckpoint` will also respectively
      handle the saving of the optimizer and LR scheduler's respective states for future retrieval. Moreover, a
      :class:`~poutyne.AtomicCSVLogger` will save all available epoch statistics in an output .tsv file. Lastly, a
      :class:`~poutyne.TensorBoardLogger` handles automatic TensorBoard logging of various neural network
      statistics.
  
      Args:
          train_generator: Generator-like object for the training set. See :func:`~Model.fit_generator()`
              for details on the types of generators supported.
          valid_generator (optional): Generator-like object for the validation set. See
              :func:`~Model.fit_generator()` for details on the types of generators supported.
              (Default value = None)
          callbacks (List[~poutyne.Callback]): List of callbacks that will be called during
              training. These callbacks are added after those used in this method (see above). This allows to assume
              that they are called after those.
              (Default value = None)
          lr_schedulers: List of learning rate schedulers. (Default value = None)
          keep_only_last_best (bool): Whether only the last saved best checkpoint is kept. Applies only when
               `save_every_epoch` is false.
               (Default value = False)
          save_every_epoch (bool, optional): Whether or not to save the model bundle's model's weights after
              every epoch.
              (Default value = False)
          disable_tensorboard (bool, optional): Whether or not to disable the automatic tensorboard logging
              callbacks.
              (Default value = False)
          seed (int, optional): Seed used to make the sampling deterministic.
              (Default value = 42)
          kwargs: Any keyword arguments to pass to :func:`~Model.fit_generator()`.
  
      Returns:
          List of dict containing the history of each epoch.
      """
      return self._train(
          self.model.fit_generator,
          train_generator,
          valid_generator,
          **kwargs,
      )
  
imports: import os
  import warnings
  from typing import Any, Callable, Dict, List, Tuple, Union
  import torch
  from poutyne.framework.callbacks import AtomicCSVLogger, BestModelRestore, LRSchedulerCheckpoint, ModelCheckpoint, OptimizerCheckpoint, PeriodicSaveLambda, RandomStatesCheckpoint, TensorBoardLogger
  from poutyne.framework.model import Model
  from poutyne.plotting import plot_history
  from poutyne.utils import load_random_states, set_seeds
label_desc: Use image node_id 19 for calling the ModelBundle obj's underlying member method code with example usage: obj.train(train_generator, valid_generator) and returns: self