nielsr HF staff commited on
Commit
2161edc
1 Parent(s): 91290e1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -0
README.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - vision
6
+ - image-captioning
7
+ ---
8
+
9
+ # InstructBLIP model
10
+
11
+ InstructBLIP model using Flan-T5-xl 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.
12
+
13
+ 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.
14
+
15
+ ## Model description
16
+
17
+ 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.
18
+
19
+ ![InstructBLIP architecture](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/instructblip_architecture.jpg)
20
+
21
+ ## Intended uses & limitations
22
+
23
+ Usage is as follows:
24
+
25
+ ```
26
+ from transformers import InstructBlipProcessor, InstructBlipForConditionalGeneration
27
+ import torch
28
+ from PIL import Image
29
+ import requests
30
+
31
+ model = InstructBlipForConditionalGeneration.from_pretrained("Salesforce/instructblip-flan-t5-xl")
32
+ processor = InstructBlipProcessor.from_pretrained("Salesforce/instructblip-flan-t5-xl")
33
+
34
+ device = "cuda" if torch.cuda.is_available() else "cpu"
35
+ model.to(device)
36
+
37
+ url = "https://raw.githubusercontent.com/salesforce/LAVIS/main/docs/_static/Confusing-Pictures.jpg"
38
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
39
+ prompt = "What is unusual about this image?"
40
+ inputs = processor(images=image, text=prompt, return_tensors="pt")
41
+
42
+ outputs = model.generate(
43
+ **inputs,
44
+ do_sample=False,
45
+ num_beams=1,
46
+ max_length=256,
47
+ min_length=1,
48
+ top_p=0.9,
49
+ repetition_penalty=1.5,
50
+ length_penalty=1.0,
51
+ temperature=1,
52
+ )
53
+ generated_text = processor.batch_decode(outputs, skip_special_tokens=True)[0].strip()
54
+ print(generated_text)
55
+ ```
56
+
57
+ Note that this shows unconditional generation of text given an image. You can also make the model continue a text prompt.
58
+
59
+ ### How to use
60
+
61
+ For code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/main/en/model_doc/instructblip).