class_docstr: Model for the DFM algorithm.
  
  Args:
      backbone (str): Pre-trained model backbone.
      layer (str): Layer from which to extract features.
      input_size (tuple[int, int]): Input size for the model.
      pre_trained (bool, optional): Boolean to check whether to use a pre_trained backbone.
      pooling_kernel_size (int, optional): Kernel size to pool features extracted from the CNN.
      n_comps (float, optional): Ratio from which number of components for PCA are calculated. Defaults to 0.97.
      score_type (str, optional): Scoring type. Options are `fre` and `nll`. Defaults to "fre". Anomaly
      segmentation is supported with `fre` only. If using `nll`, set `task` in config.yaml to classification
class_docstr_tok: ["Model","for","the","DFM","algorithm",".","Args",":","backbone","(","str",")",":","Pre-trained","model","backbone",".","layer","(","str",")",":","Layer","from","which","to","extract","features",".","input_size","(","tuple","[","int",",","int","]",")",":","Input","size","for","the","model",".","pre_trained","(","bool",",","optional",")",":","Boolean","to","check","whether","to","use","a","pre_trained","backbone",".","pooling_kernel_size","(","int",",","optional",")",":","Kernel","size","to","pool","features","extracted","from","the","CNN",".","n_comps","(","float",",","optional",")",":","Ratio","from","which","number","of","components","for","PCA","are","calculated",".","Defaults","to","0.97.","score_type","(","str",",","optional",")",":","Scoring","type",".","Options","are","`","fre","`","and","`","nll","`",".","Defaults","to","``","fre","''",".","Anomaly","segmentation","is","supported","with","`","fre","`","only",".","If","using","`","nll","`",",","set","`","task","`","in","config.yaml","to","classification"]
docstr: Compute scores.
  
  Scores are either PCA-based feature reconstruction error (FRE) scores or
  the Gaussian density-based NLL scores
  
  Args:
      features (torch.Tensor): semantic features on which PCA and density modeling is performed.
      feature_shapes  (tuple): shape of `features` tensor. Used to generate anomaly map of correct shape.
  
  Returns:
      score (Tensor): numpy array of scores
docstr_tok: ["Compute","scores",".","Scores","are","either","PCA-based","feature","reconstruction","error","(","FRE",")","scores","or","the","Gaussian","density-based","NLL","scores","Args",":","features","(","torch.Tensor",")",":","semantic","features","on","which","PCA","and","density","modeling","is","performed",".","feature_shapes","(","tuple",")",":","shape","of","`","features","`","tensor",".","Used","to","generate","anomaly","map","of","correct","shape",".","Returns",":","score","(","Tensor",")",":","numpy","array","of","scores"]
code: def score(self, features: Tensor, feature_shapes: tuple) -> Tensor:
      """Compute scores.
  
      Scores are either PCA-based feature reconstruction error (FRE) scores or
      the Gaussian density-based NLL scores
  
      Args:
          features (torch.Tensor): semantic features on which PCA and density modeling is performed.
          feature_shapes  (tuple): shape of `features` tensor. Used to generate anomaly map of correct shape.
  
      Returns:
          score (Tensor): numpy array of scores
      """
      feats_projected = self.pca_model.transform(features)
      if self.score_type == "nll":
          score = self.gaussian_model.score_samples(feats_projected)
      elif self.score_type == "fre":
          feats_reconstructed = self.pca_model.inverse_transform(
              feats_projected
          )
          fre = torch.square(features - feats_reconstructed).reshape(
              feature_shapes
          )
          fre_map = torch.unsqueeze(torch.sum(fre, dim=1), 1)
          score_map = F.interpolate(
              fre_map,
              size=self.input_size,
              mode="bilinear",
              align_corners=False,
          )
          score = torch.sum(
              torch.square(features - feats_reconstructed), dim=1
          )
      else:
          raise ValueError(f"unsupported score type: {self.score_type}")
  
      if self.score_type == "nll":
          output = score
      else:
          output = score_map, score
  
      return output
  
file_path: anomalib/src/anomalib/models/dfm/torch_model.py
imports: from __future__ import annotations
  import math
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from anomalib.models.components import PCA, DynamicBufferModule, FeatureExtractor
label_desc: Use image node_id 3 for calling the DFMModel obj's underlying member method code with example usage: obj.score(features, feature_shapes) and returns: output