Datasets:
Update README.md
Browse files
README.md
CHANGED
@@ -39,3 +39,29 @@ dataset = load_dataset("WeiChow/splash")
|
|
39 |
for item in dataset:
|
40 |
...
|
41 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
for item in dataset:
|
40 |
...
|
41 |
```
|
42 |
+
|
43 |
+
caption:
|
44 |
+
```python
|
45 |
+
from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration
|
46 |
+
import torch
|
47 |
+
from datasets import load_dataset
|
48 |
+
from tqdm import tqdm
|
49 |
+
from termcolor import cprint
|
50 |
+
|
51 |
+
dataset = load_dataset("WeiChow/splash")
|
52 |
+
|
53 |
+
model_id = "google/paligemma2-3b-ft-docci-448"
|
54 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="cuda").eval()
|
55 |
+
processor = PaliGemmaProcessor.from_pretrained(model_id)
|
56 |
+
|
57 |
+
for item in dataset:
|
58 |
+
model_inputs = processor(text="caption en", images=item['IMG'], return_tensors="pt").to(torch.bfloat16).to(model.device)
|
59 |
+
input_len = model_inputs["input_ids"].shape[-1]
|
60 |
+
|
61 |
+
with torch.inference_mode():
|
62 |
+
generation = model.generate(**model_inputs, max_new_tokens=30, do_sample=False)
|
63 |
+
generation = generation[0][input_len:]
|
64 |
+
decoded = processor.decode(generation, skip_special_tokens=True)
|
65 |
+
print(item['IMAGE_ID'])
|
66 |
+
cprint(decoded, 'cyan')
|
67 |
+
```
|