class_docstr: SwinIR
      A PyTorch impl of : `SwinIR: Image Restoration Using Swin Transformer`, based on Swin Transformer.
  Args:
      img_size (int | tuple(int)): Input image size. Default 64
      patch_size (int | tuple(int)): Patch size. Default: 1
      in_chans (int): Number of input image channels. Default: 3
      embed_dim (int): Patch embedding dimension. Default: 96
      depths (tuple(int)): Depth of each Swin Transformer layer.
      num_heads (tuple(int)): Number of attention heads in different layers.
      window_size (int): Window size. Default: 7
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4
      qkv_bias (bool): If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float): Override default qk scale of head_dim ** -0.5 if set. Default: None
      drop_rate (float): Dropout rate. Default: 0
      attn_drop_rate (float): Attention dropout rate. Default: 0
      drop_path_rate (float): Stochastic depth rate. Default: 0.1
      norm_layer (nn.Layer): Normalization layer. Default: nn.LayerNorm.
      ape (bool): If True, add absolute position embedding to the patch embedding. Default: False
      patch_norm (bool): If True, add normalization after patch embedding. Default: True
      use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False
      upscale: Upscale factor. 2/3/4/8 for image SR, 1 for denoising and compress artifact reduction
      img_range: Image range. 1. or 255.
      upsampler: The reconstruction reconstruction module. 'pixelshuffle'/'pixelshuffledirect'/'nearest+conv'/None
      resi_connection: The convolutional block before residual connection. '1conv'/'3conv'
class_docstr_tok: ["SwinIR","A","PyTorch","impl","of",":","`","SwinIR",":","Image","Restoration","Using","Swin","Transformer","`",",","based","on","Swin","Transformer",".","Args",":","img_size","(","int","|","tuple","(","int",")",")",":","Input","image","size",".","Default","64","patch_size","(","int","|","tuple","(","int",")",")",":","Patch","size",".","Default",":","1","in_chans","(","int",")",":","Number","of","input","image","channels",".","Default",":","3","embed_dim","(","int",")",":","Patch","embedding","dimension",".","Default",":","96","depths","(","tuple","(","int",")",")",":","Depth","of","each","Swin","Transformer","layer",".","num_heads","(","tuple","(","int",")",")",":","Number","of","attention","heads","in","different","layers",".","window_size","(","int",")",":","Window","size",".","Default",":","7","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4","qkv_bias","(","bool",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","Default",":","None","drop_rate","(","float",")",":","Dropout","rate",".","Default",":","0","attn_drop_rate","(","float",")",":","Attention","dropout","rate",".","Default",":","0","drop_path_rate","(","float",")",":","Stochastic","depth","rate",".","Default",":","0.1","norm_layer","(","nn.Layer",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","ape","(","bool",")",":","If","True",",","add","absolute","position","embedding","to","the","patch","embedding",".","Default",":","False","patch_norm","(","bool",")",":","If","True",",","add","normalization","after","patch","embedding",".","Default",":","True","use_checkpoint","(","bool",")",":","Whether","to","use","checkpointing","to","save","memory",".","Default",":","False","upscale",":","Upscale","factor",".","2\/3\/4\/8","for","image","SR",",","1","for","denoising","and","compress","artifact","reduction","img_range",":","Image","range",".","1.","or","255.","upsampler",":","The","reconstruction","reconstruction","module",".","'pixelshuffle'\/'pixelshuffledirect'\/'nearest+conv'\/None","resi_connection",":","The","convolutional","block","before","residual","connection",".","'1conv'\/'3conv","'"]
code: def forward(self, x):
      H, W = x.shape[2:]
      x = self.check_image_size(x)
  
      self.mean = self.mean.cast(x.dtype)
      x = (x - self.mean) * self.img_range
  
      if self.upsampler == "pixelshuffle":
          # for classical SR
          x = self.conv_first(x)
          x = self.conv_after_body(self.forward_features(x)) + x
          x = self.conv_before_upsample(x)
          x = self.conv_last(self.upsample(x))
      elif self.upsampler == "pixelshuffledirect":
          # for lightweight SR
          x = self.conv_first(x)
          x = self.conv_after_body(self.forward_features(x)) + x
          x = self.upsample(x)
      elif self.upsampler == "nearest+conv":
          # for real-world SR
          x = self.conv_first(x)
          x = self.conv_after_body(self.forward_features(x)) + x
          x = self.conv_before_upsample(x)
          x = self.lrelu(
              self.conv_up1(
                  nn.functional.interpolate(
                      x, scale_factor=2, mode="nearest"
                  )
              )
          )
          if self.upscale == 4:
              x = self.lrelu(
                  self.conv_up2(
                      nn.functional.interpolate(
                          x, scale_factor=2, mode="nearest"
                      )
                  )
              )
          x = self.conv_last(self.lrelu(self.conv_hr(x)))
      else:
          # for image denoising and JPEG compression artifact reduction
          x_first = self.conv_first(x)
          res = (
              self.conv_after_body(self.forward_features(x_first))
              + x_first
          )
          x = x + self.conv_last(res)
  
      x = x / self.img_range + self.mean
  
      return x[:, :, : H * self.upscale, : W * self.upscale]
  
imports: import math
  import paddle
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 5 for calling the SwinIR obj's underlying member method code with example usage: obj.forward(x) and returns: x