class_docstr: Feature Pyramid Loss This class implmenents the feature pyramid loss function proposed in STFPM paper.
  
  Example:
      >>> from anomalib.models.components.feature_extractors import FeatureExtractor
      >>> from anomalib.models.stfpm.loss import STFPMLoss
      >>> from torchvision.models import resnet18
  
      >>> layers = ['layer1', 'layer2', 'layer3']
      >>> teacher_model = FeatureExtractor(model=resnet18(pretrained=True), layers=layers)
      >>> student_model = FeatureExtractor(model=resnet18(pretrained=False), layers=layers)
      >>> loss = Loss()
  
      >>> inp = torch.rand((4, 3, 256, 256))
      >>> teacher_features = teacher_model(inp)
      >>> student_features = student_model(inp)
      >>> loss(student_features, teacher_features)
          tensor(51.2015, grad_fn=<SumBackward0>)
docstr: Compute the overall loss via the weighted average of the layer losses computed by the cosine similarity.
  
  Args:
    teacher_features (dict[str, Tensor]): Teacher features
    student_features (dict[str, Tensor]): Student features
  
  Returns:
    Total loss, which is the weighted average of the layer losses.
code: def forward(
      self,
      teacher_features: dict[str, Tensor],
      student_features: dict[str, Tensor],
  ) -> Tensor:
      """Compute the overall loss via the weighted average of the layer losses computed by the cosine similarity.
  
      Args:
        teacher_features (dict[str, Tensor]): Teacher features
        student_features (dict[str, Tensor]): Student features
  
      Returns:
        Total loss, which is the weighted average of the layer losses.
      """
  
      layer_losses: list[Tensor] = []
      for layer in teacher_features.keys():
          loss = self.compute_layer_loss(
              teacher_features[layer], student_features[layer]
          )
          layer_losses.append(loss)
  
      total_loss = torch.stack(layer_losses).sum()
  
      return total_loss
  
file_path: anomalib/src/anomalib/models/stfpm/loss.py
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
label_desc: Use image node_id 3 for calling the STFPMLoss obj's underlying member method code with example usage: obj.forward(teacher_features, student_features) and returns: total_loss