Spaces:
Running on Zero
Running on Zero
Download models/image_encoder.py from ashish-001/SnapSearch: direct link, hf CLI and curl.
- Browser
- Download file 583 Bytes
-
https://huggingface.co/spaces/ashish-001/SnapSearch/resolve/main/models/image_encoder.py
- Command line
-
hf download hf://spaces/ashish-001/SnapSearch/models/image_encoder.py
-
curl -L -o image_encoder.py https://huggingface.co/spaces/ashish-001/SnapSearch/resolve/main/models/image_encoder.py
583 Bytes
| import onnxruntime as ort | |
| from utils.config import IMAGE_ENCODER | |
| from utils.preprocessing import ImageProcess | |
| class ImageEncoder: | |
| def __init__(self): | |
| self.image_model = ort.InferenceSession(IMAGE_ENCODER) | |
| self.preprocess = ImageProcess() | |
| self.input_name = self.image_model.get_inputs()[0].name | |
| def get_image_embedding(self, path): | |
| image_tensor = self.preprocess.process(path) | |
| image_embeddings = self.image_model.run( | |
| None, {self.input_name: image_tensor})[0] | |
| return image_embeddings.squeeze(0) | |