atasoglu commited on
Commit
24a36dc
1 Parent(s): 61fbed5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -1
README.md CHANGED
@@ -14,4 +14,34 @@ tags:
14
  base_model:
15
  - google/vit-base-patch16-224
16
  - ytu-ce-cosmos/turkish-gpt2
17
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  base_model:
15
  - google/vit-base-patch16-224
16
  - ytu-ce-cosmos/turkish-gpt2
17
+ ---
18
+ # vit-base-patch16-224-turkish-gpt2
19
+
20
+ This vision encoder-decoder model utilizes the [google/vit-base-patch16-224](https://huggingface.co/google/vit-base-patch16-224) as the encoder and [ytu-ce-cosmos/turkish-gpt2](https://huggingface.co/ytu-ce-cosmos/turkish-gpt2) as the decoder, and it has been fine-tuned on the [flickr8k-turkish](https://huggingface.co/datasets/atasoglu/flickr8k-turkish) dataset to generate image captions in Turkish.
21
+
22
+ ## Usage
23
+
24
+ ```py
25
+ import torch
26
+ from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
27
+ from PIL import Image
28
+
29
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
30
+ model_id = "atasoglu/vit-base-patch16-224-turkish-gpt2"
31
+ img = Image.open("example.jpg")
32
+
33
+ feature_extractor = ViTImageProcessor.from_pretrained(model_id)
34
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
35
+ model = VisionEncoderDecoderModel.from_pretrained(model_id)
36
+ model.to(device)
37
+
38
+ features = feature_extractor(images=[img], return_tensors="pt")
39
+ pixel_values = features.pixel_values.to(device)
40
+
41
+ generated_captions = tokenizer.batch_decode(
42
+ model.generate(pixel_values, max_new_tokens=128),
43
+ skip_special_tokens=True,
44
+ )
45
+
46
+ print(generated_captions)
47
+ ```