Views
No views yet
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.1git clone https://github.com/sohananisetty/OFA_VQA.git
2git clone https://huggingface.co/SohanAnisetty/ofa-vqa-tinyckpt_dir, and prepare an image for the testing example below.1>>> from PIL import Image
2>>> from torchvision import transforms
3>>> from transformers import OFATokenizer, OFAModelForVQA
4
5>>> mean, std = [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]
6>>> resolution = 256
7>>> patch_resize_transform = transforms.Compose([
8 lambda image: image.convert("RGB"),
9 transforms.Resize((resolution, resolution), interpolation=Image.BICUBIC),
10 transforms.ToTensor(),
11 transforms.Normalize(mean=mean, std=std)
12 ])
13
14
15>>> tokenizer = OFATokenizer.from_pretrained(ckpt_dir)
16
17>>> txt = " what does the image describe?"
18>>> inputs = tokenizer([txt], return_tensors="pt").input_ids
19>>> img = Image.open(path_to_image)
20>>> patch_img = patch_resize_transform(img).unsqueeze(0)
21
22
23>>> model = OFAModel.from_pretrained(ckpt_dir, use_cache=False)
24>>> gen = model.generate(inputs, patch_images=patch_img, num_beams=5, no_repeat_ngram_size=3)
25
26>>> print(tokenizer.batch_decode(gen, skip_special_tokens=True))