class_docstr: Generate Anomaly Heatmap.
docstr: Compute the layer map based on likelihood estimation.
  
  Args:
    distribution: Probability distribution for each decoder block
    height: blocks height
    width: blocks width
  
  Returns:
    Final Anomaly Map
docstr_tok: ["Compute","the","layer","map","based","on","likelihood","estimation",".","Args",":","distribution",":","Probability","distribution","for","each","decoder","block","height",":","blocks","height","width",":","blocks","width","Returns",":","Final","Anomaly","Map"]
code: def compute_anomaly_map(
      self,
      distribution: list[Tensor],
      height: list[int],
      width: list[int],
  ) -> Tensor:
      """Compute the layer map based on likelihood estimation.
  
      Args:
        distribution: Probability distribution for each decoder block
        height: blocks height
        width: blocks width
  
      Returns:
        Final Anomaly Map
  
      """
      layer_maps: list[Tensor] = []
      for layer_idx in range(len(self.pool_layers)):
          layer_distribution = distribution[layer_idx].clone().detach()
          # Normalize the likelihoods to (-Inf:0] and convert to probs in range [0:1]
          layer_probabilities = torch.exp(
              layer_distribution - layer_distribution.max()
          )
          layer_map = layer_probabilities.reshape(
              -1, height[layer_idx], width[layer_idx]
          )
          # upsample
          layer_maps.append(
              F.interpolate(
                  layer_map.unsqueeze(1),
                  size=self.image_size,
                  mode="bilinear",
                  align_corners=True,
              ).squeeze(1)
          )
      # score aggregation
      score_map = torch.zeros_like(layer_maps[0])
      for layer_idx in range(len(self.pool_layers)):
          score_map += layer_maps[layer_idx]
  
      # Invert probs to anomaly scores
      anomaly_map = score_map.max() - score_map
  
      return anomaly_map
  
file_path: anomalib/src/anomalib/models/cflow/anomaly_map.py
imports: from __future__ import annotations
  from typing import List, cast
  import torch
  import torch.nn.functional
  from omegaconf import ListConfig
  from torch import Tensor, nn
label_desc: Use image node_id 2 for calling the AnomalyMapGenerator obj's underlying member method code with example usage: obj.compute_anomaly_map(distribution, height, width) and returns: anomaly_map