class_docstr: The Trainer class inherits tf.keras.Model and contains everything a
  model needs for training. It exposes trainer.cyclic_fit method which trains
  the model using Cyclic Learning rate discovered by Leslie Smith.
  
  Arguments:
  ds: Dataset object
  model: object of type tf.keras.Model
  num_classes (int, None): number of classes in the dataset. If None then will auto infer from Dataset
class_docstr_tok: ["The","Trainer","class","inherits","tf.keras.Model","and","contains","everything","a","model","needs","for","training",".","It","exposes","trainer.cyclic_fit","method","which","trains","the","model","using","Cyclic","Learning","rate","discovered","by","Leslie","Smith",".","Arguments",":","ds",":","Dataset","object","model",":","object","of","type","tf.keras.Model","num_classes","(","int",",","None",")",":","number","of","classes","in","the","dataset",".","If","None","then","will","auto","infer","from","Dataset"]
docstr: Trains model on ds as train data with cyclic learning rate. Dataset
  will be automatically converted into `tf.data` format and images will
  be prewhitened in range of [-1, 1]. Cyclical Learning Rates for
  Training Neural Networks: https://arxiv.org/abs/1506.01186.
  
  Args:
      epochs (int): number of epochs for training
      batch_size (int): batch size
      lr_range (tuple): learning rate will cycle from lr_min to lr_max
      optimizer (callable): Keras callable optimizer
      momentum(float): momentum for the optimizer
      validation_data: Data on which to evaluate
      callbacks: List of `tf.keras.callbacks` instances.
  kwargs:
      step_size (int): step size for the Cyclic learning rate.
      By default it is `2 * (self.ds.num_files//batch_size)`
      scale_mode (str): cycle or exp
      shuffle(bool): Dataset will be shuffle on each epoch if True
code: def cyclic_fit(
      self,
      epochs: int,
      batch_size: int,
      lr_range: Union[tuple, list] = (1e-4, 1e-2),
      optimizer: tf.keras.optimizers.Optimizer = tf.keras.optimizers.SGD,
      momentum: float = 0.9,
      validation_data: Any = None,
      callbacks: Optional[List] = None,
      *args,
      **kwargs,
  ):
      """Trains model on ds as train data with cyclic learning rate. Dataset
      will be automatically converted into `tf.data` format and images will
      be prewhitened in range of [-1, 1]. Cyclical Learning Rates for
      Training Neural Networks: https://arxiv.org/abs/1506.01186.
  
      Args:
          epochs (int): number of epochs for training
          batch_size (int): batch size
          lr_range (tuple): learning rate will cycle from lr_min to lr_max
          optimizer (callable): Keras callable optimizer
          momentum(float): momentum for the optimizer
          validation_data: Data on which to evaluate
          callbacks: List of `tf.keras.callbacks` instances.
      kwargs:
          step_size (int): step size for the Cyclic learning rate.
          By default it is `2 * (self.ds.num_files//batch_size)`
          scale_mode (str): cycle or exp
          shuffle(bool): Dataset will be shuffle on each epoch if True
      """
      self.step_size = 2 * (self.ds.num_files // batch_size)
      self.ds.step_size = self.step_size
      if not self.cyclic_opt_set:
          self.max_lr, self.min_lr = lr_range
          lr_schedule = tfa.optimizers.Triangular2CyclicalLearningRate(
              initial_learning_rate=lr_range[0],
              maximal_learning_rate=lr_range[1],
              step_size=kwargs.get("step_size", self.step_size),
              scale_mode=kwargs.get("scale_mode", "cycle"),
          )
  
          optimizer = self._get_optimizer(optimizer, momentum=momentum)
          optimizer = optimizer(learning_rate=lr_schedule)
          self.model.optimizer = optimizer
          self.cyclic_opt_set = True
      else:
          print("cyclic learning rate already set!")
  
      return self.model.fit(
          self._prepare_dl(batch_size, kwargs.get("shuffle", True)),
          steps_per_epoch=self.step_size,
          validation_data=validation_data,
          epochs=epochs,
          callbacks=callbacks,
      )
  
imports: import inspect
  from functools import partial
  from typing import Any, List, Optional, Union
  import matplotlib.cm
  import matplotlib.pyplot
  import numpy
  import tensorflow
  import tensorflow_addons
  from PIL import Image
  from tensorflow import keras
  from tensorflow.keras.models import Model
  from tf_keras_vis.gradcam import Gradcam, GradcamPlusPlus
  from tf_keras_vis.utils import normalize
  from typeguard import check_argument_types, typechecked
  from chitra.import_utils import is_installed
  from .datagenerator import Dataset
label_desc: Use image node_id 12 for calling the Trainer obj's underlying member method code with example usage: obj.cyclic_fit(epochs, batch_size, lr_range, optimizer, momentum, validation_data, callbacks) and returns: self