Natthaphon commited on
Commit
1315e90
·
1 Parent(s): ddd6b2d

Added info to readme

Browse files
Files changed (1) hide show
  1. README.md +28 -1
README.md CHANGED
@@ -1,5 +1,32 @@
 
 
 
 
1
  # Thai Image Captioning
2
- A
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # Acknowledgement
5
  This work is partially supported by the Program Management Unit for Human Resources & Institutional Development, Research and Innovation (PMU-B) [Grant number B04G640107]
 
1
+ ---
2
+ language:
3
+ - th
4
+ ---
5
  # Thai Image Captioning
6
+ Encoder-decoder style image captioning model using [Swin-L](https://huggingface.co/microsoft/swinv2-large-patch4-window12to16-192to256-22kto1k-ft) and [Wangchanberta](https://huggingface.co/airesearch/wangchanberta-base-att-spm-uncased). Trained on Thai language MSCOCO and IPU24 dataset.
7
+
8
+ # Usage
9
+
10
+ With `VisionEncoderDecoderModel`.
11
+ ```
12
+ from transformers import VisionEncoderDecoderModel, AutoImageProcessor, AutoTokenizer
13
+ device = 'cuda'
14
+ gen_kwargs = {"max_length": 120, "num_beams": 4}
15
+ model_path = 'Natthaphon/thaicapgen-swin-wangchan'
16
+ feature_extractor = AutoImageProcessor.from_pretrained(model_path)
17
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
18
+ model = VisionEncoderDecoderModel.from_pretrained(model_path).to(device)
19
+ pixel_values = feature_extractor(images=[Image.open('/home/palm/Pictures/KDEScreenshot/Screenshot_20241030_110135.png')], 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
+ You can also use `AutoModel` to load it. But this requires `trust_remote_code=True`.
25
+ ```
26
+ from transformers import AutoModel
27
+ model_path = 'Natthaphon/thaicapgen-swin-wangchan'
28
+ model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(device)
29
+ ```
30
 
31
  # Acknowledgement
32
  This work is partially supported by the Program Management Unit for Human Resources & Institutional Development, Research and Innovation (PMU-B) [Grant number B04G640107]