MCPcopy Create free account
hub / github.com/feast-dev/feast / _embed_image

Method _embed_image

sdk/python/feast/embedder.py:208–241  ·  view source on GitHub ↗
(self, inputs: List[Any])

Source from the content-addressed store, hash-verified

206 return self._image_processor
207
208 def _embed_image(self, inputs: List[Any]) -> "np.ndarray":
209 from pathlib import Path
210
211 import numpy as np
212 from PIL import Image
213
214 all_embeddings: List["np.ndarray"] = []
215 batch_size = self.config.batch_size
216
217 for start in range(0, len(inputs), batch_size):
218 batch = inputs[start : start + batch_size]
219 images = []
220 opened: List[Image.Image] = []
221 try:
222 for inp in batch:
223 if isinstance(
224 inp, (str, Path)
225 ): # If the input string path is too large that It gives error and we could not open the image.
226 img = Image.open(inp)
227 opened.append(img)
228 images.append(img)
229 else:
230 images.append(inp)
231
232 processed = self.image_processor(images=images, return_tensors="pt")
233 finally:
234 for opened_img in opened:
235 opened_img.close()
236
237 embeddings = self.image_model.get_image_features(**processed)
238 embeddings = embeddings / embeddings.norm(p=2, dim=-1, keepdim=True)
239 all_embeddings.append(embeddings.detach().numpy())
240
241 return np.concatenate(all_embeddings, axis=0)

Callers

nothing calls this directly

Calls 2

image_processorMethod · 0.95
closeMethod · 0.45

Tested by

no test coverage detected