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
| 160 | |
| 161 | |
| 162 | class 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 | |
| 188 | class PatchMerging2D(nn.Module): |
no outgoing calls
no test coverage detected
searching dependent graphs…