# ahzamejaz/image-captioning-using-lstms architecture

> Architecture diagram of the GitHub repository ahzamejaz/image-captioning-using-lstms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahzamejaz/image-captioning-using-lstms
- Repository: https://github.com/ahzamejaz/image-captioning-using-lstms

## Overview

#### 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`](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/run_exp.py) (Training loop), [`image_captioner/model/lstm.py`](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/lstm.py) (LSTM decoder), [`image_captioner/data/FlickerCustomDataset.py`](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/FlickerCustomDataset.py) (Flickr caption dataset), [`image_captioner/model/resnet.py`](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/resnet.py) (ResNet encoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data pipeline"]
  node_splits["Dataset splits<br/>split utility<br/>[splits.py]"]
  node_flickr_dataset["Flickr caption dataset<br/>PyTorch dataset"]
  node_data_package["Data package API<br/>package boundary<br/>[__init__.py]"]
end

subgraph group_model["Caption model"]
  node_resnet["ResNet encoder<br/>vision encoder<br/>[resnet.py]"]
  node_lstm["LSTM decoder<br/>sequence decoder<br/>[lstm.py]"]
  node_model_package["Model package API<br/>package boundary<br/>[__init__.py]"]
end

subgraph group_experiment["Experiment runtime"]
  node_run_exp["Experiment runner<br/>Python entry point<br/>[run_exp.py]"]
  node_captioner_script["Captioner module<br/>Python script<br/>[image_captioner.py]"]
  node_metadata["Experiment metadata<br/>metadata module<br/>[metadata.py]"]
  node_loss_history["Loss history<br/>experiment output<br/>[loss.json]"]
  node_training{{"Training loop<br/>optimization stage<br/>[run_exp.py]"}}
end

node_environment["ML environment<br/>dependency environment<br/>[environment.yml]"]
node_requirements["Pinned requirements<br/>dependency manifest<br/>[req.txt]"]

node_environment -.->|"provides runtime"| node_run_exp
node_requirements -.->|"declares packages"| node_environment
node_captioner_script -->|"uses captioning package"| node_model_package
node_metadata -->|"supplies metadata"| node_run_exp
node_run_exp -->|"selects partitions"| node_splits
node_splits -->|"selects examples"| node_flickr_dataset
node_data_package -.->|"exports"| node_flickr_dataset
node_flickr_dataset -->|"image tensors"| node_resnet
node_flickr_dataset -->|"caption tokens"| node_lstm
node_resnet -->|"image embedding"| node_lstm
node_model_package -.->|"exports"| node_resnet
node_model_package -.->|"exports"| node_lstm
node_run_exp -->|"runs"| node_training
node_lstm -->|"vocabulary scores"| node_training
node_training -->|"optimizer updates"| node_resnet
node_training -->|"optimizer updates"| node_lstm
node_training -->|"persists loss history"| node_loss_history

click node_run_exp "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/run_exp.py"
click node_captioner_script "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner.py"
click node_metadata "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/metadata/metadata.py"
click node_loss_history "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/loss.json"
click node_splits "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/utils/splits.py"
click node_flickr_dataset "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/FlickerCustomDataset.py"
click node_data_package "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/__init__.py"
click node_resnet "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/resnet.py"
click node_lstm "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/lstm.py"
click node_model_package "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/__init__.py"
click node_training "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/run_exp.py"
click node_environment "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/environment.yml"
click node_requirements "https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/requirements/req.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_splits,node_flickr_dataset,node_data_package toneBlue
class node_resnet,node_lstm,node_model_package toneAmber
class node_run_exp,node_captioner_script,node_metadata,node_loss_history,node_training toneMint
class node_environment,node_requirements toneNeutral
```

## Components

### Data pipeline

- [Dataset splits](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/utils/splits.py): split utility · Partitions caption examples for experiment use. · `image_captioner/data/utils/splits.py`
- [Flickr caption dataset](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/FlickerCustomDataset.py): PyTorch dataset · Loads images and caption/token samples. · `image_captioner/data/FlickerCustomDataset.py`
- [Data package API](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/data/__init__.py): package boundary · `image_captioner/data/__init__.py`

### Caption model

- [ResNet encoder](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/resnet.py): vision encoder · Converts image tensors into caption-conditioning embeddings. · `image_captioner/model/resnet.py`
- [LSTM decoder](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/lstm.py): sequence decoder · Produces vocabulary scores and autoregressive captions. · `image_captioner/model/lstm.py`
- [Model package API](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner/model/__init__.py): package boundary · `image_captioner/model/__init__.py`

### Experiment runtime

- [Experiment runner](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/run_exp.py): Python entry point · Coordinates training and experiment recording. · `run_exp.py`
- [Captioner module](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/image_captioner.py): Python script · `image_captioner.py`
- [Experiment metadata](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/metadata/metadata.py): metadata module · `metadata/metadata.py`
- [Loss history](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/loss.json): experiment output · Persisted training loss or history. · `loss.json`
- [Training loop](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/run_exp.py): optimization stage · Computes sequence loss and updates encoder and decoder parameters. · `run_exp.py`

### Other components

- [ML environment](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/environment.yml): dependency environment · Python deep-learning and image-processing runtime. · `environment.yml`
- [Pinned requirements](https://github.com/ahzamejaz/image-captioning-using-lstms/blob/main/requirements/req.txt): dependency manifest · `requirements/req.txt`

## Connections

- 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
