File size: 1,680 Bytes
e429301
 
 
 
 
 
 
 
e1f9123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e429301
 
55b822c
e75a513
 
 
 
 
 
 
 
 
 
 
4159606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
license: cc-by-4.0
task_categories:
- text-to-image
- image-to-image
language:
- en
pretty_name: splash
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
dataset_info:
  features:
  - name: IMAGE_ID
    dtype: string
  - name: CAPTION
    dtype: string
  - name: IMG
    dtype: image
  splits:
  - name: train
    num_bytes: 37969774373.0
    num_examples: 57857
  download_size: 37837578517
  dataset_size: 37969774373.0
---

It can be captioned by [PaliGemma2](https://huggingface.co/google/paligemma2-3b-ft-docci-448)


```python
from datasets import load_dataset
from tqdm import tqdm

dataset = load_dataset("WeiChow/splash")

for item in dataset:
    ...
```

caption:
```python
from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration
import torch
from datasets import load_dataset
from tqdm import tqdm
from termcolor import cprint

dataset = load_dataset("WeiChow/splash")

model_id = "google/paligemma2-3b-ft-docci-448"
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="cuda").eval()
processor = PaliGemmaProcessor.from_pretrained(model_id)

for item in dataset:
    model_inputs = processor(text="caption en", images=item['IMG'], return_tensors="pt").to(torch.bfloat16).to(model.device)
    input_len = model_inputs["input_ids"].shape[-1]

    with torch.inference_mode():
        generation = model.generate(**model_inputs, max_new_tokens=30, do_sample=False)
        generation = generation[0][input_len:]
        decoded = processor.decode(generation, skip_special_tokens=True)
        print(item['IMAGE_ID'])
        cprint(decoded, 'cyan')
```