class_docstr: Torch implementation of the CFA Model.
  
  Args:
      input_size: (tuple[int, int]): Input size of the image tensor.
      backbone (str): Backbone CNN network.
      gamma_c (int): gamma_c parameter from the paper.
      gamma_d (int): gamma_d parameter from the paper.
      num_nearest_neighbors (int): Number of nearest neighbors.
      num_hard_negative_features (int): Number of hard negative features.
      radius (float): Radius of the hypersphere to search the soft boundary.
class_docstr_tok: ["Torch","implementation","of","the","CFA","Model",".","Args",":","input_size",":","(","tuple","[","int",",","int","]",")",":","Input","size","of","the","image","tensor",".","backbone","(","str",")",":","Backbone","CNN","network",".","gamma_c","(","int",")",":","gamma_c","parameter","from","the","paper",".","gamma_d","(","int",")",":","gamma_d","parameter","from","the","paper",".","num_nearest_neighbors","(","int",")",":","Number","of","nearest","neighbors",".","num_hard_negative_features","(","int",")",":","Number","of","hard","negative","features",".","radius","(","float",")",":","Radius","of","the","hypersphere","to","search","the","soft","boundary","."]
docstr: Compute distance using target oriented features.
  
  Args:
      target_oriented_features (Tensor): Target oriented features computed
          using the descriptor.
  
  Returns:
      Tensor: Distance tensor.
docstr_tok: ["Compute","distance","using","target","oriented","features",".","Args",":","target_oriented_features","(","Tensor",")",":","Target","oriented","features","computed","using","the","descriptor",".","Returns",":","Tensor",":","Distance","tensor","."]
code: def compute_distance(
      self, target_oriented_features: Tensor
  ) -> Tensor:
      """Compute distance using target oriented features.
  
      Args:
          target_oriented_features (Tensor): Target oriented features computed
              using the descriptor.
  
      Returns:
          Tensor: Distance tensor.
      """
      if target_oriented_features.ndim == 4:
          target_oriented_features = rearrange(
              target_oriented_features, "b c h w -> b (h w) c"
          )
  
      features = target_oriented_features.pow(2).sum(
          dim=2, keepdim=True
      )
      centers = (
          self.memory_bank.pow(2)
          .sum(dim=0, keepdim=True)
          .to(features.device)
      )
      f_c = 2 * torch.matmul(
          target_oriented_features,
          (self.memory_bank.to(features.device)),
      )
      distance = features + centers - f_c
      return distance
  
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  import torchvision
  from einops import rearrange
  from sklearn.cluster import KMeans
  from torch import Tensor, nn
  from torch.fx.graph_module import GraphModule
  from torch.nn.common_types import _size_2_t
  from torch.utils.data import DataLoader
  from torchvision.models.feature_extraction import create_feature_extractor
  from tqdm import tqdm
  from anomalib.models.cfa.anomaly_map import AnomalyMapGenerator
  from anomalib.models.components import DynamicBufferModule
  from anomalib.models.components.feature_extractors import dryrun_find_featuremap_dims
label_desc: Use image node_id 3 for calling the CfaModel obj's underlying member method code with example usage: obj.compute_distance(target_oriented_features) and returns: distance