Salesforce / blip2-opt-2.7b

huggingface.co
Total runs: 302.7K
24-hour runs: 2.2K
7-day runs: 19.2K
30-day runs: 9.9K
Model's Last Updated: November 22 2024
image-text-to-text

Introduction of blip2-opt-2.7b

Model Details of blip2-opt-2.7b

BLIP-2, OPT-2.7b, pre-trained only

BLIP-2 model, leveraging OPT-2.7b (a large language model with 2.7 billion parameters). It was introduced in the paper BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models by Li et al. and first released in this repository .

Disclaimer: The team releasing BLIP-2 did not write a model card for this model so this model card has been written by the Hugging Face team.

Model description

BLIP-2 consists of 3 models: a CLIP-like image encoder, a Querying Transformer (Q-Former) and a large language model.

The authors initialize the weights of the image encoder and large language model from pre-trained checkpoints and keep them frozen while training the Querying Transformer, which is a BERT-like Transformer encoder that maps a set of "query tokens" to query embeddings, which bridge the gap between the embedding space of the image encoder and the large language model.

The goal for the model is simply to predict the next text token, giving the query embeddings and the previous text.

drawing

This allows the model to be used for tasks like:

  • image captioning
  • visual question answering (VQA)
  • chat-like conversations by feeding the image and the previous conversation as prompt to the model
Direct Use and Downstream Use

You can use the raw model for conditional text generation given an image and optional text. See the model hub to look for fine-tuned versions on a task that interests you.

Bias, Risks, Limitations, and Ethical Considerations

BLIP2-OPT uses off-the-shelf OPT as the language model. It inherits the same risks and limitations as mentioned in Meta's model card.

Like other large language models for which the diversity (or lack thereof) of training data induces downstream impact on the quality of our model, OPT-175B has limitations in terms of bias and safety. OPT-175B can also have quality issues in terms of generation diversity and hallucination. In general, OPT-175B is not immune from the plethora of issues that plague modern large language models.

BLIP2 is fine-tuned on image-text datasets (e.g. LAION ) collected from the internet. As a result the model itself is potentially vulnerable to generating equivalently inappropriate content or replicating inherent biases in the underlying data.

BLIP2 has not been tested in real world applications. It should not be directly deployed in any applications. Researchers should first carefully assess the safety and fairness of the model in relation to the specific context they’re being deployed within.

How to use

For code examples, we refer to the documentation .

Memory requirements

The memory requirements differ based on the precision one uses. One can use 4-bit inference using Bitsandbytes , which greatly reduce the memory requirements.

dtype Largest Layer or Residual Group Total Size Training using Adam
float32 490.94 MB 14.43 GB 57.72 GB
float16/bfloat16 245.47 MB 7.21 GB 28.86 GB
int8 122.73 MB 3.61 GB 14.43 GB
int4 61.37 MB 1.8 GB 7.21 GB
Running the model on CPU
Click to expand
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration

processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b")

img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' 
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')

question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt")

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True).strip())
Running the model on GPU
In full precision
Click to expand
# pip install accelerate
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration

processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", device_map="auto")

img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' 
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')

question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True).strip())
In half precision ( float16 )
Click to expand
# pip install accelerate
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration

processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")

img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' 
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')

question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True).strip())
In 8-bit precision ( int8 )
Click to expand
# pip install accelerate bitsandbytes
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration

processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", load_in_8bit=True, device_map="auto")

img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' 
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')

question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True).strip())

Runs of Salesforce blip2-opt-2.7b on huggingface.co

302.7K
Total runs
2.2K
24-hour runs
8.0K
3-day runs
19.2K
7-day runs
9.9K
30-day runs

More Information About blip2-opt-2.7b huggingface.co Model

More blip2-opt-2.7b license Visit here:

https://choosealicense.com/licenses/mit

blip2-opt-2.7b huggingface.co

blip2-opt-2.7b huggingface.co is an AI model on huggingface.co that provides blip2-opt-2.7b's model effect (), which can be used instantly with this Salesforce blip2-opt-2.7b model. huggingface.co supports a free trial of the blip2-opt-2.7b model, and also provides paid use of the blip2-opt-2.7b. Support call blip2-opt-2.7b model through api, including Node.js, Python, http.

Salesforce blip2-opt-2.7b online free

blip2-opt-2.7b huggingface.co is an online trial and call api platform, which integrates blip2-opt-2.7b's modeling effects, including api services, and provides a free online trial of blip2-opt-2.7b, you can try blip2-opt-2.7b online for free by clicking the link below.

Salesforce blip2-opt-2.7b online free url in huggingface.co:

https://huggingface.co/Salesforce/blip2-opt-2.7b

blip2-opt-2.7b install

blip2-opt-2.7b is an open source model from GitHub that offers a free installation service, and any user can find blip2-opt-2.7b on GitHub to install. At the same time, huggingface.co provides the effect of blip2-opt-2.7b install, users can directly use blip2-opt-2.7b installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

blip2-opt-2.7b install url in huggingface.co:

https://huggingface.co/Salesforce/blip2-opt-2.7b

Url of blip2-opt-2.7b

blip2-opt-2.7b huggingface.co Url

Provider of blip2-opt-2.7b huggingface.co

Salesforce
ORGANIZATIONS

Other API from Salesforce

huggingface.co

Total runs: 37.7K
Run Growth: -12.8K
Growth Rate: -31.59%
Updated: January 21 2025
huggingface.co

Total runs: 8.7K
Run Growth: 1.7K
Growth Rate: 19.98%
Updated: February 19 2024
huggingface.co

Total runs: 2.8K
Run Growth: 907
Growth Rate: 27.16%
Updated: January 25 2025
huggingface.co

Total runs: 672
Run Growth: 519
Growth Rate: 88.27%
Updated: January 21 2025
huggingface.co

Total runs: 563
Run Growth: 206
Growth Rate: 37.66%
Updated: January 21 2025
huggingface.co

Total runs: 290
Run Growth: 1
Growth Rate: 0.34%
Updated: January 15 2025
huggingface.co

Total runs: 49
Run Growth: -54
Growth Rate: -108.00%
Updated: January 15 2025