nielsr HF staff commited on
Commit
8ec352f
1 Parent(s): bd183b7

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +62 -0
README.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - vision
6
+ - image-captioning
7
+ pipeline_tag: image-to-text
8
+ ---
9
+
10
+ # InstructBLIP model
11
+
12
+ InstructBLIP model using [Flan-T5-xxl](https://huggingface.co/google/flan-t5-xxl) as language model. InstructBLIP was introduced in the paper [InstructBLIP: Towards General-purpose Vision-Language Models with Instruction Tuning](https://arxiv.org/abs/2305.06500) by Dai et al.
13
+
14
+ Disclaimer: The team releasing InstructBLIP did not write a model card for this model so this model card has been written by the Hugging Face team.
15
+
16
+ ## Model description
17
+
18
+ InstructBLIP is a visual instruction tuned version of [BLIP-2](https://huggingface.co/docs/transformers/main/model_doc/blip-2). Refer to the paper for details.
19
+
20
+ ![InstructBLIP architecture](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/instructblip_architecture.jpg)
21
+
22
+ ## Intended uses & limitations
23
+
24
+ Usage is as follows:
25
+
26
+ ```
27
+ from transformers import InstructBlipProcessor, InstructBlipForConditionalGeneration
28
+ import torch
29
+ from PIL import Image
30
+ import requests
31
+
32
+ model = InstructBlipForConditionalGeneration.from_pretrained("Salesforce/instructblip-flan-t5-xxl")
33
+ processor = InstructBlipProcessor.from_pretrained("Salesforce/instructblip-flan-t5-xxl")
34
+
35
+ device = "cuda" if torch.cuda.is_available() else "cpu"
36
+ model.to(device)
37
+
38
+ url = "https://raw.githubusercontent.com/salesforce/LAVIS/main/docs/_static/Confusing-Pictures.jpg"
39
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
40
+ prompt = "What is unusual about this image?"
41
+ inputs = processor(images=image, text=prompt, return_tensors="pt")
42
+
43
+ outputs = model.generate(
44
+ **inputs,
45
+ do_sample=False,
46
+ num_beams=1,
47
+ max_length=256,
48
+ min_length=1,
49
+ top_p=0.9,
50
+ repetition_penalty=1.5,
51
+ length_penalty=1.0,
52
+ temperature=1,
53
+ )
54
+ generated_text = processor.batch_decode(outputs, skip_special_tokens=True)[0].strip()
55
+ print(generated_text)
56
+ ```
57
+
58
+ Note that this shows unconditional generation of text given an image. You can also make the model continue a text prompt.
59
+
60
+ ### How to use
61
+
62
+ For code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/main/en/model_doc/instructblip).