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: Compile2 compiles the model of Trainer for cyclic learning rate.
  Cyclical Learning Rates for Training Neural Networks:
  https://arxiv.org/abs/1506.01186.
  
  Args:
      batch_size (int): batch size
      lr_range (tuple): learning rate will cycle from lr_min to lr_max
      optimizer (str, keras.optimizer.Optimizer): Keras optimizer
  
  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
      momentum(int): momentum for the optimizer when optimizer is of type str
code: def compile2(
      self,
      batch_size: int,
      optimizer: Union[None, str, tf.keras.optimizers.Optimizer] = None,
      lr_range: Union[tuple, list] = (1e-4, 1e-2),
      loss: Optional[tf.keras.losses.Loss] = None,
      metrics=None,
      **kwargs,
  ):
      """Compile2 compiles the model of Trainer for cyclic learning rate.
      Cyclical Learning Rates for Training Neural Networks:
      https://arxiv.org/abs/1506.01186.
  
      Args:
          batch_size (int): batch size
          lr_range (tuple): learning rate will cycle from lr_min to lr_max
          optimizer (str, keras.optimizer.Optimizer): Keras optimizer
  
      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
          momentum(int): momentum for the optimizer when optimizer is of type str
      """
      if not optimizer:
          optimizer = "adam"
      self.max_lr, self.min_lr = lr_range
      self.batch_size = batch_size
  
      self.step_size = 2 * (self.ds.num_files // batch_size)
  
      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"),
      )
  
      if isinstance(optimizer, str):
          optimizer = OPT_DICT[optimizer]
          optimizer = optimizer(learning_rate=lr_schedule)
          if kwargs.get("momentum"):
              optimizer.momentum = kwargs.get("momentum")
  
      else:
          optimizer.learning_rate = lr_schedule
  
      self.compile(optimizer=optimizer, loss=loss, metrics=metrics)
      self.cyclic_opt_set = True
      print("Model compiled!")
  
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 13 for calling the Trainer obj's underlying member method code with example usage: obj.compile2(batch_size, optimizer, lr_range, loss, metrics) without return types