Create test
Browse files
test
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from transformers import BlipProcessor, BlipForQuestionAnswering
|
| 4 |
+
|
| 5 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-capfilt-large")
|
| 6 |
+
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-capfilt-large").to("cuda")
|
| 7 |
+
|
| 8 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
| 9 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
| 10 |
+
|
| 11 |
+
question = "how many dogs are in the picture?"
|
| 12 |
+
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
|
| 13 |
+
|
| 14 |
+
out = model.generate(**inputs)
|
| 15 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
| 16 |
+
>>> 1
|