MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / __init__

Method __init__

vtp/models/layers/embeddings.py:30–59  ·  view source on GitHub ↗
(
        self,
        img_size: Union[int, Tuple[int, int]] = 224,
        patch_size: Union[int, Tuple[int, int]] = 16,
        in_chans: int = 3,
        embed_dim: int = 768,
        norm_layer: Optional[Callable] = None,
        flatten_embedding: bool = True,
    )

Source from the content-addressed store, hash-verified

28 """
29
30 def __init__(
31 self,
32 img_size: Union[int, Tuple[int, int]] = 224,
33 patch_size: Union[int, Tuple[int, int]] = 16,
34 in_chans: int = 3,
35 embed_dim: int = 768,
36 norm_layer: Optional[Callable] = None,
37 flatten_embedding: bool = True,
38 ) -> None:
39 super().__init__()
40
41 image_HW = make_2tuple(img_size)
42 patch_HW = make_2tuple(patch_size)
43 patch_grid_size = (
44 image_HW[0] // patch_HW[0],
45 image_HW[1] // patch_HW[1],
46 )
47
48 self.img_size = image_HW
49 self.patch_size = patch_HW
50 self.patches_resolution = patch_grid_size
51 self.num_patches = patch_grid_size[0] * patch_grid_size[1]
52
53 self.in_chans = in_chans
54 self.embed_dim = embed_dim
55
56 self.flatten_embedding = flatten_embedding
57
58 self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_HW, stride=patch_HW)
59 self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity()
60
61 def forward(self, x: Tensor) -> Tensor:
62 _, _, H, W = x.shape

Callers 1

__init__Method · 0.45

Calls 1

make_2tupleFunction · 0.85

Tested by

no test coverage detected