class_docstr: Sliding window method for model inference,
  with `sw_batch_size` windows for every model.forward().
  Usage example can be found in the :py:class:`monai.inferers.Inferer` base class.
  
  Args:
      roi_size: the window size to execute SlidingWindow evaluation.
          If it has non-positive components, the corresponding `inputs` size will be used.
          if the components of the `roi_size` are non-positive values, the transform will use the
          corresponding components of img size. For example, `roi_size=(32, -1)` will be adapted
          to `(32, 64)` if the second spatial dimension size of img is `64`.
      sw_batch_size: the batch size to run window slices.
      overlap: Amount of overlap between scans along each spatial dimension, defaults to ``0.25``.
      mode: {``"constant"``, ``"gaussian"``}
          How to blend output of overlapping windows. Defaults to ``"constant"``.
  
          - ``"constant``": gives equal weight to all predictions.
          - ``"gaussian``": gives less weight to predictions on edges of windows.
  
      sigma_scale: the standard deviation coefficient of the Gaussian window when `mode` is ``"gaussian"``.
          Default: 0.125. Actual window sigma is ``sigma_scale`` * ``dim_size``.
          When sigma_scale is a sequence of floats, the values denote sigma_scale at the corresponding
          spatial dimensions.
      padding_mode: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}
          Padding mode when ``roi_size`` is larger than inputs. Defaults to ``"constant"``
          See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html
      cval: fill value for 'constant' padding mode. Default: 0
      sw_device: device for the window data.
          By default the device (and accordingly the memory) of the `inputs` is used.
          Normally `sw_device` should be consistent with the device where `predictor` is defined.
      device: device for the stitched output prediction.
          By default the device (and accordingly the memory) of the `inputs` is used. If for example
          set to device=torch.device('cpu') the gpu memory consumption is less and independent of the
          `inputs` and `roi_size`. Output is on the `device`.
      progress: whether to print a tqdm progress bar.
      cache_roi_weight_map: whether to precompute the ROI weight map.
      cpu_thresh: when provided, dynamically switch to stitching on cpu (to save gpu memory)
          when input image volume is larger than this threshold (in pixels/voxels).
          Otherwise use ``"device"``. Thus, the output may end-up on either cpu or gpu.
      buffer_steps: the number of sliding window iterations along the ``buffer_dim``
          to be buffered on ``sw_device`` before writing to ``device``.
          (Typically, ``sw_device`` is ``cuda`` and ``device`` is ``cpu``.)
          default is None, no buffering. For the buffer dim, when spatial size is divisible by buffer_steps*roi_size,
          (i.e. no overlapping among the buffers) non_blocking copy may be automatically enabled for efficiency.
      buffer_dim: the spatial dimension along which the buffers are created.
          0 indicates the first spatial dimension. Default is -1, the last spatial dimension.
      with_coord: whether to pass the window coordinates to ``network``. Defaults to False.
          If True, the ``network``'s 2nd input argument should accept the window coordinates.
  
  Note:
      ``sw_batch_size`` denotes the max number of windows per network inference iteration,
      not the batch size of inputs.
