MCPcopy Create free account
hub / github.com/lingeringlight/START / PatchEmbed2D

Class PatchEmbed2D

models/vmamba.py:162–185  ·  view source on GitHub ↗

r""" Image to Patch Embedding Args: patch_size (int): Patch token size. Default: 4. in_chans (int): Number of input image channels. Default: 3. embed_dim (int): Number of linear projection output channels. Default: 96. norm_layer (nn.Module, optional): Normalizati

Source from the content-addressed store, hash-verified

160
161
162class PatchEmbed2D(nn.Module):
163 r""" Image to Patch Embedding
164 Args:
165 patch_size (int): Patch token size. Default: 4.
166 in_chans (int): Number of input image channels. Default: 3.
167 embed_dim (int): Number of linear projection output channels. Default: 96.
168 norm_layer (nn.Module, optional): Normalization layer. Default: None
169 """
170
171 def __init__(self, patch_size=4, in_chans=3, embed_dim=96, norm_layer=None, **kwargs):
172 super().__init__()
173 if isinstance(patch_size, int):
174 patch_size = (patch_size, patch_size)
175 self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
176 if norm_layer is not None:
177 self.norm = norm_layer(embed_dim)
178 else:
179 self.norm = None
180
181 def forward(self, x):
182 x = self.proj(x).permute(0, 2, 3, 1)
183 if self.norm is not None:
184 x = self.norm(x)
185 return x
186
187
188class PatchMerging2D(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…