class_docstr: Encoder based on SwinTransformer
  Set the initial weights and configuration with a pretrained SwinTransformer and then
  modify the detailed configurations
  
  Args:
      input_size: Input image size (width, height)
      align_long_axis: Whether to rotate image if height is greater than width
      window_size: Window size(=patch size) of SwinTransformer
      encoder_layer: Number of layers of SwinTransformer encoder
      name_or_path: Name of a pretrained model name either registered in huggingface.co. or saved in local.
                    otherwise, `swin_base_patch4_window12_384` will be set (using `timm`).
class_docstr_tok: ["Encoder","based","on","SwinTransformer","Set","the","initial","weights","and","configuration","with","a","pretrained","SwinTransformer","and","then","modify","the","detailed","configurations","Args",":","input_size",":","Input","image","size","(","width",",","height",")","align_long_axis",":","Whether","to","rotate","image","if","height","is","greater","than","width","window_size",":","Window","size","(","=patch","size",")","of","SwinTransformer","encoder_layer",":","Number","of","layers","of","SwinTransformer","encoder","name_or_path",":","Name","of","a","pretrained","model","name","either","registered","in","huggingface.co",".","or","saved","in","local",".","otherwise",",","`","swin_base_patch4_window12_384","`","will","be","set","(","using","`","timm","`",")","."]
docstr: Convert PIL Image to tensor according to specified input_size after following steps below:
      - resize
      - rotate (if align_long_axis is True and image is not aligned longer axis with canvas)
      - pad
code: def prepare_input(
      self, img: Image.Image, random_padding: bool = False
  ) -> torch.Tensor:
      """
      Convert PIL Image to tensor according to specified input_size after following steps below:
          - resize
          - rotate (if align_long_axis is True and image is not aligned longer axis with canvas)
          - pad
      """
      if img is None:
          return
      # crop margins
      try:
          img = self.crop_margin(img.convert("RGB"))
      except OSError:
          # might throw an error for broken files
          return
      if img.height == 0 or img.width == 0:
          return
      if self.align_long_axis and (
          (
              self.input_size[0] > self.input_size[1]
              and img.width > img.height
          )
          or (
              self.input_size[0] < self.input_size[1]
              and img.width < img.height
          )
      ):
          img = rotate(img, angle=-90, expand=True)
      img = resize(img, min(self.input_size))
      img.thumbnail((self.input_size[1], self.input_size[0]))
      delta_width = self.input_size[1] - img.width
      delta_height = self.input_size[0] - img.height
      if random_padding:
          pad_width = np.random.randint(low=0, high=delta_width + 1)
          pad_height = np.random.randint(low=0, high=delta_height + 1)
      else:
          pad_width = delta_width // 2
          pad_height = delta_height // 2
      padding = (
          pad_width,
          pad_height,
          delta_width - pad_width,
          delta_height - pad_height,
      )
      return self.to_tensor(ImageOps.expand(img, padding))
  
imports: import logging
  import math
  import os
  from typing import List, Optional, Union
  from collections import defaultdict
  from pathlib import Path
  import numpy
  from PIL import Image
  import cv2
  import timm
  import torch
  import torch.nn
  import torch.nn.functional
  from PIL import ImageOps
  from timm.models.swin_transformer import SwinTransformer
  from torchvision.transforms.functional import resize, rotate
  from transformers import PreTrainedTokenizerFast, StoppingCriteria, StoppingCriteriaList, MBartConfig, MBartForCausalLM
  from transformers.file_utils import ModelOutput
  from transformers.modeling_utils import PretrainedConfig, PreTrainedModel
  from nougat.postprocessing import postprocess
  from nougat.transforms import train_transform, test_transform
label_desc: Use image node_id 5 for calling the SwinEncoder obj's underlying member method code with example usage: obj.prepare_input(img, random_padding) and returns: self