Views
No views yet
1import requests
2from PIL import Image
3from transformers import BlipProcessor, BlipForConditionalGeneration
4
5processor = BlipProcessor.from_pretrained("unography/blip-long-cap")
6model = BlipForConditionalGeneration.from_pretrained("unography/blip-long-cap")
7
8img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
9raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
10
11inputs = processor(raw_image, return_tensors="pt")
12pixel_values = inputs.pixel_values
13out = model.generate(pixel_values=pixel_values, max_length=250, num_beams=3, repetition_penalty=2.5)
14print(processor.decode(out[0], skip_special_tokens=True))
15>>> a woman sitting on the sand, interacting with a dog wearing a blue and white checkered collar. the dog is positioned to the left of the woman, who is holding something in their hand. the background features a serene beach setting with waves crashing onto the shore. there are no other animals or people visible in the image. the time of day appears to be either early morning or late afternoon, based on the lighting and shadows.
161import requests
2from PIL import Image
3from transformers import BlipProcessor, BlipForConditionalGeneration
4
5processor = BlipProcessor.from_pretrained("unography/blip-long-cap")
6model = BlipForConditionalGeneration.from_pretrained("unography/blip-long-cap").to("cuda")
7
8img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
9raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
10
11inputs = processor(raw_image, return_tensors="pt").to("cuda")
12pixel_values = inputs.pixel_values
13out = model.generate(pixel_values=pixel_values, max_length=250, num_beams=3, repetition_penalty=2.5)
14print(processor.decode(out[0], skip_special_tokens=True))
15>>> a woman sitting on the sand, interacting with a dog wearing a blue and white checkered collar. the dog is positioned to the left of the woman, who is holding something in their hand. the background features a serene beach setting with waves crashing onto the shore. there are no other animals or people visible in the image. the time of day appears to be either early morning or late afternoon, based on the lighting and shadows.float16)1import torch
2import requests
3from PIL import Image
4from transformers import BlipProcessor, BlipForConditionalGeneration
5
6processor = BlipProcessor.from_pretrained("unography/blip-long-cap")
7model = BlipForConditionalGeneration.from_pretrained("unography/blip-long-cap", torch_dtype=torch.float16).to("cuda")
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
12inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
13pixel_values = inputs.pixel_values
14out = model.generate(pixel_values=pixel_values, max_length=250, num_beams=3, repetition_penalty=2.5)
15print(processor.decode(out[0], skip_special_tokens=True))
16>>> a woman sitting on the sand, interacting with a dog wearing a blue and white checkered collar. the dog is positioned to the left of the woman, who is holding something in their hand. the background features a serene beach setting with waves crashing onto the shore. there are no other animals or people visible in the image. the time of day appears to be either early morning or late afternoon, based on the lighting and shadows.