Views
No views yet
| 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 |
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)<pad>=0, <start>=1, <end>=2, 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)1git clone https://github.com/OmarGamal488/flickr-image-captioning.git
2cd flickr-image-captioning
3uv sync1import pickle, torch
2from huggingface_hub import hf_hub_download
3from src.inference import load_attention_model, caption_image
4from src.utils import get_device
5
6repo_id = "OmarGamal48812/flickr-captioning"
7ckpt_path = hf_hub_download(repo_id=repo_id, filename="attention_gru_glove.pth")
8vocab_path = hf_hub_download(repo_id=repo_id, filename="vocab.pkl")
9
10device = get_device()
11with open(vocab_path, "rb") as f:
12 vocab = pickle.load(f)
13
14encoder, decoder, cfg = load_attention_model(ckpt_path, len(vocab), device)
15
16caption, beams = caption_image(
17 encoder, decoder, "your_image.jpg", vocab, device,
18 method="beam", beam_width=5,
19)
20print(caption)
21for b in beams[:3]:
22 print(f" {b.score:+.3f} {b.caption}")1@inproceedings{xu2015show,
2 title = {Show, Attend and Tell: Neural Image Caption Generation with Visual Attention},
3 author = {Xu, Kelvin and Ba, Jimmy and Kiros, Ryan and Cho, Kyunghyun and Courville, Aaron and
4 Salakhutdinov, Ruslan and Zemel, Richard and Bengio, Yoshua},
5 booktitle = {ICML},
6 year = {2015}
7}
8
9@article{bahdanau2014neural,
10 title = {Neural Machine Translation by Jointly Learning to Align and Translate},
11 author = {Bahdanau, Dzmitry and Cho, Kyunghyun and Bengio, Yoshua},
12 journal = {arXiv preprint arXiv:1409.0473},
13 year = {2014}
14}
15
16@inproceedings{selvaraju2017gradcam,
17 title = {Grad-{CAM}: Visual Explanations from Deep Networks via Gradient-based Localization},
18 author = {Selvaraju, Ramprasaath R. and Cogswell, Michael and Das, Abhishek and
19 Vedantam, Ramakrishna and Parikh, Devi and Batra, Dhruv},
20 booktitle = {ICCV},
21 year = {2017}
22}