This is the
medium
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.
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. There is no need to worry about the mismatch between Fairseq and transformers, since we have addressed the issue yet.
After, refer the path to OFA-medium to
ckpt_dir
, and prepare an image for the testing example below. Also, ensure that you have pillow and torchvision in your environment.
>>> from PIL import Image
>>> from torchvision import transforms
>>> from transformers import OFATokenizer, OFAModel
>>> from generate import sequence_generator
>>> mean, std = [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]
>>> resolution = 256>>> patch_resize_transform = transforms.Compose([
lambda image: image.convert("RGB"),
transforms.Resize((resolution, resolution), interpolation=Image.BICUBIC),
transforms.ToTensor(),
transforms.Normalize(mean=mean, std=std)
])
>>> tokenizer = OFATokenizer.from_pretrained(ckpt_dir)
>>> txt = " what does the image describe?">>> inputs = tokenizer([txt], return_tensors="pt").input_ids
>>> img = Image.open(path_to_image)
>>> patch_img = patch_resize_transform(img).unsqueeze(0)
# using the generator of fairseq version>>> model = OFAModel.from_pretrained(ckpt_dir, use_cache=True)
>>> generator = sequence_generator.SequenceGenerator(
tokenizer=tokenizer,
beam_size=5,
max_len_b=16,
min_len=0,
no_repeat_ngram_size=3,
)
>>> data = {}
>>> data["net_input"] = {"input_ids": inputs, 'patch_images': patch_img, 'patch_masks':torch.tensor([True])}
>>> gen_output = generator.generate([model], data)
>>> gen = [gen_output[i][0]["tokens"] for i inrange(len(gen_output))]
# using the generator of huggingface version>>> model = OFAModel.from_pretrained(ckpt_dir, use_cache=False)
>>> gen = model.generate(inputs, patch_images=patch_img, num_beams=5, no_repeat_ngram_size=3)
>>> print(tokenizer.batch_decode(gen, skip_special_tokens=True))
Runs of OFA-Sys ofa-medium on huggingface.co
14
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
6
30-day runs
More Information About ofa-medium huggingface.co Model
ofa-medium huggingface.co is an AI model on huggingface.co that provides ofa-medium's model effect (), which can be used instantly with this OFA-Sys ofa-medium model. huggingface.co supports a free trial of the ofa-medium model, and also provides paid use of the ofa-medium. Support call ofa-medium model through api, including Node.js, Python, http.
ofa-medium huggingface.co is an online trial and call api platform, which integrates ofa-medium's modeling effects, including api services, and provides a free online trial of ofa-medium, you can try ofa-medium online for free by clicking the link below.
OFA-Sys ofa-medium online free url in huggingface.co:
ofa-medium is an open source model from GitHub that offers a free installation service, and any user can find ofa-medium on GitHub to install. At the same time, huggingface.co provides the effect of ofa-medium install, users can directly use ofa-medium installed effect in huggingface.co for debugging and trial. It also supports api for free installation.