code: def __init__(
      self,
      *,
      dim=(64, 128, 256, 512),
      depth=(2, 2, 8, 2),
      global_window_size=(8, 4, 2, 1),
      local_window_size=7,
      cross_embed_kernel_sizes=((4, 8, 16, 32), (2, 4), (2, 4), (2, 4)),
      cross_embed_strides=(4, 2, 2, 2),
      num_classes=1000,
      attn_dropout=0.0,
      ff_dropout=0.0,
      channels=3,
  ):
      super().__init__()
  
      dim = cast_tuple(dim, 4)
      depth = cast_tuple(depth, 4)
      global_window_size = cast_tuple(global_window_size, 4)
      local_window_size = cast_tuple(local_window_size, 4)
      cross_embed_kernel_sizes = cast_tuple(cross_embed_kernel_sizes, 4)
      cross_embed_strides = cast_tuple(cross_embed_strides, 4)
  
      assert len(dim) == 4
      assert len(depth) == 4
      assert len(global_window_size) == 4
      assert len(local_window_size) == 4
      assert len(cross_embed_kernel_sizes) == 4
      assert len(cross_embed_strides) == 4
  
      # dimensions
  
      last_dim = dim[-1]
      dims = [channels, *dim]
      dim_in_and_out = tuple(zip(dims[:-1], dims[1:]))
  
      # layers
  
      self.layers = nn.ModuleList([])
  
      for (
          (dim_in, dim_out),
          layers,
          global_wsz,
          local_wsz,
          cel_kernel_sizes,
          cel_stride,
      ) in zip(
          dim_in_and_out,
          depth,
          global_window_size,
          local_window_size,
          cross_embed_kernel_sizes,
          cross_embed_strides,
      ):
          self.layers.append(
              nn.ModuleList(
                  [
                      CrossEmbedLayer(
                          dim_in,
                          dim_out,
                          cel_kernel_sizes,
                          stride=cel_stride,
                      ),
                      Transformer(
                          dim_out,
                          local_window_size=local_wsz,
                          global_window_size=global_wsz,
                          depth=layers,
                          attn_dropout=attn_dropout,
                          ff_dropout=ff_dropout,
                      ),
                  ]
              )
          )
  
      # final logits
  
      self.to_logits = nn.Sequential(
          Reduce("b c h w -> b c", "mean"),
          nn.Linear(last_dim, num_classes),
      )
  
imports: import torch
  from torch import nn, einsum
  from einops import rearrange
  from einops.layers.torch import Rearrange, Reduce
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new CrossFormer object from inherited base classes: nn with example: obj = CrossFormer()