class_docstr: Implements Swin Transformer from the `"Swin Transformer: Hierarchical Vision Transformer using
  Shifted Windows" <https://arxiv.org/pdf/2103.14030>`_ paper.
  
  The code is adapted from `"Torchvision repository" <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
class_docstr_tok: ["Implements","Swin","Transformer","from","the","`","``","Swin","Transformer",":","Hierarchical","Vision","Transformer","using","Shifted","Windows","''","<","https",":","\/\/arxiv.org\/pdf\/2103.14030",">","`","_","paper",".","The","code","is","adapted","from","`","``","Torchvision","repository","''","<","https",":","\/\/github.com\/pytorch\/vision\/blob\/main\/torchvision\/models\/swin_transformer.py",">","`","_"]
code: def extract_end_points_all(
      self,
      x: Tensor,
      use_l5: Optional[bool] = True,
      use_l5_exp: Optional[bool] = False,
      *args,
      **kwargs,
  ) -> Dict[str, Tensor]:
      # First conv layer in SwinTransformer down samples by a factor of 4, so we modify the end-point extraction
      # function, so that the model is compatible with down-stream heads (e.g., Mask-RCNN)
  
      out_dict = (
          {}
      )  # Use dictionary over NamedTuple so that JIT is happy
  
      if self.training and self.neural_augmentor is not None:
          x = self.neural_augmentor(x)
          out_dict["augmented_tensor"] = x
  
      # [N, C, H, W] --> [N, H/4, W/4, C]
      x = self.conv_1(x)
  
      # first layer down-samples by 4, so L1 and l2 should be identity
      if self.extract_end_point_nchw_format:
          x_nchw = torch.permute(x, dims=(0, 3, 1, 2))
          out_dict["out_l1"] = x_nchw
          out_dict["out_l2"] = x_nchw
      else:
          out_dict["out_l1"] = x
          out_dict["out_l2"] = x
  
      # [N, H/4, W/4, C] --> [N, H/8, W/8, C]
      x = self.layer_1(x)
      out_dict["out_l3"] = (
          torch.permute(x, dims=(0, 3, 1, 2))
          if self.extract_end_point_nchw_format
          else x
      )
  
      # [N, H/8, W/8, C] --> [N, H/16, W/16, C]
      x = self.layer_2(x)
      out_dict["out_l4"] = (
          torch.permute(x, dims=(0, 3, 1, 2))
          if self.extract_end_point_nchw_format
          else x
      )
  
      if use_l5:
          # [N, H/16, W/16, C] --> [N, H/32, W/32, C]
          x = self.layer_3(x)
          x = self.layer_4(x)
          # [N, H/32, W/32, C] --> [N, C, H/32, W/32]
          x = self.layer_5(x)
          out_dict["out_l5"] = (
              x
              if self.extract_end_point_nchw_format
              else torch.permute(x, dims=(0, 2, 3, 1))
          )
  
          if use_l5_exp:
              x = self.conv_1x1_exp(x)
              out_dict["out_l5_exp"] = x
      return out_dict
  
file_path: ml-cvnets/cvnets/models/classification/swin_transformer.py
imports: import argparse
  from typing import Dict, List, Optional
  import torch
  from torch import Tensor, nn
  from cvnets.layers import ConvLayer2d, Dropout, GlobalPool, Identity, LinearLayer, get_normalization_layer
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.classification.config.swin_transformer import get_configuration
  from cvnets.modules import PatchMerging, Permute, SwinTransformerBlock
  from utils import logger
label_desc: Use image node_id 2 for calling the SwinTransformer obj's underlying member method code with example usage: obj.extract_end_points_all(x, use_l5, use_l5_exp) and returns: out_dict