MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / get_text_features

Method get_text_features

utils/clip_eval.py:35–44  ·  view source on GitHub ↗
(self, text: str, norm: bool = True)

Source from the content-addressed store, hash-verified

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)

Callers 1

txt_to_img_similarityMethod · 0.95

Calls 2

encode_textMethod · 0.95
tokenizeMethod · 0.80

Tested by

no test coverage detected