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: Extract features from the pretrained network.
  
  Args:
      batch (Tensor): Image batch.
  
  Returns:
      Tensor: Tensor containing extracted features.
docstr_tok: ["Extract","features","from","the","pretrained","network",".","Args",":","batch","(","Tensor",")",":","Image","batch",".","Returns",":","Tensor",":","Tensor","containing","extracted","features","."]
code: def get_features(self, batch: Tensor) -> Tensor:
      """Extract features from the pretrained network.
  
      Args:
          batch (Tensor): Image batch.
  
      Returns:
          Tensor: Tensor containing extracted features.
      """
      self.feature_extractor.eval()
      features = self.feature_extractor(batch)[self.layer]
      batch_size = len(features)
      if self.pooling_kernel_size > 1:
          features = F.avg_pool2d(
              input=features, kernel_size=self.pooling_kernel_size
          )
      feature_shapes = features.shape
      features = features.view(batch_size, -1).detach()
      if self.training:
          output = features
      else:
          output = (features, feature_shapes)
  
      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 4 for calling the DFMModel obj's underlying member method code with example usage: obj.get_features(batch) and returns: output