class_docstr: Implementation of paper "Born Again Neural Networks"
  https://arxiv.org/abs/1805.04770
  
  :param student_model (torch.nn.Module): Student model
  :param train_loader (torch.utils.data.DataLoader): Dataloader for training
  :param val_loader (torch.utils.data.DataLoader): Dataloader for validation
  :param optimizer (torch.optim.*): Optimizer for training
  :param num_gen (int): Number of generations to train.
  :param loss_fn (torch.nn.Module): Loss Function used for first model in gen.
                                    later, KLDivLoss is used.
  :param temp (float): Temperature parameter for distillation
  :param distil_weight (float): Weight paramter for distillation loss
  :param device (str): Device for training; 'cpu' for cpu and 'cuda' for gpu
  :param log (bool): True if logging required
  :param logdir (str): Directory for storing logs
class_docstr_tok: ["Implementation","of","paper","``","Born","Again","Neural","Networks","''","https",":","\/\/arxiv.org\/abs\/1805.04770",":","param","student_model","(","torch.nn.Module",")",":","Student","model",":","param","train_loader","(","torch.utils.data.DataLoader",")",":","Dataloader","for","training",":","param","val_loader","(","torch.utils.data.DataLoader",")",":","Dataloader","for","validation",":","param","optimizer","(","torch.optim",".","*",")",":","Optimizer","for","training",":","param","num_gen","(","int",")",":","Number","of","generations","to","train",".",":","param","loss_fn","(","torch.nn.Module",")",":","Loss","Function","used","for","first","model","in","gen.","later",",","KLDivLoss","is","used",".",":","param","temp","(","float",")",":","Temperature","parameter","for","distillation",":","param","distil_weight","(","float",")",":","Weight","paramter","for","distillation","loss",":","param","device","(","str",")",":","Device","for","training",";","'cpu","'","for","cpu","and","'cuda","'","for","gpu",":","param","log","(","bool",")",":","True","if","logging","required",":","param","logdir","(","str",")",":","Directory","for","storing","logs"]
docstr: Function used for calculating the KD loss during distillation
  
  :param y_pred_student (Tensor): Predicted outputs from the student network
  :param y_pred_teacher (Tensor): Predicted outputs from the teacher network
  :param y_true (Tensor): True labels
docstr_tok: ["Function","used","for","calculating","the","KD","loss","during","distillation",":","param","y_pred_student","(","Tensor",")",":","Predicted","outputs","from","the","student","network",":","param","y_pred_teacher","(","Tensor",")",":","Predicted","outputs","from","the","teacher","network",":","param","y_true","(","Tensor",")",":","True","labels"]
code: def calculate_kd_loss(self, y_pred_student, y_pred_teacher, y_true):
      """
      Function used for calculating the KD loss during distillation
  
      :param y_pred_student (Tensor): Predicted outputs from the student network
      :param y_pred_teacher (Tensor): Predicted outputs from the teacher network
      :param y_true (Tensor): True labels
      """
      if self.gen == 0:
          return self.loss_fn(y_pred_student, y_true)
  
      s_i = F.log_softmax(y_pred_student / self.temp, dim=1)
      t_i = F.softmax(y_pred_teacher / self.temp, dim=1)
      KD_loss = nn.KLDivLoss()(s_i, t_i) * (
          self.distil_weight * self.temp * self.temp
      )
      KD_loss += F.cross_entropy(y_pred_student, y_true) * (
          1.0 - self.distil_weight
      )
  
      return KD_loss
  
file_path: KD_Lib/KD_Lib/KD/vision/BANN/BANN.py
imports: import glob
  import os
  from copy import deepcopy
  import torch
  import torch.nn
  import torch.nn.functional
  from KD_Lib.KD.common import BaseClass
label_desc: Use image node_id 4 for calling the BANN obj's underlying member method code with example usage: obj.calculate_kd_loss(y_pred_student, y_pred_teacher, y_true) and returns: KD_loss, self