code: def inference(img, model, tile, tile_overlap, window_size, scale):
      # test the image tile by tile
      b, c, h, w = img.size()
      tile = min(tile, h, w)
      assert (
          tile % window_size == 0
      ), "tile size should be a multiple of window_size"
      sf = scale
  
      stride = tile - tile_overlap
      h_idx_list = list(range(0, h - tile, stride)) + [h - tile]
      w_idx_list = list(range(0, w - tile, stride)) + [w - tile]
      E = torch.zeros(
          b,
          c,
          h * sf,
          w * sf,
          dtype=devices.dtype,
          device=device_swinir,
      ).type_as(img)
      W = torch.zeros_like(E, dtype=devices.dtype, device=device_swinir)
  
      with tqdm(
          total=len(h_idx_list) * len(w_idx_list), desc="SwinIR tiles"
      ) as pbar:
          for h_idx in h_idx_list:
              if state.interrupted or state.skipped:
                  break
  
              for w_idx in w_idx_list:
                  if state.interrupted or state.skipped:
                      break
  
                  in_patch = img[
                      ..., h_idx : h_idx + tile, w_idx : w_idx + tile
                  ]
                  out_patch = model(in_patch)
                  out_patch_mask = torch.ones_like(out_patch)
  
                  E[
                      ...,
                      h_idx * sf : (h_idx + tile) * sf,
                      w_idx * sf : (w_idx + tile) * sf,
                  ].add_(out_patch)
                  W[
                      ...,
                      h_idx * sf : (h_idx + tile) * sf,
                      w_idx * sf : (w_idx + tile) * sf,
                  ].add_(out_patch_mask)
                  pbar.update(1)
      output = E.div_(W)
  
      return output
  
file_path: stable-diffusion-webui/extensions-builtin/SwinIR/scripts/swinir_model.py
imports: import sys
  import platform
  import numpy
  import torch
  from PIL import Image
  from tqdm import tqdm
  from modules import modelloader, devices, script_callbacks, shared
  from modules.shared import opts, state
  from swinir_model_arch import SwinIR
  from swinir_model_arch_v2 import Swin2SR
  from modules.upscaler import Upscaler, UpscalerData
label_desc: Use image node_id 2 for calling a global function with example usage: inference(img, model, tile, tile_overlap, window_size, scale) and returns: output