Downloads · 30 days
3
4% of all-time downloads
OmarGamal48812/flickr-captioning
flickr-captioning is a image-to-text model from OmarGamal48812. Use it when you need a caption or text from an image. It is set up for pytorch. The card lists the license as mit.
This model generates a natural-language description of an image. It uses a ResNet50 spatial-feature encoder, a Bahdanau (additive) attention module, and a GRU decoder initialized with GloVe 6B 300d embeddings, trained…
Downloads · 30 days
3
4% of all-time downloads
All-time downloads
73
Public
Repo size
812 MB
Likes
0
Public
Click a slice to open those files.
.pth591 MB · 100%
From the Hugging Face model README
This model generates a natural-language description of an image. It uses a ResNet50 spatial-feature encoder, a Bahdanau (additive) attention module, and a GRU decoder initialized with GloVe 6B 300d embeddings, trained on the merged Flickr8k + Flickr30k dataset (39,874 images × 5 captions). It follows the architecture from Show, Attend and Tell (Xu et al., 2015) with label smoothing, scheduled sampling, and two-phase CNN fine-tuning.
Evaluated on the held-out 1,873-image test split (image-level split — no captions cross train/val/test).
| Metric | Value |
|---|---|
| BLEU-1 | 0.6859 |
| BLEU-2 | 0.5289 |
| BLEU-3 | 0.4041 |
| BLEU-4 | 0.3093 |
| METEOR | 0.4709 |
| CIDEr | 0.7961 |
| ROUGE-L | 0.5257 |
Beam search uses length-normalized log-probs (alpha = 0.7) and a
repetition penalty of 1.2.
Image (3, 224, 224)
└─ ResNet50 (pretrained, frozen first 10 epochs, last 2 blocks fine-tuned)
output: (B, 2048, 7, 7) → reshape to (B, 49, 2048)
└─ Bahdanau attention V·tanh(W_enc(features) + W_dec(h_prev))
output: context vector (B, 2048), attention weights (B, 49)
└─ GRUCell (per timestep — re-queries attention each step)
hidden state size: 1024, embedding size: 300 (GloVe 6B 300d)
└─ Linear → vocab logits (V = 10,111)
Total parameters: ~37 M (25 M frozen ResNet, 12 M trainable decoder/projection).
<pad>=0, <start>=1, <end>=2, <unk>=3`.CrossEntropyLoss(ignore_index=0, label_smoothing=0.1) plus
doubly-stochastic regularization α_c · ((1 − Σ_t α_t)²).mean() with α_c = 1.03.2e-3, encoder LR 8e-5 (Phase B)ReduceLROnPlateau on val BLEU-4, factor=0.5, patience=3attention_gru_glove.pth — PyTorch checkpoint (encoder + decoder state dicts, config)vocab.pkl — pickled Vocabulary object built from the train splitconfig.json — JSON copy of the training hyperparametersmetrics_beam5.json — full test-set metrics (beam search k=5)git clone https://github.com/OmarGamal488/flickr-image-captioning.git
cd flickr-image-captioning
uv sync
Then in Python:
import pickle, torch
from huggingface_hub import hf_hub_download
from src.inference import load_attention_model, caption_image
from src.utils import get_device
repo_id = "OmarGamal48812/flickr-captioning"
ckpt_path = hf_hub_download(repo_id=repo_id, filename="attention_gru_glove.pth")
vocab_path = hf_hub_download(repo_id=repo_id, filename="vocab.pkl")
device = get_device()
with open(vocab_path, "rb") as f:
vocab = pickle.load(f)
encoder, decoder, cfg = load_attention_model(ckpt_path, len(vocab), device)
caption, beams = caption_image(
encoder, decoder, "your_image.jpg", vocab, device,
method="beam", beam_width=5,
)
print(caption)
for b in beams[:3]:
print(f" {b.score:+.3f} {b.caption}")
If you use this checkpoint, please cite the three papers this work builds on:
@inproceedings{xu2015show,
title = {Show, Attend and Tell: Neural Image Caption Generation with Visual Attention},
author = {Xu, Kelvin and Ba, Jimmy and Kiros, Ryan and Cho, Kyunghyun and Courville, Aaron and
Salakhutdinov, Ruslan and Zemel, Richard and Bengio, Yoshua},
booktitle = {ICML},
year = {2015}
}
@article{bahdanau2014neural,
title = {Neural Machine Translation by Jointly Learning to Align and Translate},
author = {Bahdanau, Dzmitry and Cho, Kyunghyun and Bengio, Yoshua},
journal = {arXiv preprint arXiv:1409.0473},
year = {2014}
}
@inproceedings{selvaraju2017gradcam,
title = {Grad-{CAM}: Visual Explanations from Deep Networks via Gradient-based Localization},
author = {Selvaraju, Ramprasaath R. and Cogswell, Michael and Das, Abhishek and
Vedantam, Ramakrishna and Parikh, Devi and Batra, Dhruv},
booktitle = {ICCV},
year = {2017}
}