class_docstr: PatchcoreLightning Module to train PatchCore algorithm.
  
  Args:
      input_size (tuple[int, int]): Size of the model input.
      backbone (str): Backbone CNN network
      layers (list[str]): Layers to extract features from the backbone CNN
      pre_trained (bool, optional): Boolean to check whether to use a pre_trained backbone.
      coreset_sampling_ratio (float, optional): Coreset sampling ratio to subsample embedding.
          Defaults to 0.1.
      num_neighbors (int, optional): Number of nearest neighbors. Defaults to 9.
class_docstr_tok: ["PatchcoreLightning","Module","to","train","PatchCore","algorithm",".","Args",":","input_size","(","tuple","[","int",",","int","]",")",":","Size","of","the","model","input",".","backbone","(","str",")",":","Backbone","CNN","network","layers","(","list","[","str","]",")",":","Layers","to","extract","features","from","the","backbone","CNN","pre_trained","(","bool",",","optional",")",":","Boolean","to","check","whether","to","use","a","pre_trained","backbone",".","coreset_sampling_ratio","(","float",",","optional",")",":","Coreset","sampling","ratio","to","subsample","embedding",".","Defaults","to","0.1.","num_neighbors","(","int",",","optional",")",":","Number","of","nearest","neighbors",".","Defaults","to","9","."]
docstr: Apply subsampling to the embedding collected from the training set.
docstr_tok: ["Apply","subsampling","to","the","embedding","collected","from","the","training","set","."]
code: def on_validation_start(self) -> None:
      """Apply subsampling to the embedding collected from the training set."""
      # NOTE: Previous anomalib versions fit subsampling at the end of the epoch.
      #   This is not possible anymore with PyTorch Lightning v1.4.0 since validation
      #   is run within train epoch.
      logger.info(
          "Aggregating the embedding extracted from the training set."
      )
      embeddings = torch.vstack(self.embeddings)
  
      logger.info("Applying core-set subsampling to get the embedding.")
      self.model.subsample_embedding(
          embeddings, self.coreset_sampling_ratio
      )
  
file_path: anomalib/src/anomalib/models/patchcore/lightning_model.py
imports: from __future__ import annotations
  import logging
  import torch
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.utilities.types import STEP_OUTPUT
  from torch import Tensor
  from anomalib.models.components import AnomalyModule
  from anomalib.models.patchcore.torch_model import PatchcoreModel
label_desc: Use image node_id 4 for calling the Patchcore obj's underlying member method code with example usage: obj.on_validation_start() without return types