# pavankumarkema/trafficforecastingindia architecture

> Architecture diagram of the GitHub repository pavankumarkema/trafficforecastingindia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pavankumarkema/trafficforecastingindia
- Repository: https://github.com/pavankumarkema/trafficforecastingindia

## Overview

This repository is a traffic-forecasting research system with a Streamlit commute dashboard. Its modeling workflow ingests PEMS-BAY or Bengaluru traffic, sanitizes time series, constructs spatial graphs, trains a benchmark model, adapts it to Bengaluru, and evaluates held-out forecasts. The model combines graph convolution, BiLSTM and temporal attention; separate explainability utilities analyze attention. The dashboard’s advertised commute and visualization features are documented, but the sampled app excerpt does not show how it obtains model predictions. Edges reflect shown calls or README workflow statements; unsampled wiring is omitted.

Main entry points: [`train_transfer.py`](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_transfer.py) (Bengaluru fine-tuning), [`train_base.py`](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_base.py) (Base training), [`app.py`](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py) (Commute dashboard), [`src/data_loader.py`](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/data_loader.py) (Dataset loaders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Traffic ingestion"]
  node_loader["Dataset loaders<br/>[data_loader.py]"]
  node_sanitizer["Time-series preparation<br/>[preprocessor.py]"]
end

subgraph group_modeling["Forecast modeling"]
  node_graph["Spatial graph builder"]
  node_base_train["Base training<br/>[train_base.py]"]
  node_network["Forecast network<br/>[models.py]"]
  node_base_checkpoint["PEMS-BAY checkpoint<br/>[pems_bay_base.pth]"]
  node_transfer_train["Bengaluru fine-tuning<br/>[train_transfer.py]"]
  node_transfer_engine["Weight adaptation"]
  node_target_checkpoint["Bengaluru checkpoint"]
end

subgraph group_evaluation["Evaluation"]
  node_interpretability["Attention analysis<br/>[explainability.py]"]
  node_paper_eval["Held-out evaluation"]
  node_metrics["Forecast metrics<br/>[paper_metrics.csv]"]
end

subgraph group_product["Commute experience"]
  node_dashboard["Commute dashboard<br/>[app.py]"]
  node_route_tools["Route and travel estimates<br/>[app.py]"]
  node_traffic_map["Interactive traffic map<br/>[app.py]"]
  node_benchmark_view["Benchmark comparison<br/>[app.py]"]
end

node_commuters(("Commuters"))
node_pems["PEMS-BAY data<br/>[PEMS-BAY.csv]"]
node_bangalore["Bengaluru routes"]

node_pems -->|"loads"| node_loader
node_bangalore -->|"loads"| node_loader
node_loader -->|"supplies data"| node_base_train
node_sanitizer -->|"prepares sequences"| node_base_train
node_graph -->|"builds adjacency"| node_base_train
node_base_train -->|"trains"| node_network
node_base_train -->|"saves weights"| node_base_checkpoint
node_loader -->|"supplies data"| node_transfer_train
node_sanitizer -->|"prepares sequences"| node_transfer_train
node_graph -->|"builds adjacency"| node_transfer_train
node_base_checkpoint -->|"provides weights"| node_transfer_train
node_transfer_train -->|"fine-tunes"| node_network
node_transfer_train -.->|"saves weights"| node_target_checkpoint
node_transfer_engine -->|"adapts parameters"| node_network
node_transfer_train -.->|"uses adaptation"| node_transfer_engine
node_target_checkpoint -->|"provides model"| node_paper_eval
node_sanitizer -->|"transforms data"| node_paper_eval
node_graph -->|"builds adjacency"| node_paper_eval
node_paper_eval -->|"exports metrics"| node_metrics
node_network -.->|"provides attention"| node_interpretability
node_commuters -->|"use"| node_dashboard
node_dashboard -->|"offers routing"| node_route_tools
node_dashboard -->|"renders map"| node_traffic_map
node_dashboard -->|"shows comparison"| node_benchmark_view

click node_pems "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/data/PEMS-BAY.csv"
click node_bangalore "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/data/bangalore_routes.csv"
click node_loader "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/data_loader.py"
click node_sanitizer "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/preprocessor.py"
click node_graph "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/graph_constructor.py"
click node_base_train "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_base.py"
click node_network "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/models.py"
click node_base_checkpoint "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/models/pems_bay_base.pth"
click node_transfer_train "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_transfer.py"
click node_transfer_engine "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/transfer_learner.py"
click node_target_checkpoint "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/models/bangalore_transfer_model.pth"
click node_interpretability "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/explainability.py"
click node_paper_eval "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/generate_paper_results.py"
click node_metrics "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/results/paper_metrics.csv"
click node_dashboard "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py"
click node_route_tools "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py"
click node_traffic_map "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py"
click node_benchmark_view "https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py"

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_loader,node_sanitizer toneBlue
class node_graph,node_base_train,node_network,node_base_checkpoint,node_transfer_train,node_transfer_engine,node_target_checkpoint toneAmber
class node_interpretability,node_paper_eval,node_metrics,node_bangalore toneMint
class node_dashboard,node_route_tools,node_traffic_map,node_benchmark_view toneRose
class node_commuters toneIndigo
class node_pems toneTeal
```

## Components

### Traffic ingestion

- [Dataset loaders](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/data_loader.py): `src/data_loader.py`
- [Time-series preparation](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/preprocessor.py): `src/preprocessor.py`

### Forecast modeling

- [Spatial graph builder](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/graph_constructor.py): `src/graph_constructor.py`
- [Base training](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_base.py): `train_base.py`
- [Forecast network](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/models.py): `src/models.py`
- [PEMS-BAY checkpoint](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/models/pems_bay_base.pth): `models/pems_bay_base.pth`
- [Bengaluru fine-tuning](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/train_transfer.py): `train_transfer.py`
- [Weight adaptation](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/transfer_learner.py): `src/transfer_learner.py`
- [Bengaluru checkpoint](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/models/bangalore_transfer_model.pth): `models/bangalore_transfer_model.pth`

### Evaluation

- [Attention analysis](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/src/explainability.py): `src/explainability.py`
- [Held-out evaluation](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/generate_paper_results.py): `generate_paper_results.py`
- [Forecast metrics](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/results/paper_metrics.csv): `results/paper_metrics.csv`

### Commute experience

- [Commute dashboard](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py): `app.py`
- [Route and travel estimates](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py): `app.py`
- [Interactive traffic map](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py): `app.py`
- [Benchmark comparison](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/app.py): `app.py`

### Other components

- **Commuters**
- [PEMS-BAY data](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/data/PEMS-BAY.csv): `data/PEMS-BAY.csv`
- [Bengaluru routes](https://github.com/pavankumarkema/trafficforecastingindia/blob/main/data/bangalore_routes.csv): `data/bangalore_routes.csv`

## Connections

- PEMS-BAY data → Dataset loaders: loads (evidence: `README.md`)
- Bengaluru routes → Dataset loaders: loads (evidence: `README.md`)
- Dataset loaders → Base training: supplies data (evidence: `train_base.py`)
- Time-series preparation → Base training: prepares sequences (evidence: `train_base.py`)
- Spatial graph builder → Base training: builds adjacency (evidence: `train_base.py`)
- Base training → Forecast network: trains (evidence: `train_base.py`)
- Base training → PEMS-BAY checkpoint: saves weights (evidence: `train_base.py`)
- Dataset loaders → Bengaluru fine-tuning: supplies data (evidence: `train_transfer.py`)
- Time-series preparation → Bengaluru fine-tuning: prepares sequences (evidence: `train_transfer.py`)
- Spatial graph builder → Bengaluru fine-tuning: builds adjacency (evidence: `train_transfer.py`)
- PEMS-BAY checkpoint → Bengaluru fine-tuning: provides weights (evidence: `train_transfer.py`)
- Bengaluru fine-tuning → Forecast network: fine-tunes (evidence: `train_transfer.py`)
- Bengaluru fine-tuning → Bengaluru checkpoint: saves weights
- Weight adaptation → Forecast network: adapts parameters (evidence: `src/transfer_learner.py`)
- Bengaluru fine-tuning → Weight adaptation: uses adaptation
- Bengaluru checkpoint → Held-out evaluation: provides model (evidence: `generate_paper_results.py`)
- Time-series preparation → Held-out evaluation: transforms data (evidence: `generate_paper_results.py`)
- Spatial graph builder → Held-out evaluation: builds adjacency (evidence: `generate_paper_results.py`)
- Held-out evaluation → Forecast metrics: exports metrics (evidence: `generate_paper_results.py`)
- Forecast network → Attention analysis: provides attention
- Commuters → Commute dashboard: use (evidence: `README.md`)
- Commute dashboard → Route and travel estimates: offers routing (evidence: `README.md`)
- Commute dashboard → Interactive traffic map: renders map (evidence: `README.md`)
- Commute dashboard → Benchmark comparison: shows comparison (evidence: `README.md`)
