Views
No views yet
1import requests
2from PIL import Image
3from transformers import BlipProcessor, BlipForConditionalGeneration
4
5processor = BlipProcessor.from_pretrained("unography/blip-large-long-cap")
6model = BlipForConditionalGeneration.from_pretrained("unography/blip-large-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)
14print(processor.decode(out[0], skip_special_tokens=True))
15>>> a woman sitting on the beach, wearing a checkered shirt and a dog collar. the woman is interacting with the dog, which is positioned towards the left side of the image. the setting is a beachfront with a calm sea and a golden hue.
161import requests
2from PIL import Image
3from transformers import BlipProcessor, BlipForConditionalGeneration
4
5processor = BlipProcessor.from_pretrained("unography/blip-large-long-cap")
6model = BlipForConditionalGeneration.from_pretrained("unography/blip-large-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)
14print(processor.decode(out[0], skip_special_tokens=True))
15>>> a woman sitting on the beach, wearing a checkered shirt and a dog collar. the woman is interacting with the dog, which is positioned towards the left side of the image. the setting is a beachfront with a calm sea and a golden hue.float16)1import torch
2import requests
3from PIL import Image
4from transformers import BlipProcessor, BlipForConditionalGeneration
5
6processor = BlipProcessor.from_pretrained("unography/blip-large-long-cap")
7model = BlipForConditionalGeneration.from_pretrained("unography/blip-large-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)
15print(processor.decode(out[0], skip_special_tokens=True))
16>>> a woman sitting on the beach, wearing a checkered shirt and a dog collar. the woman is interacting with the dog, which is positioned towards the left side of the image. the setting is a beachfront with a calm sea and a golden hue.