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","``","`"]
code: def on_batch_end(self, batch, logs):
      # Log the learning rate
      lr = K.get_value(self.model.optimizer.lr)
      self.lrs.append(lr)
  
      # Log the loss
      loss = logs["loss"]
      self.batch_num += 1
      self.avg_loss = self.beta * self.avg_loss + (1 - self.beta) * loss
      smoothed_loss = self.avg_loss / (1 - self.beta**self.batch_num)
      self.losses.append(smoothed_loss)
  
      # Check whether the loss got too large or NaN
      # print("\n%s:%s\n" % (smoothed_loss, self.stop_factor * self.best_loss))
      if (
          self.batch_num > 1
          and smoothed_loss > self.stop_factor * self.best_loss
      ):
          self.model.stop_training = True
          return
  
      # record best loss
      if smoothed_loss < self.best_loss or self.batch_num == 1:
          self.best_loss = smoothed_loss
  
      # Increase the learning rate for the next batch
      lr *= self.lr_mult
      K.set_value(self.model.optimizer.lr, lr)
  
      # stop if LR grows too large
      if lr > 10.0:
          self.model.stop_training = True
          return
  
file_path: ktrain/ktrain/lroptimize/lrfinder.py
imports: from ..None import utils
  from ..imports import *
label_desc: Use image node_id 2 for calling the LRFinder obj's underlying member method code with example usage: obj.on_batch_end(batch, logs) without return types