Model Card for Image-Captioning-BLIP (Fine‑Tuned BLIP for Image Captioning)
0
3 commits
3 linked in READMEs
updated Aug 31, 2025
This repository provides a lightweight, pragmatic fine‑tuning and evaluation pipeline around Salesforce BLIP for image captioning, with sane defaults and a tiny, production‑friendly inference helper. Use it to fine‑tune Salesforce/blip-image-captioning-base on Flickr8k or COCO‑Karpathy and export artifacts you can push to the Hugging Face Hub.
TL;DR: End‑to‑end train → evaluate → export → caption images with a few commands. Defaults: BLIP‑base (ViT‑B/16), Flickr8k, BLEU during training, COCO‑style metrics (CIDEr/METEOR/SPICE) after training.
This project fine‑tunes BLIP (Bootstrapping Language‑Image Pre-training) for the image‑to‑text task. BLIP couples a ViT visual encoder with a text decoder for conditional generation and uses a bootstrapped captioning strategy during pretraining in the original work. Here, we re‑use the open BlipForConditionalGeneration weights and processor and adapt them to caption everyday photographs from Flickr8k or the COCO Karpathy split.
Salesforce/blip-image-captioning-baseUsers (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Use the code below to get started with the model.
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
# Replace with your fine-tuned repo once pushed, e.g. "amirhossein-yousefi/blip-captioning-flickr8k"
MODEL_ID = "Salesforce/blip-image-captioning-base"
processor = BlipProcessor.from_pretrained(MODEL_ID)
model = BlipForConditionalGeneration.from_pretrained(MODEL_ID)
image = Image.open("example.jpg").convert("RGB")
inputs = processor(image, return_tensors="pt")
out = model.generate(**inputs, max_new_tokens=30, num_beams=5, length_penalty=1.0, early_stopping=True)
print(processor.decode(out[0], skip_special_tokens=True))
Two common options are wired in:
ariG23498/flickr8k) — 8k images with 5 captions each. Default split in this repo: 90% train / 5% val / 5% test (deterministic by seed).yerevann/coco-karpathy) — community‑prepared Karpathy splits for COCO captions.⚠️ Always verify dataset licenses and usage terms before training or publishing models derived from them.
This project uses the Hugging Face Trainer with a custom collator; BlipProcessor handles both image and text preprocessing, and labels are padded to -100 for loss masking.
BlipProcessor consistent with BLIP defaults (resize/normalize/tokenize).45e-58 (train & eval)2TrueFalse (set True for low‑VRAM setups)50 steps; keep 2 checkpointssacrebleumax_txt_len = 40, gen_max_new_tokens = 30, num_beams = 5, length_penalty = 1.0, early_stopping = TrueAfter training, a compact JSON with COCO metrics is written to:
blip-open-out/coco_metrics.json
| Metric | Score |
|---|---|
| BLEU‑4 | 0.9708 |
| METEOR | 0.7888 |
| CIDEr | 9.3330 |
| SPICE | — |
{
"Bleu_4": 0.9707865195383757,
"METEOR": 0.7887653835397767,
"CIDEr": 9.332990983959254,
"SPICE": null
}
Estimate using the ML CO2 Impact calculator. Fill the values you observe for your runs:
-100), using the BLIP processor’s packing.Model Card for Image-Captioning-BLIP (Fine‑Tuned BLIP for Image Captioning)
0
3 commits
3 linked in READMEs
updated Aug 31, 2025
This repository provides a lightweight, pragmatic fine‑tuning and evaluation pipeline around Salesforce BLIP for image captioning, with sane defaults and a tiny, production‑friendly inference helper. Use it to fine‑tune Salesforce/blip-image-captioning-base on Flickr8k or COCO‑Karpathy and export artifacts you can push to the Hugging Face Hub.
TL;DR: End‑to‑end train → evaluate → export → caption images with a few commands. Defaults: BLIP‑base (ViT‑B/16), Flickr8k, BLEU during training, COCO‑style metrics (CIDEr/METEOR/SPICE) after training.
This project fine‑tunes BLIP (Bootstrapping Language‑Image Pre-training) for the image‑to‑text task. BLIP couples a ViT visual encoder with a text decoder for conditional generation and uses a bootstrapped captioning strategy during pretraining in the original work. Here, we re‑use the open BlipForConditionalGeneration weights and processor and adapt them to caption everyday photographs from Flickr8k or the COCO Karpathy split.
Salesforce/blip-image-captioning-baseUsers (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Use the code below to get started with the model.
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
# Replace with your fine-tuned repo once pushed, e.g. "amirhossein-yousefi/blip-captioning-flickr8k"
MODEL_ID = "Salesforce/blip-image-captioning-base"
processor = BlipProcessor.from_pretrained(MODEL_ID)
model = BlipForConditionalGeneration.from_pretrained(MODEL_ID)
image = Image.open("example.jpg").convert("RGB")
inputs = processor(image, return_tensors="pt")
out = model.generate(**inputs, max_new_tokens=30, num_beams=5, length_penalty=1.0, early_stopping=True)
print(processor.decode(out[0], skip_special_tokens=True))
Two common options are wired in:
ariG23498/flickr8k) — 8k images with 5 captions each. Default split in this repo: 90% train / 5% val / 5% test (deterministic by seed).yerevann/coco-karpathy) — community‑prepared Karpathy splits for COCO captions.⚠️ Always verify dataset licenses and usage terms before training or publishing models derived from them.
This project uses the Hugging Face Trainer with a custom collator; BlipProcessor handles both image and text preprocessing, and labels are padded to -100 for loss masking.
BlipProcessor consistent with BLIP defaults (resize/normalize/tokenize).45e-58 (train & eval)2TrueFalse (set True for low‑VRAM setups)50 steps; keep 2 checkpointssacrebleumax_txt_len = 40, gen_max_new_tokens = 30, num_beams = 5, length_penalty = 1.0, early_stopping = TrueAfter training, a compact JSON with COCO metrics is written to:
blip-open-out/coco_metrics.json
| Metric | Score |
|---|---|
| BLEU‑4 | 0.9708 |
| METEOR | 0.7888 |
| CIDEr | 9.3330 |
| SPICE | — |
{
"Bleu_4": 0.9707865195383757,
"METEOR": 0.7887653835397767,
"CIDEr": 9.332990983959254,
"SPICE": null
}
Estimate using the ML CO2 Impact calculator. Fill the values you observe for your runs:
-100), using the BLIP processor’s packing.