class_docstr: Callback that standardizes the image-level and pixel-level anomaly scores.
class_docstr_tok: ["Callback","that","standardizes","the","image-level","and","pixel-level","anomaly","scores","."]
docstr: Collect the statistics of the normal training data.
  
  Create a trainer and use it to predict the anomaly maps and scores of the normal training data. Then
   estimate the distribution of anomaly scores for normal data at the image and pixel level by computing
   the mean and standard deviations. A dictionary containing the computed statistics is stored in self.stats.
docstr_tok: ["Collect","the","statistics","of","the","normal","training","data",".","Create","a","trainer","and","use","it","to","predict","the","anomaly","maps","and","scores","of","the","normal","training","data",".","Then","estimate","the","distribution","of","anomaly","scores","for","normal","data","at","the","image","and","pixel","level","by","computing","the","mean","and","standard","deviations",".","A","dictionary","containing","the","computed","statistics","is","stored","in","self.stats","."]
code: def _collect_stats(
      self, trainer: pl.Trainer, pl_module: AnomalyModule
  ) -> None:
      """Collect the statistics of the normal training data.
  
      Create a trainer and use it to predict the anomaly maps and scores of the normal training data. Then
       estimate the distribution of anomaly scores for normal data at the image and pixel level by computing
       the mean and standard deviations. A dictionary containing the computed statistics is stored in self.stats.
      """
      predictions = Trainer(
          accelerator=trainer.accelerator, devices=trainer.num_devices
      ).predict(
          model=self._create_inference_model(pl_module),
          dataloaders=trainer.datamodule.train_dataloader(),
      )
      pl_module.normalization_metrics.reset()
      for batch in predictions:
          if "pred_scores" in batch.keys():
              pl_module.normalization_metrics.update(
                  anomaly_scores=batch["pred_scores"]
              )
          if "anomaly_maps" in batch.keys():
              pl_module.normalization_metrics.update(
                  anomaly_maps=batch["anomaly_maps"]
              )
      pl_module.normalization_metrics.compute()
  
imports: from __future__ import annotations
  import logging
  from typing import Any
  import pytorch_lightning
  from pytorch_lightning import Callback, Trainer
  from pytorch_lightning.utilities.types import STEP_OUTPUT
  from torch.distributions import LogNormal
  from anomalib.models import get_model
  from anomalib.models.components import AnomalyModule
  from anomalib.post_processing.normalization.cdf import normalize, standardize
  from anomalib.utils.metrics import AnomalyScoreDistribution
label_desc: Use image node_id 8 for calling the CdfNormalizationCallback obj's underlying member method code with example usage: obj._collect_stats(trainer, pl_module) without return types