class_docstr: Encoder Decoder segmentors.
  
  EncoderDecoder typically consists of backbone, decode_head, auxiliary_head.
  Note that auxiliary_head is only used for deep supervision during training,
  which could be dumped during inference.
class_docstr_tok: ["Encoder","Decoder","segmentors",".","EncoderDecoder","typically","consists","of","backbone",",","decode_head",",","auxiliary_head",".","Note","that","auxiliary_head","is","only","used","for","deep","supervision","during","training",",","which","could","be","dumped","during","inference","."]
docstr: Inference by sliding-window with overlap.
  
  If h_crop > h_img or w_crop > w_img, the small patch will be used to
  decode without padding.
docstr_tok: ["Inference","by","sliding-window","with","overlap",".","If","h_crop",">","h_img","or","w_crop",">","w_img",",","the","small","patch","will","be","used","to","decode","without","padding","."]
code: def slide_inference(self, img, img_meta, rescale):
      """Inference by sliding-window with overlap.
  
      If h_crop > h_img or w_crop > w_img, the small patch will be used to
      decode without padding.
      """
  
      h_stride, w_stride = self.test_cfg.stride
      h_crop, w_crop = self.test_cfg.crop_size
      batch_size, _, h_img, w_img = img.size()
      num_classes = self.num_classes
      h_grids = max(h_img - h_crop + h_stride - 1, 0) // h_stride + 1
      w_grids = max(w_img - w_crop + w_stride - 1, 0) // w_stride + 1
      preds = img.new_zeros((batch_size, num_classes, h_img, w_img))
      count_mat = img.new_zeros((batch_size, 1, h_img, w_img))
      for h_idx in range(h_grids):
          for w_idx in range(w_grids):
              y1 = h_idx * h_stride
              x1 = w_idx * w_stride
              y2 = min(y1 + h_crop, h_img)
              x2 = min(x1 + w_crop, w_img)
              y1 = max(y2 - h_crop, 0)
              x1 = max(x2 - w_crop, 0)
              crop_img = img[:, :, y1:y2, x1:x2]
              crop_seg_logit = self.encode_decode(crop_img, img_meta)
              preds += F.pad(
                  crop_seg_logit,
                  (
                      int(x1),
                      int(preds.shape[3] - x2),
                      int(y1),
                      int(preds.shape[2] - y2),
                  ),
              )
  
              count_mat[:, :, y1:y2, x1:x2] += 1
      assert (count_mat == 0).sum() == 0
      if torch.onnx.is_in_onnx_export():
          # cast count_mat to constant while exporting to ONNX
          count_mat = torch.from_numpy(
              count_mat.cpu().detach().numpy()
          ).to(device=img.device)
      preds = preds / count_mat
      if rescale:
          preds = resize(
              preds,
              size=img_meta[0]["ori_shape"][:2],
              mode="bilinear",
              align_corners=self.align_corners,
              warning=False,
          )
      return preds
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from mmseg.core import add_prefix
  from mmseg.models import builder
  from mmseg.models.builder import SEGMENTORS
  from mmseg.models.segmentors.base import BaseSegmentor
  from mmseg.ops import resize
label_desc: Use image node_id 11 for calling the EncoderDecoderMask2Former obj's underlying member method code with example usage: obj.slide_inference(img, img_meta, rescale) and returns: preds