File size: 2,218 Bytes
581e3f9 10a4da5 581e3f9 7289eda 581e3f9 7289eda 581e3f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
---
datasets:
- Dataseeds/DataSeeds.AI-Sample-Dataset-DSD
language:
- en
pipeline_tag: image-text-to-text
---
## ๐ผ๏ธ BLIP Image Captioning โ Finetuned (`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.
### ๐ง Model Details
* **Base model**: [`Salesforce/blip-image-captioning-base`](https://huggingface.co/Salesforce/blip-image-captioning-base)
* **Task**: Image Captioning
---
## ๐งช Example Usage
```python
from 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))
```
---
## ๐ฅ Input
* **Image** (RGB format, e.g., `.jpg`, `.png`)
## ๐ค Output
* **Caption**: A string describing the contents of the image.
* **Hashtags**: A list of unique hashtags derived from the caption.
---
## ๐ Example
**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
``` |