class_docstr: Tile Image into (non)overlapping Patches. Images are tiled in order to efficiently process large images.
  
  Args:
      tile_size: Tile dimension for each patch
      stride: Stride length between patches
      remove_border_count: Number of border pixels to be removed from tile before untiling
      mode: Upscaling mode for image resize.Supported formats: padding, interpolation
  
  Examples:
      >>> import torch
      >>> from torchvision import transforms
      >>> from skimage.data import camera
      >>> tiler = Tiler(tile_size=256,stride=128)
      >>> image = transforms.ToTensor()(camera())
      >>> tiles = tiler.tile(image)
      >>> image.shape, tiles.shape
      (torch.Size([3, 512, 512]), torch.Size([9, 3, 256, 256]))
  
      >>> # Perform your operations on the tiles.
  
      >>> # Untile the patches to reconstruct the image
      >>> reconstructed_image = tiler.untile(tiles)
      >>> reconstructed_image.shape
      torch.Size([1, 3, 512, 512])
docstr: Fold the tiles back into the original tensor.
  
  This is the core method to reconstruct the original image from its tiled version.
  
  Args:
      tiles: Tiles from the input image, generated via __unfold method.
  
  Returns:
      Output that is the reconstructed version of the input tensor.
docstr_tok: ["Fold","the","tiles","back","into","the","original","tensor",".","This","is","the","core","method","to","reconstruct","the","original","image","from","its","tiled","version",".","Args",":","tiles",":","Tiles","from","the","input","image",",","generated","via","__unfold","method",".","Returns",":","Output","that","is","the","reconstructed","version","of","the","input","tensor","."]
code: def __fold(self, tiles: Tensor) -> Tensor:
      """Fold the tiles back into the original tensor.
  
      This is the core method to reconstruct the original image from its tiled version.
  
      Args:
          tiles: Tiles from the input image, generated via __unfold method.
  
      Returns:
          Output that is the reconstructed version of the input tensor.
      """
      # number of channels differs between image and anomaly map, so infer from input tiles.
      _, num_channels, tile_size_h, tile_size_w = tiles.shape
      scale_h, scale_w = (tile_size_h / self.tile_size_h), (
          tile_size_w / self.tile_size_w
      )
      # identify device type based on input tensor
      device = tiles.device
      # calculate tile size after borders removed
      reduced_tile_h = tile_size_h - (2 * self.remove_border_count)
      reduced_tile_w = tile_size_w - (2 * self.remove_border_count)
      # reconstructed image dimension
      image_size = (
          self.batch_size,
          num_channels,
          int(self.resized_h * scale_h),
          int(self.resized_w * scale_w),
      )
  
      # rearrange input tiles in format [tile_count, batch, channel, tile_h, tile_w]
      tiles = tiles.contiguous().view(
          self.batch_size,
          self.num_patches_h,
          self.num_patches_w,
          num_channels,
          tile_size_h,
          tile_size_w,
      )
      tiles = tiles.permute(0, 3, 1, 2, 4, 5)
      tiles = tiles.contiguous().view(
          self.batch_size, num_channels, -1, tile_size_h, tile_size_w
      )
      tiles = tiles.permute(2, 0, 1, 3, 4)
  
      # remove tile borders by defined count
      tiles = tiles[
          :,
          :,
          :,
          self.remove_border_count : reduced_tile_h
          + self.remove_border_count,
          self.remove_border_count : reduced_tile_w
          + self.remove_border_count,
      ]
  
      # create tensors to store intermediate results and outputs
      img = torch.zeros(image_size, device=device)
      lookup = torch.zeros(image_size, device=device)
      ones = torch.ones(reduced_tile_h, reduced_tile_w, device=device)
  
      # reconstruct image by adding patches to their respective location and
      # create a lookup for patch count in every location
      for patch, (loc_i, loc_j) in zip(
          tiles,
          product(
              range(
                  self.remove_border_count,
                  int(self.resized_h * scale_h) - reduced_tile_h + 1,
                  int(self.stride_h * scale_h),
              ),
              range(
                  self.remove_border_count,
                  int(self.resized_w * scale_w) - reduced_tile_w + 1,
                  int(self.stride_w * scale_w),
              ),
          ),
      ):
          img[
              :,
              :,
              loc_i : (loc_i + reduced_tile_h),
              loc_j : (loc_j + reduced_tile_w),
          ] += patch
          lookup[
              :,
              :,
              loc_i : (loc_i + reduced_tile_h),
              loc_j : (loc_j + reduced_tile_w),
          ] += ones
  
      # divide the reconstucted image by the lookup to average out the values
      img = torch.divide(img, lookup)
      # alternative way of removing nan values (isnan not supported by openvino)
      img[img != img] = 0  # pylint: disable=comparison-with-itself
  
      return img
  
imports: from __future__ import annotations
  from enum import Enum
  from itertools import product
  from math import ceil
  from typing import Sequence
  import torch
  import torchvision.transforms
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 5 for calling the Tiler obj's underlying member method code with example usage: obj.__fold(tiles) and returns: img