Update README.md
This commit is contained in:
parent
af1d88b9ac
commit
25d2acb8e5
38
README.md
38
README.md
|
@ -32,11 +32,12 @@ You can use this model for conditional and un-conditional image captioning
|
||||||
<summary> Click to expand </summary>
|
<summary> Click to expand </summary>
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
import requests
|
||||||
|
from PIL import Image
|
||||||
|
from transformers import BlipProcessor, BlipForConditionalGeneration
|
||||||
|
|
||||||
from transformers import BlipProcessor, BlipForImageCaptioning
|
processor = BlipProcessor.from_pretrained("ybelkada/blip-image-captioning-base")
|
||||||
|
model = BlipForConditionalGeneration.from_pretrained("ybelkada/blip-image-captioning-base")
|
||||||
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
||||||
model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-base")
|
|
||||||
|
|
||||||
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
||||||
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
||||||
|
@ -46,13 +47,15 @@ text = "a photography of"
|
||||||
inputs = processor(raw_image, text, return_tensors="pt")
|
inputs = processor(raw_image, text, return_tensors="pt")
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
# >>> a photography of a woman and her dog
|
||||||
|
|
||||||
# unconditional image captioning
|
# unconditional image captioning
|
||||||
inputs = processor(raw_image, return_tensors="pt")
|
inputs = processor(raw_image, return_tensors="pt")
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
>>> a woman sitting on the beach with her dog
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -64,11 +67,12 @@ print(processor.decode(out[0], skip_special_tokens=True)
|
||||||
<summary> Click to expand </summary>
|
<summary> Click to expand </summary>
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
import requests
|
||||||
from transformers import BlipProcessor, BlipForImageCaptioning
|
from PIL import Image
|
||||||
|
from transformers import BlipProcessor, BlipForConditionalGeneration
|
||||||
|
|
||||||
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
||||||
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").to("cuda")
|
model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-base").to("cuda")
|
||||||
|
|
||||||
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
||||||
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
||||||
|
@ -78,13 +82,15 @@ text = "a photography of"
|
||||||
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
|
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
# >>> a photography of a woman and her dog
|
||||||
|
|
||||||
# unconditional image captioning
|
# unconditional image captioning
|
||||||
inputs = processor(raw_image, return_tensors="pt").to("cuda")
|
inputs = processor(raw_image, return_tensors="pt").to("cuda")
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
>>> a woman sitting on the beach with her dog
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -95,7 +101,9 @@ print(processor.decode(out[0], skip_special_tokens=True)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import torch
|
import torch
|
||||||
from transformers import BlipProcessor, BlipForImageCaptioning
|
import requests
|
||||||
|
from PIL import Image
|
||||||
|
from transformers import BlipProcessor, BlipForConditionalGeneration
|
||||||
|
|
||||||
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
||||||
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda")
|
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda")
|
||||||
|
@ -108,13 +116,15 @@ text = "a photography of"
|
||||||
inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16)
|
inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16)
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
# >>> a photography of a woman and her dog
|
||||||
|
|
||||||
# unconditional image captioning
|
# unconditional image captioning
|
||||||
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
|
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
|
||||||
|
|
||||||
out = model.generate(**inputs)
|
out = model.generate(**inputs)
|
||||||
print(processor.decode(out[0], skip_special_tokens=True)
|
print(processor.decode(out[0], skip_special_tokens=True))
|
||||||
|
>>> a woman sitting on the beach with her dog
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue