OFA-Sys / ofa-large-caption

huggingface.co
Total runs: 57
24-hour runs: 1
7-day runs: 10
30-day runs: 18
Model's Last Updated: November 09 2022

Introduction of ofa-large-caption

Model Details of ofa-large-caption

OFA-large-caption

Introduction

This is the large version of OFA model finetuned for image captioning . 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.

How to use

To use it in transformers, please refer to https://github.com/OFA-Sys/OFA/tree/feature/add_transformers . Install the transformers and download the models as shown below.

git clone --single-branch --branch feature/add_transformers https://github.com/OFA-Sys/OFA.git
pip install OFA/transformers/
git clone https://huggingface.co/OFA-Sys/OFA-large-caption

After, refer the path to OFA-large 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 = 480
>>> 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 in range(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-large-caption on huggingface.co

57
Total runs
1
24-hour runs
4
3-day runs
10
7-day runs
18
30-day runs

More Information About ofa-large-caption huggingface.co Model

More ofa-large-caption license Visit here:

https://choosealicense.com/licenses/apache-2.0

ofa-large-caption huggingface.co

ofa-large-caption huggingface.co is an AI model on huggingface.co that provides ofa-large-caption's model effect (), which can be used instantly with this OFA-Sys ofa-large-caption model. huggingface.co supports a free trial of the ofa-large-caption model, and also provides paid use of the ofa-large-caption. Support call ofa-large-caption model through api, including Node.js, Python, http.

ofa-large-caption huggingface.co Url

https://huggingface.co/OFA-Sys/ofa-large-caption

OFA-Sys ofa-large-caption online free

ofa-large-caption huggingface.co is an online trial and call api platform, which integrates ofa-large-caption's modeling effects, including api services, and provides a free online trial of ofa-large-caption, you can try ofa-large-caption online for free by clicking the link below.

OFA-Sys ofa-large-caption online free url in huggingface.co:

https://huggingface.co/OFA-Sys/ofa-large-caption

ofa-large-caption install

ofa-large-caption is an open source model from GitHub that offers a free installation service, and any user can find ofa-large-caption on GitHub to install. At the same time, huggingface.co provides the effect of ofa-large-caption install, users can directly use ofa-large-caption installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

ofa-large-caption install url in huggingface.co:

https://huggingface.co/OFA-Sys/ofa-large-caption

Url of ofa-large-caption

ofa-large-caption huggingface.co Url

Provider of ofa-large-caption huggingface.co

OFA-Sys
ORGANIZATIONS

Other API from OFA-Sys

huggingface.co

Total runs: 3.4K
Run Growth: 3.4K
Growth Rate: 99.80%
Updated:November 09 2022
huggingface.co

Total runs: 92
Run Growth: 38
Growth Rate: 41.30%
Updated:November 09 2022
huggingface.co

Total runs: 50
Run Growth: 39
Growth Rate: 78.00%
Updated:November 09 2022
huggingface.co

Total runs: 41
Run Growth: -14
Growth Rate: -34.15%
Updated:August 16 2023
huggingface.co

Total runs: 14
Run Growth: 6
Growth Rate: 42.86%
Updated:November 09 2022
huggingface.co

Total runs: 10
Run Growth: 8
Growth Rate: 80.00%
Updated:November 09 2022
huggingface.co

Total runs: 5
Run Growth: 4
Growth Rate: 80.00%
Updated:November 09 2022
huggingface.co

Total runs: 3
Run Growth: 2
Growth Rate: 66.67%
Updated:October 26 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:June 30 2023