ydshieh / vit-gpt2-coco-en

huggingface.co
Total runs: 4.2K
24-hour runs: -98
7-day runs: -905
30-day runs: -1.4K
Model's Last Updated: 2022年9月16日
image-to-text

Introduction of vit-gpt2-coco-en

Model Details of vit-gpt2-coco-en

Example

The model is by no means a state-of-the-art model, but nevertheless produces reasonable image captioning results. It was mainly fine-tuned as a proof-of-concept for the 🤗 FlaxVisionEncoderDecoder Framework.

The model can be used as follows:

In PyTorch


import torch
import requests
from PIL import Image
from transformers import ViTFeatureExtractor, AutoTokenizer, VisionEncoderDecoderModel


loc = "ydshieh/vit-gpt2-coco-en"

feature_extractor = ViTFeatureExtractor.from_pretrained(loc)
tokenizer = AutoTokenizer.from_pretrained(loc)
model = VisionEncoderDecoderModel.from_pretrained(loc)
model.eval()


def predict(image):

    pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values

    with torch.no_grad():
        output_ids = model.generate(pixel_values, max_length=16, num_beams=4, return_dict_in_generate=True).sequences

    preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
    preds = [pred.strip() for pred in preds]

    return preds


# We will verify our results on an image of cute cats
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
with Image.open(requests.get(url, stream=True).raw) as image:
    preds = predict(image)

print(preds)
# should produce
# ['a cat laying on top of a couch next to another cat']

In Flax


import jax
import requests
from PIL import Image
from transformers import ViTFeatureExtractor, AutoTokenizer, FlaxVisionEncoderDecoderModel


loc = "ydshieh/vit-gpt2-coco-en"

feature_extractor = ViTFeatureExtractor.from_pretrained(loc)
tokenizer = AutoTokenizer.from_pretrained(loc)
model = FlaxVisionEncoderDecoderModel.from_pretrained(loc)

gen_kwargs = {"max_length": 16, "num_beams": 4}


# This takes sometime when compiling the first time, but the subsequent inference will be much faster
@jax.jit
def generate(pixel_values):
    output_ids = model.generate(pixel_values, **gen_kwargs).sequences
    return output_ids
    
    
def predict(image):

    pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values
    output_ids = generate(pixel_values)
    preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
    preds = [pred.strip() for pred in preds]
    
    return preds
    
    
# We will verify our results on an image of cute cats
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
with Image.open(requests.get(url, stream=True).raw) as image:
    preds = predict(image)
    
print(preds)
# should produce
# ['a cat laying on top of a couch next to another cat']

Runs of ydshieh vit-gpt2-coco-en on huggingface.co

4.2K
Total runs
-98
24-hour runs
-905
3-day runs
-905
7-day runs
-1.4K
30-day runs

More Information About vit-gpt2-coco-en huggingface.co Model

vit-gpt2-coco-en huggingface.co

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

vit-gpt2-coco-en huggingface.co Url

https://huggingface.co/ydshieh/vit-gpt2-coco-en

ydshieh vit-gpt2-coco-en online free

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

ydshieh vit-gpt2-coco-en online free url in huggingface.co:

https://huggingface.co/ydshieh/vit-gpt2-coco-en

vit-gpt2-coco-en install

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

vit-gpt2-coco-en install url in huggingface.co:

https://huggingface.co/ydshieh/vit-gpt2-coco-en

Url of vit-gpt2-coco-en

vit-gpt2-coco-en huggingface.co Url

Provider of vit-gpt2-coco-en huggingface.co

ydshieh
ORGANIZATIONS

Other API from ydshieh

huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年8月27日
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年12月17日
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年1月23日
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年8月27日
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年2月6日
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: 2024年6月13日