class_docstr: PL Lightning Module for the EfficientAd algorithm.
  
  Args:
      teacher_file_name (str): path to the pre-trained teacher model
      teacher_out_channels (int): number of convolution output channels
      image_size (tuple): size of input images
      model_size (str): size of student and teacher model
      lr (float): learning rate
      weight_decay (float): optimizer weight decay
      padding (bool): use padding in convoluional layers
      pad_maps (bool): relevant if padding is set to False. In this case, pad_maps = True pads the
          output anomaly maps so that their size matches the size in the padding = True case.
      batch_size (int): batch size for imagenet dataloader
class_docstr_tok: ["PL","Lightning","Module","for","the","EfficientAd","algorithm",".","Args",":","teacher_file_name","(","str",")",":","path","to","the","pre-trained","teacher","model","teacher_out_channels","(","int",")",":","number","of","convolution","output","channels","image_size","(","tuple",")",":","size","of","input","images","model_size","(","str",")",":","size","of","student","and","teacher","model","lr","(","float",")",":","learning","rate","weight_decay","(","float",")",":","optimizer","weight","decay","padding","(","bool",")",":","use","padding","in","convoluional","layers","pad_maps","(","bool",")",":","relevant","if","padding","is","set","to","False",".","In","this","case",",","pad_maps","=","True","pads","the","output","anomaly","maps","so","that","their","size","matches","the","size","in","the","padding","=","True","case",".","batch_size","(","int",")",":","batch","size","for","imagenet","dataloader"]
docstr: Calculate the mean and std of the teacher models activations.
  Adapted from https://math.stackexchange.com/a/2148949
  
  Args:
      dataloader (DataLoader): Dataloader of the respective dataset.
  
  Returns:
      dict[str, Tensor]: Dictionary of channel-wise mean and std
docstr_tok: ["Calculate","the","mean","and","std","of","the","teacher","models","activations",".","Adapted","from","https",":","\/\/math.stackexchange.com\/a\/2148949","Args",":","dataloader","(","DataLoader",")",":","Dataloader","of","the","respective","dataset",".","Returns",":","dict","[","str",",","Tensor","]",":","Dictionary","of","channel-wise","mean","and","std"]
code: def teacher_channel_mean_std(
      self, dataloader: DataLoader
  ) -> dict[str, Tensor]:
      """Calculate the mean and std of the teacher models activations.
      Adapted from https://math.stackexchange.com/a/2148949
  
      Args:
          dataloader (DataLoader): Dataloader of the respective dataset.
  
      Returns:
          dict[str, Tensor]: Dictionary of channel-wise mean and std
      """
  
      arrays_defined = False
      n: torch.Tensor | None = None
      chanel_sum: torch.Tensor | None = None
      chanel_sum_sqr: torch.Tensor | None = None
  
      for batch in tqdm.tqdm(
          dataloader,
          desc="Calculate teacher channel mean & std",
          position=0,
          leave=True,
      ):
          y = self.model.teacher(batch["image"].to(self.device))
          if not arrays_defined:
              _, num_channels, _, _ = y.shape
              n = torch.zeros(
                  (num_channels,), dtype=torch.int64, device=y.device
              )
              chanel_sum = torch.zeros(
                  (num_channels,), dtype=torch.float64, device=y.device
              )
              chanel_sum_sqr = torch.zeros(
                  (num_channels,), dtype=torch.float64, device=y.device
              )
              arrays_defined = True
  
          n += y[:, 0].numel()
          chanel_sum += torch.sum(y, dim=[0, 2, 3])
          chanel_sum_sqr += torch.sum(y**2, dim=[0, 2, 3])
  
      assert n is not None
  
      channel_mean = chanel_sum / n
  
      channel_std = (
          torch.sqrt((chanel_sum_sqr / n) - (channel_mean**2))
      ).float()[None, :, None, None]
      channel_mean = channel_mean.float()[None, :, None, None]
  
      return {"mean": channel_mean, "std": channel_std}
  
imports: from __future__ import annotations
  import logging
  from pathlib import Path
  import albumentations
  import numpy
  import torch
  import tqdm
  from albumentations.pytorch import ToTensorV2
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.utilities.types import STEP_OUTPUT
  from torch import Tensor, optim
  from torch.utils.data import DataLoader
  from torchvision.datasets import ImageFolder
  from anomalib.data.utils import DownloadInfo, download_and_extract
  from anomalib.models.components import AnomalyModule
  from .torch_model import EfficientAdModel, EfficientAdModelSize, reduce_tensor_elems
label_desc: Use image node_id 4 for calling the EfficientAd obj's underlying member method code with example usage: obj.teacher_channel_mean_std(dataloader) and returns: dict