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-baseckpt_dir, and prepare an image for the testing example below.1from PIL import Image
2from torchvision import transforms
3from transformers import OFATokenizer, OFAModelForVQA
4
5mean, std = [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]
6resolution = 480
7patch_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
15tokenizer = OFATokenizer.from_pretrained(ckpt_dir)
16
17txt = " what does the image describe?"
18inputs = tokenizer([txt], return_tensors="pt").input_ids
19inputs = inputs.cuda()
20img = Image.open(path_to_image)
21patch_img = patch_resize_transform(img).unsqueeze(0).cuda()
22
23
24model = OFAModel.from_pretrained(ckpt_dir, use_cache=False).cuda()
25gen = model.generate(inputs, patch_images=patch_img, num_beams=5, no_repeat_ngram_size=3)
26
27print(tokenizer.batch_decode(gen skip_special_tokens=True))