| 477 | |
| 478 | |
| 479 | class MLPProj(torch.nn.Module): |
| 480 | |
| 481 | def __init__(self, in_dim, out_dim): |
| 482 | super().__init__() |
| 483 | |
| 484 | self.proj = torch.nn.Sequential( |
| 485 | torch.nn.LayerNorm(in_dim), torch.nn.Linear(in_dim, in_dim), |
| 486 | torch.nn.GELU(), torch.nn.Linear(in_dim, out_dim), |
| 487 | torch.nn.LayerNorm(out_dim)) |
| 488 | |
| 489 | def forward(self, image_embeds): |
| 490 | clip_extra_context_tokens = self.proj(image_embeds) |
| 491 | return clip_extra_context_tokens |
| 492 | |
| 493 | class PositionalEncoding(nn.Module): |
| 494 | def __init__(self, d_model, max_len=5000): |