(self, text)
| 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) |
| 27 | text_features = self.clip_model.get_text_features(**inputs) |
| 28 | text_features = text_features / text_features.norm(dim=-1, keepdim=True) # normalize features |
| 29 | return text_features |
| 30 | |
| 31 | def sample_images(folder, num_images): |
| 32 | all_images = [f for f in os.listdir(folder) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] |