Sohan Anisetty commited on
Commit
3ef4848
1 Parent(s): dc57090

add readme

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # OFA-tiny
6
+
7
+ ## Introduction
8
+ This is the **tiny** version of OFA pretrained model finetuned on vqaV2.
9
+
10
+ The directory includes 4 files, namely `config.json` which consists of model configuration, `vocab.json` and `merge.txt` for our OFA tokenizer, and lastly `pytorch_model.bin` which consists of model weights.
11
+
12
+
13
+ ## How to use
14
+ Download the models as shown below.
15
+ ```bash
16
+ git clone https://github.com/sohananisetty/OFA_VQA.git
17
+ git clone https://huggingface.co/SohanAnisetty/ofa-vqa-tiny
18
+ ```
19
+
20
+ After, refer the path to ofa-vqa-tiny to `ckpt_dir`, and prepare an image for the testing example below.
21
+
22
+ ```python
23
+ >>> from PIL import Image
24
+ >>> from torchvision import transforms
25
+ >>> from transformers import OFATokenizer, OFAModelForVQA
26
+
27
+ >>> mean, std = [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]
28
+ >>> resolution = 256
29
+ >>> patch_resize_transform = transforms.Compose([
30
+ lambda image: image.convert("RGB"),
31
+ transforms.Resize((resolution, resolution), interpolation=Image.BICUBIC),
32
+ transforms.ToTensor(),
33
+ transforms.Normalize(mean=mean, std=std)
34
+ ])
35
+
36
+
37
+ >>> tokenizer = OFATokenizer.from_pretrained(ckpt_dir)
38
+
39
+ >>> txt = " what does the image describe?"
40
+ >>> inputs = tokenizer([txt], return_tensors="pt").input_ids
41
+ >>> img = Image.open(path_to_image)
42
+ >>> patch_img = patch_resize_transform(img).unsqueeze(0)
43
+
44
+
45
+ >>> model = OFAModel.from_pretrained(ckpt_dir, use_cache=False)
46
+ >>> gen = model.generate(inputs, patch_images=patch_img, num_beams=5, no_repeat_ngram_size=3)
47
+
48
+ >>> print(tokenizer.batch_decode(gen, skip_special_tokens=True))
49
+ ```