class_docstr_tok: ["Sliding","window","method","for","model","inference",",","with","`","sw_batch_size","`","windows","for","every","model.forward","(",")",".","Usage","example","can","be","found","in","the",":","py",":","class",":","`","monai.inferers.Inferer","`","base","class",".","Args",":","roi_size",":","the","window","size","to","execute","SlidingWindow","evaluation",".","If","it","has","non-positive","components",",","the","corresponding","`","inputs","`","size","will","be","used",".","if","the","components","of","the","`","roi_size","`","are","non-positive","values",",","the","transform","will","use","the","corresponding","components","of","img","size",".","For","example",",","`","roi_size=","(","32",",","-1",")","`","will","be","adapted","to","`","(","32",",","64",")","`","if","the","second","spatial","dimension","size","of","img","is","`","64","`",".","sw_batch_size",":","the","batch","size","to","run","window","slices",".","overlap",":","Amount","of","overlap","between","scans","along","each","spatial","dimension",",","defaults","to","``","0.25","``",".","mode",":","{","``","``","constant","''","``",",","``","``","gaussian","''","``","}","How","to","blend","output","of","overlapping","windows",".","Defaults","to","``","``","constant","''","``",".","-","``","``","constant","``","``",":","gives","equal","weight","to","all","predictions",".","-","``","``","gaussian","``","``",":","gives","less","weight","to","predictions","on","edges","of","windows",".","sigma_scale",":","the","standard","deviation","coefficient","of","the","Gaussian","window","when","`","mode","`","is","``","``","gaussian","''","``",".","Default",":","0.125",".","Actual","window","sigma","is","``","sigma_scale","``","*","``","dim_size","``",".","When","sigma_scale","is","a","sequence","of","floats",",","the","values","denote","sigma_scale","at","the","corresponding","spatial","dimensions",".","padding_mode",":","{","``","``","constant","''","``",",","``","``","reflect","''","``",",","``","``","replicate","''","``",",","``","``","circular","''","``","}","Padding","mode","when","``","roi_size","``","is","larger","than","inputs",".","Defaults","to","``","``","constant","''","``","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.functional.pad.html","cval",":","fill","value","for","'constant","'","padding","mode",".","Default",":","0","sw_device",":","device","for","the","window","data",".","By","default","the","device","(","and","accordingly","the","memory",")","of","the","`","inputs","`","is","used",".","Normally","`","sw_device","`","should","be","consistent","with","the","device","where","`","predictor","`","is","defined",".","device",":","device","for","the","stitched","output","prediction",".","By","default","the","device","(","and","accordingly","the","memory",")","of","the","`","inputs","`","is","used",".","If","for","example","set","to","device=torch.device","(","'cpu","'",")","the","gpu","memory","consumption","is","less","and","independent","of","the","`","inputs","`","and","`","roi_size","`",".","Output","is","on","the","`","device","`",".","progress",":","whether","to","print","a","tqdm","progress","bar",".","cache_roi_weight_map",":","whether","to","precompute","the","ROI","weight","map",".","cpu_thresh",":","when","provided",",","dynamically","switch","to","stitching","on","cpu","(","to","save","gpu","memory",")","when","input","image","volume","is","larger","than","this","threshold","(","in","pixels\/voxels",")",".","Otherwise","use","``","``","device","''","``",".","Thus",",","the","output","may","end-up","on","either","cpu","or","gpu",".","buffer_steps",":","the","number","of","sliding","window","iterations","along","the","``","buffer_dim","``","to","be","buffered","on","``","sw_device","``","before","writing","to","``","device","``",".","(","Typically",",","``","sw_device","``","is","``","cuda","``","and","``","device","``","is","``","cpu","``",".",")","default","is","None",",","no","buffering",".","For","the","buffer","dim",",","when","spatial","size","is","divisible","by","buffer_steps","*","roi_size",",","(","i.e",".","no","overlapping","among","the","buffers",")","non_blocking","copy","may","be","automatically","enabled","for","efficiency",".","buffer_dim",":","the","spatial","dimension","along","which","the","buffers","are","created",".","0","indicates","the","first","spatial","dimension",".","Default","is","-1",",","the","last","spatial","dimension",".","with_coord",":","whether","to","pass","the","window","coordinates","to","``","network","``",".","Defaults","to","False",".","If","True",",","the","``","network","``","'s","2nd","input","argument","should","accept","the","window","coordinates",".","Note",":","``","sw_batch_size","``","denotes","the","max","number","of","windows","per","network","inference","iteration",",","not","the","batch","size","of","inputs","."]
code: def __init__(
      self,
      roi_size: Sequence[int] | int,
      sw_batch_size: int = 1,
      overlap: Sequence[float] | float = 0.25,
      mode: BlendMode | str = BlendMode.CONSTANT,
      sigma_scale: Sequence[float] | float = 0.125,
      padding_mode: PytorchPadMode | str = PytorchPadMode.CONSTANT,
      cval: float = 0.0,
      sw_device: torch.device | str | None = None,
      device: torch.device | str | None = None,
      progress: bool = False,
      cache_roi_weight_map: bool = False,
      cpu_thresh: int | None = None,
      buffer_steps: int | None = None,
      buffer_dim: int = -1,
      with_coord: bool = False,
  ) -> None:
      super().__init__()
      self.roi_size = roi_size
      self.sw_batch_size = sw_batch_size
      self.overlap = overlap
      self.mode: BlendMode = BlendMode(mode)
      self.sigma_scale = sigma_scale
      self.padding_mode = padding_mode
      self.cval = cval
      self.sw_device = sw_device
      self.device = device
      self.progress = progress
      self.cpu_thresh = cpu_thresh
      self.buffer_steps = buffer_steps
      self.buffer_dim = buffer_dim
      self.with_coord = with_coord
  
      # compute_importance_map takes long time when computing on cpu. We thus
      # compute it once if it's static and then save it for future usage
      self.roi_weight_map = None
      try:
          if (
              cache_roi_weight_map
              and isinstance(roi_size, Sequence)
              and min(roi_size) > 0
          ):  # non-dynamic roi size
              if device is None:
                  device = "cpu"
              self.roi_weight_map = compute_importance_map(
                  ensure_tuple(self.roi_size),
                  mode=mode,
                  sigma_scale=sigma_scale,
                  device=device,
              )
          if cache_roi_weight_map and self.roi_weight_map is None:
              warnings.warn(
                  "cache_roi_weight_map=True, but cache is not created. (dynamic roi_size?)"
              )
      except BaseException as e:
          raise RuntimeError(
              f"roi size {self.roi_size}, mode={mode}, sigma_scale={sigma_scale}, device={device}\n"
              "Seems to be OOM. Please try smaller patch size or mode='constant' instead of mode='gaussian'."
          ) from e
  
imports: from __future__ import annotations
  import warnings
  from abc import ABC, abstractmethod
  from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
  from pydoc import locate
  from typing import Any
  import torch
  import torch.nn
  from monai.apps.utils import get_logger
  from monai.data.meta_tensor import MetaTensor
  from monai.data.thread_buffer import ThreadBuffer
  from monai.inferers.merger import AvgMerger, Merger
  from monai.inferers.splitter import Splitter
  from monai.inferers.utils import compute_importance_map, sliding_window_inference
  from monai.utils import BlendMode, PatchKeys, PytorchPadMode, ensure_tuple, optional_import
  from monai.visualize import CAM, GradCAM, GradCAMpp
label_desc: Use image node_id 1 to create a new SlidingWindowInferer object from inherited base classes: Inferer with example: obj = SlidingWindowInferer(roi_size, sw_batch_size, overlap, mode, sigma_scale, padding_mode, cval, sw_device, device, progress, cache_roi_weight_map, cpu_thresh, buffer_steps, buffer_dim, with_coord)