class_docstr: Classification module for KDE-based anomaly detection.
  
  Args:
      n_pca_components (int, optional): Number of PCA components. Defaults to 16.
      feature_scaling_method (FeatureScalingMethod, optional): Scaling method applied to features before passing to
          KDE. Options are `norm` (normalize to unit vector length) and `scale` (scale to max length observed in
          training).
      max_training_points (int, optional): Maximum number of training points to fit the KDE model. Defaults to 40000.
class_docstr_tok: ["Classification","module","for","KDE-based","anomaly","detection",".","Args",":","n_pca_components","(","int",",","optional",")",":","Number","of","PCA","components",".","Defaults","to","16.","feature_scaling_method","(","FeatureScalingMethod",",","optional",")",":","Scaling","method","applied","to","features","before","passing","to","KDE",".","Options","are","`","norm","`","(","normalize","to","unit","vector","length",")","and","`","scale","`","(","scale","to","max","length","observed","in","training",")",".","max_training_points","(","int",",","optional",")",":","Maximum","number","of","training","points","to","fit","the","KDE","model",".","Defaults","to","40000","."]
docstr: Pre-process the CNN features.
  
  Args:
    feature_stack (Tensor): Features extracted from CNN
    max_length (Tensor | None): Used to unit normalize the feature_stack vector. If ``max_len`` is not
      provided, the length is calculated from the ``feature_stack``. Defaults to None.
  
  Returns:
      (Tuple): Stacked features and length
docstr_tok: ["Pre-process","the","CNN","features",".","Args",":","feature_stack","(","Tensor",")",":","Features","extracted","from","CNN","max_length","(","Tensor","|","None",")",":","Used","to","unit","normalize","the","feature_stack","vector",".","If","``","max_len","``","is","not","provided",",","the","length","is","calculated","from","the","``","feature_stack","``",".","Defaults","to","None",".","Returns",":","(","Tuple",")",":","Stacked","features","and","length"]
code: def pre_process(
      self, feature_stack: Tensor, max_length: Tensor | None = None
  ) -> tuple[Tensor, Tensor]:
      """Pre-process the CNN features.
  
      Args:
        feature_stack (Tensor): Features extracted from CNN
        max_length (Tensor | None): Used to unit normalize the feature_stack vector. If ``max_len`` is not
          provided, the length is calculated from the ``feature_stack``. Defaults to None.
  
      Returns:
          (Tuple): Stacked features and length
      """
  
      if max_length is None:
          max_length = torch.max(
              torch.linalg.norm(feature_stack, ord=2, dim=1)
          )
  
      if self.feature_scaling_method == FeatureScalingMethod.NORM:
          feature_stack /= torch.linalg.norm(
              feature_stack, ord=2, dim=1
          )[:, None]
      elif self.feature_scaling_method == FeatureScalingMethod.SCALE:
          feature_stack /= max_length
      else:
          raise RuntimeError(
              "Unknown pre-processing mode. Available modes are: Normalized and Scale."
          )
      return feature_stack, max_length
  
file_path: anomalib/src/anomalib/models/components/classification/kde_classifier.py
imports: from __future__ import annotations
  import logging
  import random
  from enum import Enum
  import torch
  from torch import Tensor, nn
  from anomalib.models.components import PCA, GaussianKDE
label_desc: Use image node_id 2 for calling the KDEClassifier obj's underlying member method code with example usage: obj.pre_process(feature_stack, max_length) and returns: feature_stack,  max_length