(self, text)
| 56 | self.device = torch.device("cuda") |
| 57 | |
| 58 | def encode_text(self, text): |
| 59 | text = self.tokenizer([text] + self.canon).to(self.device) |
| 60 | with torch.no_grad(): |
| 61 | text_features = self.clip_pretrained.encode_text(text).type(torch.float32) |
| 62 | text_features = (text_features / text_features.norm(dim=-1, keepdim=True)).to(self.device) |
| 63 | self.text_feature = text_features |
| 64 | # return text_features |
| 65 | |
| 66 | def compute_similarity(self, semantic_feature): |
| 67 | logit = semantic_feature @ self.text_feature.T |