(self, text: str, norm: bool = True)
| 33 | return self.model.encode_image(images) |
| 34 | |
| 35 | def get_text_features(self, text: str, norm: bool = True) -> torch.Tensor: |
| 36 | |
| 37 | tokens = clip.tokenize(text).to(self.device) |
| 38 | |
| 39 | text_features = self.encode_text(tokens).detach() |
| 40 | |
| 41 | if norm: |
| 42 | text_features /= text_features.norm(dim=-1, keepdim=True) |
| 43 | |
| 44 | return text_features |
| 45 | |
| 46 | def get_image_features(self, img: torch.Tensor, norm: bool = True) -> torch.Tensor: |
| 47 | image_features = self.encode_images(img) |
no test coverage detected