(self, text, token=None, device=None)
| 70 | ) |
| 71 | |
| 72 | def forward(self, text, token=None, device=None): |
| 73 | with torch.no_grad(): |
| 74 | text = clip.tokenize(text, truncate=True).to(device) |
| 75 | x = self.clip.token_embedding(text).type(self.clip.dtype) |
| 76 | |
| 77 | x = x + self.clip.positional_embedding.type(self.clip.dtype) |
| 78 | x = x.permute(1, 0, 2) |
| 79 | x = self.clip.transformer(x) |
| 80 | x = self.clip.ln_final(x).type(self.clip.dtype) |
| 81 | |
| 82 | x = self.text_pre_proj(x) |
| 83 | xf_out = self.textTransEncoder(x) |
| 84 | xf_out = self.text_ln(xf_out) |
| 85 | if self.use_text_proj: |
| 86 | xf_proj = self.text_proj(xf_out[text.argmax(dim=-1), torch.arange(xf_out.shape[1])]) |
| 87 | return xf_proj |
| 88 | else: |
| 89 | xf_out = xf_out.permute(1, 0, 2) |
| 90 | return xf_out |
| 91 | |
| 92 | def load_pretrained(self, ckpt_path): |
| 93 | checkpoint = torch.load(ckpt_path, map_location='cpu') |
nothing calls this directly
no outgoing calls
no test coverage detected