(self, text, device)
| 104 | return text_features |
| 105 | |
| 106 | def encode_text(self, text, device): |
| 107 | with torch.no_grad(): |
| 108 | text = clip.tokenize(text, truncate=True).to(device) |
| 109 | x = self.clip.token_embedding(text).type(self.clip.dtype) |
| 110 | |
| 111 | x = x + self.clip.positional_embedding.type(self.clip.dtype) |
| 112 | x = x.permute(1, 0, 2) # NLD -> LND |
| 113 | x = self.clip.transformer(x) |
| 114 | x = self.clip.ln_final(x).type(self.clip.dtype) |
| 115 | |
| 116 | # B, T, D |
| 117 | xf_out = x.permute(1, 0, 2) |
| 118 | return xf_out |
| 119 | |
| 120 | def retrieve(self, caption, length, clip_model, device, idx=None): |
| 121 | value = hash(caption) |
no outgoing calls
no test coverage detected