Run this model with HF Jobs
Run radames/blip_image_embeddings on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/radames/blip_image_embeddings. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/radames/blip_image_embeddings on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use radames/blip_image_embeddings with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use radames/blip_image_embeddings with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="radames/blip_image_embeddings")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("radames/blip_image_embeddings", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update pipeline.py
Browse files12346 unmodified lines11121314151617181920212223242526272829303132333435363738393 unmodified lines4344454647484950515253from typing import Dict, List, Anyfrom PIL import Imageimport requestsimport torch6 unmodified linesdevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')class PreTrainedPipeline():def __init__(self, path=""):# load the optimized modelself.model_path = os.path.join(path,'model_large_retrieval_coco.pth')self.model = blip_feature_extractor(pretrained=self.model_path,image_size=384,vit='large',med_config=os.path.join(path, 'configs/med_config.json'))self.model.eval()self.model = self.model.to(device)image_size = 384self.transform = transforms.Compose([transforms.Resize((image_size,image_size),interpolation=InterpolationMode.BICUBIC),transforms.ToTensor(),transforms.Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711))])def __call__(self, inputs: str) -> List[float]:"""Args:data (:obj:):3 unmodified lines- "feature_vector": A list of floats corresponding to the image embedding."""parameters = {"mode": "image"}# decode base64 image to PILimage = Image.open(BytesIO(base64.b64decode(inputs))).convert("RGB")image = self.transform(image).unsqueeze(0).to(device)text=""with torch.no_grad():feature_vector = self.model(image, text, mode=parameters["mode"])[0,0].tolist()# postprocess the predictionreturn feature_vector12346 unmodified lines1112131415161718192021222324252627282930313233343536373839403 unmodified lines444546474849505152535455565758596061from typing import Dict, List, Any, Unionfrom PIL import Imageimport requestsimport torch6 unmodified linesdevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')class PreTrainedPipeline():def __init__(self, path=""):# load the optimized modelself.model_path = os.path.join(path, 'model_large_retrieval_coco.pth')self.model = blip_feature_extractor(pretrained=self.model_path,image_size=384,vit='large',med_config=os.path.join(path, 'configs/med_config.json'))self.model.eval()self.model = self.model.to(device)image_size = 384self.transform = transforms.Compose([transforms.Resize((image_size, image_size),interpolation=InterpolationMode.BICUBIC),transforms.ToTensor(),transforms.Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711))])def __call__(self, inputs: Union[str, "Image.Image"]) -> List[float]:"""Args:data (:obj:):3 unmodified lines- "feature_vector": A list of floats corresponding to the image embedding."""parameters = {"mode": "image"}if isinstance(inputs, str):# decode base64 image to PILimage = Image.open(BytesIO(base64.b64decode(inputs))).convert("RGB")elif isinstance(inputs, Image.Image):image = inputs.convert("RGB")image = self.transform(image).unsqueeze(0).to(device)text = ""with torch.no_grad():feature_vector = self.model(image, text, mode=parameters["mode"])[0, 0].tolist()# postprocess the predictionreturn feature_vector
pipeline.py+24-16