Commit
·
2a70c3d
1
Parent(s):
c99c5ee
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
|
5 |
+
# OFA-tiny
|
6 |
+
This is the **tiny** version of OFA pretrained model. OFA is a unified multimodal pretrained model that unifies modalities (i.e., cross-modality, vision, language) and tasks (e.g., image generation, visual grounding, image captioning, image classification, text generation, etc.) to a simple sequence-to-sequence learning framework.
|
7 |
+
|
8 |
+
To use it in Transformers, please refer to https://github.com/OFA-Sys/OFA/tree/feature/add_transformers and download the directory of transformers. After installation, you can use it as shown below:
|
9 |
+
|
10 |
+
```
|
11 |
+
>>> from PIL import Image
|
12 |
+
>>> from torchvision import transforms
|
13 |
+
>>> from transformers import OFATokenizer, OFAForConditionalGeneration
|
14 |
+
|
15 |
+
>>> mean, std = [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]
|
16 |
+
>>> resolution = 256
|
17 |
+
>>> patch_resize_transform = transforms.Compose([
|
18 |
+
lambda image: image.convert("RGB"),
|
19 |
+
transforms.Resize((resolution, resolution), interpolation=Image.BICUBIC),
|
20 |
+
transforms.ToTensor(),
|
21 |
+
transforms.Normalize(mean=mean, std=std)
|
22 |
+
])
|
23 |
+
|
24 |
+
>>> model = OFAForConditionalGeneration.from_pretrained(ckpt_dir)
|
25 |
+
>>> tokenizer = OFATokenizer.from_pretrained(ckpt_dir)
|
26 |
+
|
27 |
+
>>> txt = " what is the description of the image?"
|
28 |
+
>>> inputs = tokenizer([txt], max_length=1024, return_tensors="pt")["input_ids"]
|
29 |
+
>>> img = Image.open(path_to_image)
|
30 |
+
>>> patch_img = patch_resize_transform(img).unsqueeze(0)
|
31 |
+
|
32 |
+
>>> gen = model.generate(inputs, patch_img=patch_img, num_beams=4)
|
33 |
+
>>> print(tokenizer.decode(gen, skip_special_tokens=True, clean_up_tokenization_spaces=False))
|
34 |
+
```
|