MCPcopy Create free account
hub / github.com/TPCD/DCCL / PatchEmbed

Class PatchEmbed

model/vision_transformer.py:117–132  ·  view source on GitHub ↗

Image to Patch Embedding

Source from the content-addressed store, hash-verified

115
116
117class PatchEmbed(nn.Module):
118 """ Image to Patch Embedding
119 """
120 def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768):
121 super().__init__()
122 num_patches = (img_size // patch_size) * (img_size // patch_size)
123 self.img_size = img_size
124 self.patch_size = patch_size
125 self.num_patches = num_patches
126
127 self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
128
129 def forward(self, x):
130 B, C, H, W = x.shape
131 x = self.proj(x).flatten(2).transpose(1, 2)
132 return x
133
134
135class VisionTransformer(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected