Downloads · 30 days
11
1% of all-time downloads
atasoglu/vit-gpt2-flickr8k
vit-gpt2-flickr8k is a image-to-text model from atasoglu. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as apache-2.0.
Vision Encoder Decoder (ViT + GPT2) model that fine-tuned on flickr8k-dataset for image-to-text task.
Downloads · 30 days
11
1% of all-time downloads
All-time downloads
2.1K
Public
Parameters
264M
2 GB on disk
Likes
1
Public
Click a slice to open those files.
.bin982 MB · 50%
How the weights are stored.
F32239M · 90%
From the Hugging Face model README
Vision Encoder Decoder (ViT + GPT2) model that fine-tuned on flickr8k-dataset for image-to-text task.
Example:
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
import torch
from PIL import Image
# load models
feature_extractor = ViTImageProcessor.from_pretrained("atasoglu/vit-gpt2-flickr8k")
tokenizer = AutoTokenizer.from_pretrained("atasoglu/vit-gpt2-flickr8k")
model = VisionEncoderDecoderModel.from_pretrained("atasoglu/vit-gpt2-flickr8k")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
# load image
img = Image.open("example.jpg")
# encode (extracting features)
pixel_values = feature_extractor(images=[img], return_tensors="pt").pixel_values
pixel_values = pixel_values.to(device)
# generate caption
output_ids = model.generate(pixel_values)
# decode
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
print(preds)
For more, see this awesome blog.