Views
No views yet
main of transformers (at time of writing):pip install accelerate git+https://github.com/huggingface/transformers.git -U -qfp16 and int8 usage)1import requests
2from PIL import Image
3from transformers import BlipProcessor, Blip2ForConditionalGeneration
4
5model_name = "ethzanalytics/blip2-flan-t5-xl-sharded"
6processor = BlipProcessor.from_pretrained(model_name)
7model = Blip2ForConditionalGeneration.from_pretrained(model_name)
8
9img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
10raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
11
12question = "how many dogs are in the picture?"
13inputs = processor(raw_image, question, return_tensors="pt")
14
15out = model.generate(**inputs)
16print(processor.decode(out[0], skip_special_tokens=True))