Commit
·
b6d2ff6
1
Parent(s):
c186c67
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
| 1 |
---
|
| 2 |
pipeline_tag: image-to-text
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
pipeline_tag: image-to-text
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
## Usage:
|
| 6 |
+
```
|
| 7 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 8 |
+
import torch
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
processor = BlipProcessor.from_pretrained("prasanna2003/blip-image-captioning")
|
| 12 |
+
if processor.tokenizer.eos_token is None:
|
| 13 |
+
processor.tokenizer.eos_token = '<|eos|>'
|
| 14 |
+
model = BlipForConditionalGeneration.from_pretrained("prasanna2003/blip-image-captioning")
|
| 15 |
+
|
| 16 |
+
image = Image.open('file_name.jpg').convert('RGB')
|
| 17 |
+
|
| 18 |
+
prompt = """Instruction: Answer the following input according to the image.
|
| 19 |
+
output: """
|
| 20 |
+
|
| 21 |
+
inputs = processor(image, prompt, return_tensors="pt")
|
| 22 |
+
|
| 23 |
+
output = model.generate(**inputs, max_length=100)
|
| 24 |
+
print(tokenizer.decode(output[0]))
|
| 25 |
+
|
| 26 |
+
```
|