File size: 1,021 Bytes
cf6b11e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
---
library_name: transformers
license: mit
language:
- th
pipeline_tag: image-to-text
base_model: Salesforce/blip2-opt-2.7b-coco
---
## THAI-BLIP-2
fine-tuned for image captioning task from [blip2-opt-2.7b-coco](Salesforce/blip2-opt-2.7b-coco) with MSCOCO2017 thai caption.
## How to use:
```python
from transformers import Blip2ForConditionalGeneration, Blip2Processor
from PIL import Image
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
processor = Blip2Processor.from_pretrained("kkatiz/THAI-BLIP-2")
model = Blip2ForConditionalGeneration.from_pretrained("kkatiz/THAI-BLIP-2", device_map=device, torch_dtype=torch.bfloat16)
img = Image.open("Your image...")
inputs = processor(images=img, return_tensors="pt").to(device, torch.bfloat16)
# Adjust your `max_length`
generated_ids = model.generate(**inputs, max_length=20)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
print(generated_text)
``` |