How ahzamejaz/image-captioning-using-lstms works
Purpose and entry points
This repository is a Python image-captioning experiment: it pairs image features from a ResNet encoder with an LSTM text decoder to generate captions. The apparent executable entry points are run_exp.py for experiments/training orchestration and image_captioner.py as a top-level module/script. Package code lives under image_captioner/.
Experiment orchestration
run_exp.py is the primary control boundary for running the captioning workflow. It should coordinate dataset construction, model creation, optimization, and recording outcomes. loss.json appears to hold persisted loss/history output from an experiment, while metadata/metadata.py likely centralizes experiment or dataset metadata.
Grounding paths:
• run_exp.py
• loss.json
• metadata/metadata.py
Dataset and split pipeline
The data layer defines a custom Flickr-style caption dataset and utilities for partitioning examples. It is responsible for converting image/caption source records into samples consumable by the model pipeline, including any vocabulary/token representation and image loading/transform boundary.
Grounding paths:
• image_captioner/data/FlickerCustomDataset.py
• image_captioner/data/utils/splits.py
• image_captioner/data/__init__.py
Visual encoder
The visual branch is implemented as a ResNet-based image encoder. Its architectural role is to accept image tensors and emit feature vectors or embeddings that initialize or condition caption decoding. This is the key boundary between computer-vision preprocessing/backbone execution and sequence generation.
Grounding paths:
• image_captioner/model/resnet.py
• image_captioner/model/__init__.py
Language decoder
The LSTM model implements autoregressive caption generation. It consumes encoded image context plus caption tokens during training, and likely produces token logits for loss computation; at inference it would iteratively feed generated tokens back into the decoder until an end token or length limit.
Grounding paths:
• image_captioner/model/lstm.py
• image_captioner/model/__init__.py
End-to-end flow
The expected primary flow is: dataset split selection → custom dataset yields image/caption samples → image passes through ResNet → image embedding conditions LSTM → decoder outputs vocabulary scores → training loop computes sequence loss and updates encoder/decoder parameters → experiment metrics/history are persisted. During generation, the update loop becomes token-by-token decoding rather than teacher-forced caption input.
Key package boundaries:
• image_captioner/data/ owns source-data adaptation and splits.
• image_captioner/model/ owns neural architecture.
• run_exp.py connects those boundaries into a runnable experiment.
Runtime and dependencies
The project is Python-based, with environment and dependency definitions in environment.yml and requirements/req.txt. Given the ResNet/LSTM architecture, the material runtime is a deep-learning framework environment with image-processing support; no deployed service, web runtime, database, or cloud infrastructure is represented in the repository tree.
Grounding paths:
• environment.yml
• requirements/req.in
• requirements/req.txt
Main entry points: run_exp.py Training loop · lstm.py LSTM decoder · FlickerCustomDataset.py Flickr caption dataset · resnet.py ResNet encoder
Components 13
Data pipeline
- Dataset splits · Partitions caption examples for experiment use.
image_captioner/data/utils/splits.py - Flickr caption dataset · Loads images and caption/token samples.
image_captioner/data/FlickerCustomDataset.py - Data package API
image_captioner/data/__init__.py
Caption model
- ResNet encoder · Converts image tensors into caption-conditioning embeddings.
image_captioner/model/resnet.py - LSTM decoder · Produces vocabulary scores and autoregressive captions.
image_captioner/model/lstm.py - Model package API
image_captioner/model/__init__.py
Experiment runtime
- Experiment runner · Coordinates training and experiment recording.
run_exp.py - Captioner module
image_captioner.py - Experiment metadata
metadata/metadata.py - Loss history · Persisted training loss or history.
loss.json - Training loop · Computes sequence loss and updates encoder and decoder parameters.
run_exp.py
Other components
- ML environment · Python deep-learning and image-processing runtime.
environment.yml - Pinned requirements
requirements/req.txt
Connections 17
- ML environment → Experiment runner: provides runtime
- Pinned requirements → ML environment: declares packages
- Captioner module → Model package API: uses captioning package
- Experiment metadata → Experiment runner: supplies metadata
- Experiment runner → Dataset splits: selects partitions
- Dataset splits → Flickr caption dataset: selects examples
- Data package API → Flickr caption dataset: exports
- Flickr caption dataset → ResNet encoder: image tensors
- Flickr caption dataset → LSTM decoder: caption tokens · Teacher-forced training input.
- ResNet encoder → LSTM decoder: image embedding · Conditions decoding.
- Model package API → ResNet encoder: exports
- Model package API → LSTM decoder: exports
- Experiment runner → Training loop: runs
- LSTM decoder → Training loop: vocabulary scores
- Training loop → ResNet encoder: optimizer updates
- Training loop → LSTM decoder: optimizer updates
- Training loop → Loss history: persists loss history