Automatic image caption generation using EfficientNetB3 + Stacked LSTM + Bahdanau Attention, trained on Flickr8k + Flickr30k.
the Model App is deployed on a HuggingFace Space :
https://huggingface.co/spaces/Mohamed-M99/flickr-8k-30k-Image-Captioning-DPproject
Upload an image and get an AI‑generated caption.
image-captioning/
│
├── notebook.ipynb
├── app.py
├── requirements.txt
│
├── Artifacts (generated after training)
│ ├── best_model.pth
│ ├── best_encoder.pth
│ ├── word2idx.pkl
│ ├── idx2word.pkl
│ ├── captions_dict.pkl
│ ├── image_to_path.pkl
│ ├── train_imgs.pkl
│ ├── val_imgs.pkl
│ └── test_imgs.pkl
│
└── Outputs (generated during training)
├── attention_training_curves.png
└── caption_generation_sample.png
| Dataset | Source | Images |
|---|---|---|
| Flickr8k | Kaggle | 8,091 |
| Flickr30k | Kaggle | 31,783 |
Split: 80% train / 10% val / 10% test (image-level, no leakage)
| Metric | Score |
|---|---|
| BLEU-1 | 0.7050 |
| BLEU-2 | 0.5352 |
| BLEU-3 | 0.4024 |
| BLEU-4 | 0.2965 |
| Training Epochs | 65 (early stop) |
| Training Duration | 4 hours |
| Choice | Rationale |
|---|---|
| Spatial features (100×1536) | Allows attention to localize to image regions |
| Stacked 2-layer LSTM | Richer sequential representations |
| GloVe 300d initialization | Strong semantic prior before training |
| 3-tier learning rates | Protects pre-trained weights, accelerates decoder |
| Frequency threshold = 4 | Filters noise without shrinking vocab too aggressively |
| Beam search (width = 3) | Better captions than greedy at inference time |
KaggleHub · NLTK · PyTorch · TorchVision · EfficientNetB3 · GloVe · Streamlit