# Embedding from BLIP2

**URL:** <https://discuss.huggingface.co/t/embedding-from-blip2/43972>\
**Category:** Models\
**Created:** [June 20, 2023, 7:08pm UTC](https://discuss.huggingface.co/t/embedding-from-blip2/43972 "2023-06-20T19:08:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiva2022](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@shiva2022](https://discuss.huggingface.co/u/shiva2022)\
**Post date:** [June 20, 2023, 7:08pm UTC](https://discuss.huggingface.co/t/embedding-from-blip2/43972/1 "2023-06-20T19:08:19Z")

</div>

Looking for a code sample to get Embedding from BLIP2 model.

import torch  
from PIL import Image  
import requests  
from transformers import AutoProcessor, Blip2Model

device = “cuda” if torch.cuda.is\_available() else “cpu”

model = Blip2Model.from\_pretrained(“Salesforce/blip2-opt-2.7b”, torch\_dtype=torch.float16)

model.to(device)  
processor = AutoProcessor.from\_pretrained(“Salesforce/blip2-opt-2.7b”)  
url = “[http://images.cocodataset.org/val2017/000000039769.jpg](http://images.cocodataset.org/val2017/000000039769.jpg)”  
image = Image.open(requests.get(url, stream=True).raw)  
inputs = processor(images=image, return\_tensors=“pt”).to(device, torch.float16)  
image\_outputs = model.get\_image\_features(\*\*inputs)  
image\_outputs.pooler\_output.cpu().tolist()[0]

==========================================  
Does the above look right? What is the size of embedding expected.  
Any help of how to get similar embedding size for BLIP2 Text?
