MCPcopy Create free account
hub / github.com/Agent-RL/ReCall / encode_image

Method encode_image

src/flashrag/retriever/encoder.py:210–224  ·  view source on GitHub ↗
(self, image_list: List)

Source from the content-addressed store, hash-verified

208
209 @torch.inference_mode()
210 def encode_image(self, image_list: List) -> np.ndarray:
211 # Each item in image_list: PIL Image, local path, or URL
212 if self.model_type == "CLIPModel" or self.model_type == 'ChineseCLIPModel':
213 # need handle image
214 image_list = [parse_image(image) for image in image_list]
215 inputs = self.processor(images=image_list, return_tensors="pt")
216 inputs = {k: v.cuda() for k, v in inputs.items()}
217 image_emb = self.model.get_image_features(**inputs)
218 image_emb = image_emb / image_emb.norm(p=2, dim=-1, keepdim=True)
219 image_emb = image_emb.detach().cpu().numpy().astype(np.float32)
220 elif self.model_type.endswith("CLIPModel"):
221 image_emb = self.model.encode_image(image_list)
222 else:
223 raise NotImplementedError(f"Unsupported model type: {self.model_type}")
224 return image_emb
225
226 @torch.inference_mode()
227 def encode_text(self, text_list: List[str]) -> np.ndarray:

Callers

nothing calls this directly

Calls 1

parse_imageFunction · 0.90

Tested by

no test coverage detected