Downloads · 30 days
6
1% of all-time downloads
sadassa17/rgb-language_cap
rgb-language_cap is a image-to-text model from sadassa17. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as mit.
<u<bWe are creating a spatial aware vision-language(VL) model.</b</u
Downloads · 30 days
6
1% of all-time downloads
All-time downloads
594
Public
Parameters
239M
1.9 GB on disk
Likes
0
Public
Click a slice to open those files.
.bin957 MB · 50%
From the Hugging Face model README
<u><b>We are creating a spatial aware vision-language(VL) model.</b></u>
This is a trained model on COCO dataset images including extra information regarding the spatial relationship between the entities of the image.
This is a sequence to sequence model for image-captioning. The architecture is <u><b>ViT encoder and GPT2 decoder.</b></u>
<details> <summary>Requirements!</summary> - 4GB GPU RAM. - CUDA enabled docker </details>The way to download and run this:
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
from transformers import pipeline
image_captioner = pipeline("image-to-text", model="sadassa17/rgb-language_cap", max_new_tokens=200, device=device)
filename = 'path/to/file'
generated_captions = image_captioner(filename)
print(generated_captions)
The model is trained to produce as many words as possible with a maximum of 200 tokens, which translates to roughly 5 sentences, while the 6th sentence is usually cropped.
<i>The output is always of that form: "Object1" is to the "Left/Right etc." of the "Object2".</i>
import os
def print_up_to_n_sentences(captions, n):
for caption in captions:
generated_text = caption.get('generated_text', '')
sentences = generated_text.split('.')
result = '.'.join(sentences[:n])
#print(result)
return result
filename = 'path/to/file'
generated_captions = image_captioner(filename)
captions = print_up_to_n_sentences(generated_captions, 5)
print(captions)