class_docstr: ```
  Tracks (and plots) the change in loss of a Keras model as learning rate is gradually increased.
  Used to visually identify a good learning rate, given model and data.
  Reference:
      Original Paper: https://arxiv.org/abs/1506.01186
  ```
class_docstr_tok: ["``","`","Tracks","(","and","plots",")","the","change","in","loss","of","a","Keras","model","as","learning","rate","is","gradually","increased",".","Used","to","visually","identify","a","good","learning","rate",",","given","model","and","data",".","Reference",":","Original","Paper",":","https",":","\/\/arxiv.org\/abs\/1506.01186","``","`"]
docstr: ```
  Track loss as learning rate is increased.
  NOTE: batch_size is ignored when train_data is instance of Iterator.
  ```
docstr_tok: ["``","`","Track","loss","as","learning","rate","is","increased",".","NOTE",":","batch_size","is","ignored","when","train_data","is","instance","of","Iterator",".","``","`"]
code: def find(
      self,
      train_data,
      steps_per_epoch,
      use_gen=False,
      class_weight=None,
      start_lr=1e-7,
      lr_mult=1.01,
      max_epochs=None,
      batch_size=U.DEFAULT_BS,
      workers=1,
      use_multiprocessing=False,
      verbose=1,
  ):
      """
      ```
      Track loss as learning rate is increased.
      NOTE: batch_size is ignored when train_data is instance of Iterator.
      ```
      """
  
      # check arguments and initialize
      if train_data is None:
          raise ValueError("train_data is required")
      # U.data_arg_check(train_data=train_data, train_required=True)
      self.lrs = []
      self.losses = []
  
      # compute steps_per_epoch
      # num_samples = U.nsamples_from_data(train_data)
      # if U.is_iter(train_data):
      # use_gen = True
      # steps_per_epoch = num_samples // train_data.batch_size
      # else:
      # use_gen = False
      # steps_per_epoch = np.ceil(num_samples/batch_size)
  
      # max_epochs and lr_mult are None, set max_epochs
      # using sample size of 1500 batches
      if max_epochs is None and lr_mult is None:
          max_epochs = int(np.ceil(1500.0 / steps_per_epoch))
  
      if max_epochs:
          epochs = max_epochs
          num_batches = epochs * steps_per_epoch
          end_lr = 10 if start_lr < 10 else start_lr * 10
          self.lr_mult = (end_lr / start_lr) ** (1 / num_batches)
      else:
          epochs = 1024
          self.lr_mult = lr_mult
  
      # Save weights into a file
      new_file, self._weightfile = tempfile.mkstemp()
      self.model.save_weights(self._weightfile)
  
      # Remember the original learning rate
      original_lr = K.get_value(self.model.optimizer.lr)
  
      # Set the initial learning rate
      K.set_value(self.model.optimizer.lr, start_lr)
  
      callback = keras.callbacks.LambdaCallback(
          on_batch_end=lambda batch, logs: self.on_batch_end(
              batch, logs
          )
      )
  
      if use_gen:
          # *_generator methods are deprecated from TF 2.1.0
          fit_fn = self.model.fit
          fit_fn(
              train_data,
              steps_per_epoch=steps_per_epoch,
              epochs=epochs,
              class_weight=class_weight,
              workers=workers,
              use_multiprocessing=use_multiprocessing,
              verbose=verbose,
              callbacks=[callback],
          )
      else:
          self.model.fit(
              train_data[0],
              train_data[1],
              batch_size=batch_size,
              epochs=epochs,
              class_weight=class_weight,
              verbose=verbose,
              callbacks=[callback],
          )
  
      # Restore the weights to the state before model fitting
      self.model.load_weights(self._weightfile)
      self._weightfile = None
  
      # Restore the original learning rate
      K.set_value(self.model.optimizer.lr, original_lr)
  
      # compute stats for numerical estimates of lr
      self._compute_stats()
  
      return
  
file_path: ktrain/ktrain/lroptimize/lrfinder.py
imports: from ..None import utils
  from ..imports import *
label_desc: Use image node_id 3 for calling the LRFinder obj's underlying member method code with example usage: obj.find(train_data, steps_per_epoch, use_gen, class_weight, start_lr, lr_mult, max_epochs, batch_size, workers, use_multiprocessing, verbose) without return types