| 154 | """ |
| 155 | |
| 156 | def __init__(self, img_size=224, patch_size=7, stride=4, in_chans=3, embed_dim=768): |
| 157 | super().__init__() |
| 158 | img_size = to_2tuple(img_size) |
| 159 | patch_size = to_2tuple(patch_size) |
| 160 | |
| 161 | self.img_size = img_size |
| 162 | self.patch_size = patch_size |
| 163 | self.H, self.W = img_size[0] // patch_size[0], img_size[1] // patch_size[1] |
| 164 | self.num_patches = self.H * self.W |
| 165 | self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=stride, |
| 166 | padding=(patch_size[0] // 2, patch_size[1] // 2)) |
| 167 | self.norm = nn.LayerNorm(embed_dim) |
| 168 | |
| 169 | self.apply(self._init_weights) |
| 170 | |
| 171 | def _init_weights(self, m): |
| 172 | if isinstance(m, nn.Linear): |