Downloads · 30 days
31
9% of all-time downloads
candra/blip-image-captioning-finetuned
blip-image-captioning-finetuned is a image-text-to-text model from candra. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product.
This model is a BLIP (Bootstrapping Language-Image Pretraining) model fine-tuned for image captioning. It takes an image as input and generates a descriptive caption. Additionally, it can convert that caption into cle…
Downloads · 30 days
31
9% of all-time downloads
All-time downloads
351
Public
Parameters
247M
2 GB on disk
Likes
5
Public
Click a slice to open those files.
.safetensors990 MB · 100%
From the Hugging Face model README
candra/blip-image-captioning-finetuned)This model is a BLIP (Bootstrapping Language-Image Pretraining) model fine-tuned for image captioning. It takes an image as input and generates a descriptive caption. Additionally, it can convert that caption into cleaned, hashtag-friendly keywords.
Salesforce/blip-image-captioning-basefrom transformers import AutoProcessor, BlipForConditionalGeneration
import torch
from PIL import Image
# Load model and processor
processor = AutoProcessor.from_pretrained("candra/blip-image-captioning-finetuned")
model = BlipForConditionalGeneration.from_pretrained("candra/blip-image-captioning-finetuned")
# Load image
image_path = "IMAGE.jpg"
image = Image.open(image_path).convert("RGB")
# Set device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
# Preprocess and generate caption
inputs = processor(images=image, return_tensors="pt")
pixel_values = inputs.pixel_values.to(device)
generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print("Caption:", generated_caption)
# Convert caption to hashtags
words = generated_caption.lower().split(", ")
unique_words = sorted(set(words))
hashtags = ["#" + word.replace(" ", "") for word in unique_words]
print("Hashtags:", " ".join(hashtags))
.jpg, .png)Input Image
<img src="lion.jpg" alt="Example Image" width="500"/>
Generated Caption
animal, lion, mammal, wildlife, zoo, barrel, grass, backgound
Hashtags
#animal #lion #mammal #wildlife #zoo #barrel #grass #backgound