class_docstr: Event handler triggered on completing every iteration to calculate and save the probability map.
  This handler use metadata from MetaTensor to create the probability map. This can be simply achieved by using
  `monai.data.SlidingPatchWSIDataset` or `monai.data.MaskedPatchWSIDataset` as the dataset.
docstr: Args:
      engine: Ignite Engine, it can be a trainer, validator or evaluator.
docstr_tok: ["Args",":","engine",":","Ignite","Engine",",","it","can","be","a","trainer",",","validator","or","evaluator","."]
code: def attach(self, engine: Engine) -> None:
      """
      Args:
          engine: Ignite Engine, it can be a trainer, validator or evaluator.
      """
  
      image_data = engine.data_loader.dataset.image_data  # type: ignore
      self.num_images = len(image_data)
  
      # Initialized probability maps for all the images
      for sample in image_data:
          name = sample[ProbMapKeys.NAME]
          self.counter[name] = sample[ProbMapKeys.COUNT]
          self.prob_map[name] = np.zeros(
              sample[ProbMapKeys.SIZE], dtype=self.dtype
          )
  
      if self._name is None:
          self.logger = engine.logger
      if not engine.has_event_handler(self, Events.ITERATION_COMPLETED):
          engine.add_event_handler(Events.ITERATION_COMPLETED, self)
      if not engine.has_event_handler(self.finalize, Events.COMPLETED):
          engine.add_event_handler(Events.COMPLETED, self.finalize)
  
file_path: MONAI/monai/handlers/probability_maps.py
imports: from __future__ import annotations
  import logging
  import threading
  from typing import TYPE_CHECKING
  import numpy
  from monai.config import DtypeLike, IgniteInfo
  from monai.data.folder_layout import FolderLayout
  from monai.utils import ProbMapKeys, min_version, optional_import
  from monai.utils.enums import CommonKeys
label_desc: Use image node_id 2 for calling the ProbMapProducer obj's underlying member method code with example usage: obj.attach(engine) without return types