Views
No views yet
validate folder together with README.md and captions.txt.1import torch
2import requests
3from PIL import Image
4from transformers import Blip2Processor, Blip2ForConditionalGeneration
5processor = Blip2Processor.from_pretrained("anonymoussubmission2024/vlrm-blip2-opt-2.7b")
6model = Blip2ForConditionalGeneration.from_pretrained("anonymoussubmission2024/vlrm-blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")
7img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
8raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
9inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
10out = model.generate(**inputs, max_new_tokens=60)
11processor.decode(out[0], skip_special_tokens=True).strip()
12>>> 'a woman in a plaid shirt shaking hands with a yellow labrador retriever sitting on the ground at sunset on a beach in florida'1import torch
2import requests
3from PIL import Image
4from transformers import Blip2Processor, Blip2ForConditionalGeneration
5processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
6model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")
7img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
8raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
9inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
10out = model.generate(**inputs, max_new_tokens=60)
11processor.decode(out[0], skip_special_tokens=True).strip()
12>>> 'a woman sitting on the beach with a dog'vlrm-blip2-opt-2.7b.pt (VLRM in the paper)vlrm-rs-blip2-opt-2.7b.pt (VLRM-RS in the paper)1from huggingface_hub import hf_hub_download
2finetuned_weights_state_dict = torch.load(hf_hub_download(repo_id="anonymoussubmission2024/vlrm-blip2-opt-2.7b", filename="vlrm-blip2-opt-2.7b.pt"))
3model.load_state_dict(finetuned_weights_state_dict, strict=False)
4out = model.generate(**inputs, max_new_tokens=60)
5processor.decode(out[0], skip_special_tokens=True).strip()
6>>> 'a woman in a plaid shirt shaking hands with a yellow labrador retriever sitting on the ground at sunset on a beach in florida'