Commit
·
3aedf50
1
Parent(s):
e137a83
Added readme
Browse files
README.md
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- th
|
4 |
+
---
|
5 |
+
# Thai Image Captioning
|
6 |
+
Encoder-decoder style image captioning model using [CLIP encoder](https://huggingface.co/openai/clip-vit-base-patch32) and [GPT2](https://huggingface.co/openai-community/gpt2). Trained on Thai language MSCOCO and IPU24 dataset.
|
7 |
+
|
8 |
+
# Usage
|
9 |
+
|
10 |
+
Use `AutoModel` to load it. Requires `trust_remote_code=True`.
|
11 |
+
```python
|
12 |
+
from transformers import AutoModel, AutoImageProcessor, AutoTokenizer
|
13 |
+
device = 'cuda'
|
14 |
+
gen_kwargs = {"max_length": 120, "num_beams": 4}
|
15 |
+
model_path = 'Natthaphon/thaicapgen-clip-gpt2'
|
16 |
+
feature_extractor = AutoImageProcessor.from_pretrained(model_path)
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
18 |
+
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(device)
|
19 |
+
pixel_values = feature_extractor(images=[Image.open(image_path)], return_tensors="pt").pixel_values
|
20 |
+
pixel_values = pixel_values.to(device)
|
21 |
+
output_ids = model.generate(pixel_values, **gen_kwargs)
|
22 |
+
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
23 |
+
```
|
24 |
+
|
25 |
+
# Acknowledgement
|
26 |
+
This work is partially supported by the Program Management Unit for Human Resources & Institutional Development, Research and Innovation (PMU-B) [Grant number B04G640107]
|