(self, image)
| 17 | self.processor = CLIPProcessor.from_pretrained(model_name) |
| 18 | |
| 19 | def encode_image(self, image): |
| 20 | pixel_values = self.processor(images=image, return_tensors="pt").pixel_values.to(self.device) |
| 21 | image_features = self.clip_model.get_image_features(pixel_values=pixel_values) |
| 22 | image_features = image_features / image_features.norm(dim=-1, keepdim=True) # normalize features |
| 23 | return image_features |
| 24 | |
| 25 | def encode_text(self, text): |
| 26 | inputs = self.processor(text=[text], padding=True, return_tensors="pt").to(self.device) |
no test coverage detected