(self, x: torch.Tensor)
| 390 | self.proj = nn.Parameter((output_dim** -0.5) * torch.randn(output_dim, output_dim)) |
| 391 | |
| 392 | def forward(self, x: torch.Tensor): |
| 393 | x = x.to( |
| 394 | dtype=self.transformer.get_cast_dtype(), |
| 395 | device=self.transformer.get_cast_device(), |
| 396 | ) |
| 397 | # to patches |
| 398 | x = self.conv1(x) # shape = [*, width, grid, grid] |
| 399 | x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2] |
| 400 | x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width] |
| 401 | |
| 402 | x = x + get_abs_pos(self.positional_embedding, x.size(1)) |
| 403 | |
| 404 | x = self.ln_pre(x) |
| 405 | |
| 406 | x = x.permute(1, 0, 2) # NLD -> LND |
| 407 | x = self.transformer(x) |
| 408 | x = x.permute(1, 0, 2) # LND -> NLD |
| 409 | |
| 410 | x = self.attn_pool(x) |
| 411 | x = self.ln_post(x) |
| 412 | x = x @ self.proj |
| 413 | |
| 414 | return x |
| 415 | |
| 416 | def encode(self, image_paths: List[str]): |
| 417 | images = [] |
nothing calls this directly
no test coverage detected