# johnwtt/kalmannetforsensorfusion architecture

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

- Interactive diagram: https://gitdiagram.com/johnwtt/kalmannetforsensorfusion
- Repository: https://github.com/johnwtt/kalmannetforsensorfusion

## Overview

1. **What this repository is**
   - This is a PyTorch-based research implementation of **KalmanNet for integrated navigation/data fusion** on the NCLT dataset.
   - The codebase is organized around a standard ML pipeline: **raw sensor/ground-truth data → preprocessing → dataset objects → model training → checkpoint/export → inference/visualization**.

2. **Primary runtime and framework**
   - The core training and model code lives under `Net/`, and is centered on **Python + PyTorch**.
   - Training is launched from `train.py` and configured through files in `configs/`, which strongly suggests a config-driven experiment workflow rather than hardcoded scripts.

3. **Data ingestion boundary**
   - Raw NCLT data is handled in `data/NCLT/`.
   - `down.py` downloads sensor and ground-truth archives; `preprocess.py` converts them into the repository’s processed format.
   - The processed artifacts in `data/NCLT/processed/` are the main data interface for the rest of the system: `train.pt`, `val.pt`, `test.pt` and RTK variants (`*_rtk.pt`).

4. **Dataset layer**
   - `Net/dataset/nclt_dataset.py` and `Net/dataset/track_dataset.py` define dataset abstractions for loading the processed navigation sequences.
   - This layer is the bridge between the preprocessed `.pt` files and the model/trainer stack, likely packaging time-series inputs, targets, and possibly auxiliary measurements for fusion.

5. **Model subsystem**
   - `Net/models/kalman_net/kalman_net.py` is the core KalmanNet implementation.
   - `Net/models/kalman_net/skalman_net.py` provides a “split” variant, likely separating parts of the estimation/fusion pipeline.
   - `Net/models/fusion_net/fusion_kalman_net.py` appears to combine multiple sensing sources into the KalmanNet framework, which is the main architectural specialization in this repo.

6. **Training subsystem**
   - `Net/trainer/base_trainer.py` provides shared training/evaluation behavior.
   - `Net/trainer/fusion_trainer.py` specializes that flow for the fusion models.
   - This split indicates the repo has a general training loop plus task-specific logic for the navigation fusion use case.

7. **Experiment configuration and parameterization**
   - `configs/nclt/fusion/wheel_gpsfusion_origin.py` and `wheel_gpsfusion_split.py` define the two main experiment variants documented in the README.
   - `Net/params/make_params.py` likely builds a structured parameter object from the config, which helps keep dataset/model/trainer wiring consistent across experiments.

8. **Shared utilities**
   - `Net/utils/metrics.py` likely defines loss/error metrics such as MSE and navigation-specific evaluation.
   - `Net/utils/registry.py` suggests a registration mechanism for dynamically selecting datasets, models, or trainers from config.
   - `Net/utils/misc.py` contains supporting helpers used across the training and evaluation pipeline.

9. **Main data flow**
   - The flow is: **NCLT raw data and ground truth** are downloaded and preprocessed into `.pt` tensors.
   - Those tensors feed the dataset classes, which feed the KalmanNet/fusion models through the trainer.
   - Training produces checkpoints under `weights/`, and one trained artifact is already included in `weights/kalman560/`.

10. **Artifact outputs and deployment**
   - The repository includes `model.onnx` and `model.onnx.data`, indicating at least one exported inference representation outside pure PyTorch checkpoints.
   - This suggests the trained model can be consumed in a deployment or offline inference setting, not just during training.

11. **Inference and analysis workflow**
   - `nclt_predict.ipynb` is the primary inference/postprocessing entry point.
   - The notebook likely loads a trained checkpoint, runs prediction on test sequences, and produces geospatial outputs for visualization.

12. **Visualization boundary**
   - The `QGIS/` directory contains a prepared QGIS project and example outputs (`.kml`, `.json`) for plotting trajectories on a map.
   - The visualization layer is intentionally outside the ML pipeline: the model outputs coordinates, and QGIS is used to inspect trajectory quality and alignment against map context.

13. **Repository-specific experiment scope**
   - The current tracked configuration and artifacts focus on a single NCLT day (`2012-11-16`) and compare KalmanNet vs. split KalmanNet/fusion variants.
   - That makes this repo less of a generic framework and more of a focused experimental implementation for integrated navigation on one dataset/domain.

14. **Architectural summary**
   - The cleanest diagram would show four major boundaries:  
     **Data preparation** (`data/NCLT`) → **Learning pipeline** (`Net/dataset`, `Net/models`, `Net/trainer`, `Net/utils`, `configs`, `train.py`) → **Saved artifacts** (`weights`, `model.onnx`) → **Evaluation/visualization** (`nclt_predict.ipynb`, `QGIS/`).

Main entry points: [`Net/utils/registry.py`](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/utils/registry.py) (Registry), [`Net/trainer/base_trainer.py`](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/base_trainer.py) (Base trainer), [`Net/trainer/fusion_trainer.py`](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/fusion_trainer.py) (Fusion trainer), [`data/NCLT/processed`](https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/data/NCLT/processed) (Processed sets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data_prep["Data prep"]
  node_raw_nclt[("NCLT raw<br/>raw data")]
  node_downloader["Downloader<br/>ingest script<br/>[down.py]"]
  node_preprocess["Preprocess<br/>prep script<br/>[preprocess.py]"]
  node_processed_data[("Processed sets<br/>torch tensors")]
end

subgraph group_learning["Learning stack"]
  node_train_entry["Train entry<br/>runner<br/>[train.py]"]
  node_config_fusion["Fusion cfgs<br/>experiment config"]
  node_params_builder["Params builder<br/>config wiring<br/>[make_params.py]"]
  node_registry["Registry<br/>factory<br/>[registry.py]"]
  node_nclt_dataset["NCLT dataset<br/>[nclt_dataset.py]"]
  node_track_dataset["Track dataset<br/>[track_dataset.py]"]
  node_kalman_net["KalmanNet<br/>model<br/>[kalman_net.py]"]
  node_split_kalman["Split KalmanNet<br/>model variant<br/>[skalman_net.py]"]
  node_fusion_kalman["Fusion Kalman<br/>fusion model"]
  node_base_trainer["Base trainer<br/>[base_trainer.py]"]
  node_fusion_trainer["Fusion trainer<br/>trainer variant<br/>[fusion_trainer.py]"]
  node_metrics["Metrics<br/>eval utils<br/>[metrics.py]"]
end

subgraph group_artifacts["Artifacts"]
  node_checkpoint[("Checkpoint<br/>trained model")]
  node_onnx["ONNX export<br/>exported model<br/>[model.onnx]"]
end

subgraph group_eval["Eval and viz"]
  node_predict_nb["Predict notebook<br/>analysis notebook<br/>[nclt_predict.ipynb]"]
  node_qgis_proj["QGIS project<br/>visualization<br/>[20121116.qgz]"]
end

node_raw_nclt -->|"source"| node_downloader
node_downloader -->|"input"| node_preprocess
node_preprocess -->|"writes"| node_processed_data
node_processed_data -->|"loads"| node_nclt_dataset
node_processed_data -->|"loads"| node_track_dataset
node_config_fusion -->|"configures"| node_params_builder
node_params_builder -->|"resolves"| node_registry
node_registry -->|"selects"| node_nclt_dataset
node_registry -->|"selects"| node_kalman_net
node_registry -->|"selects"| node_fusion_kalman
node_registry -->|"selects"| node_fusion_trainer
node_train_entry -->|"loads"| node_config_fusion
node_train_entry -->|"builds"| node_params_builder
node_nclt_dataset -->|"feeds"| node_base_trainer
node_track_dataset -->|"feeds"| node_base_trainer
node_kalman_net -->|"trained by"| node_base_trainer
node_split_kalman -->|"trained by"| node_fusion_trainer
node_fusion_kalman -->|"trained by"| node_fusion_trainer
node_base_trainer -->|"evaluates"| node_metrics
node_fusion_trainer -->|"evaluates"| node_metrics
node_base_trainer -->|"saves"| node_checkpoint
node_checkpoint -->|"loads"| node_predict_nb
node_onnx -->|"loads"| node_predict_nb
node_predict_nb -->|"exports"| node_qgis_proj

click node_raw_nclt "https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/data/NCLT"
click node_downloader "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/data/NCLT/down.py"
click node_preprocess "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/data/NCLT/preprocess.py"
click node_processed_data "https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/data/NCLT/processed"
click node_train_entry "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/train.py"
click node_config_fusion "https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/configs/nclt/fusion"
click node_params_builder "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/params/make_params.py"
click node_registry "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/utils/registry.py"
click node_nclt_dataset "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/dataset/nclt_dataset.py"
click node_track_dataset "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/dataset/track_dataset.py"
click node_kalman_net "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/kalman_net/kalman_net.py"
click node_split_kalman "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/kalman_net/skalman_net.py"
click node_fusion_kalman "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/fusion_net/fusion_kalman_net.py"
click node_base_trainer "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/base_trainer.py"
click node_fusion_trainer "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/fusion_trainer.py"
click node_metrics "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/utils/metrics.py"
click node_checkpoint "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/weights/kalman560/epoch=44-val_loss=75.70-val_MSE_dB=18.79.ckpt"
click node_onnx "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/model.onnx"
click node_predict_nb "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/nclt_predict.ipynb"
click node_qgis_proj "https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/QGIS/20121116.qgz"

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_raw_nclt,node_downloader,node_preprocess,node_processed_data toneBlue
class node_train_entry,node_config_fusion,node_params_builder,node_registry,node_nclt_dataset,node_track_dataset,node_kalman_net,node_split_kalman,node_fusion_kalman,node_base_trainer,node_fusion_trainer,node_metrics toneAmber
class node_checkpoint,node_onnx toneMint
class node_predict_nb,node_qgis_proj toneRose
```

## Components

### Data prep

Raw NCLT ingestion and preprocessing into trainable sequence tensors.

- [NCLT raw](https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/data/NCLT): raw data · Source sensor and ground-truth archives for the NCLT navigation dataset. · `data/NCLT`
- [Downloader](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/data/NCLT/down.py): ingest script · Downloads the NCLT sensor and ground-truth archives. · `data/NCLT/down.py`
- [Preprocess](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/data/NCLT/preprocess.py): prep script · Converts raw NCLT data into the repository's processed tensor format. · `data/NCLT/preprocess.py`
- [Processed sets](https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/data/NCLT/processed): torch tensors · Train/val/test sequence tensors, including RTK variants, consumed by datasets. · `data/NCLT/processed`

### Learning stack

Config-driven PyTorch training, datasets, models, trainers, and utilities.

- [Train entry](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/train.py): runner · Main training entry point that launches the experiment pipeline. · `train.py`
- [Fusion cfgs](https://github.com/johnwtt/kalmannetforsensorfusion/tree/main/configs/nclt/fusion): experiment config · NCLT fusion experiment variants for origin and split KalmanNet runs. · `configs/nclt/fusion`
- [Params builder](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/params/make_params.py): config wiring · Builds structured parameters from config for dataset, model, and trainer setup. · `Net/params/make_params.py`
- [Registry](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/utils/registry.py): factory · Central selection mechanism for pluggable components such as datasets, models, or trainers. · `Net/utils/registry.py`
- [NCLT dataset](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/dataset/nclt_dataset.py): dataset · Loads processed NCLT sequences and packages inputs and targets. · `Net/dataset/nclt_dataset.py`
- [Track dataset](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/dataset/track_dataset.py): dataset · Alternative sequence dataset abstraction for trajectory-style navigation data. · `Net/dataset/track_dataset.py`
- [KalmanNet](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/kalman_net/kalman_net.py): model · Core KalmanNet implementation for learned state estimation. · `Net/models/kalman_net/kalman_net.py`
- [Split KalmanNet](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/kalman_net/skalman_net.py): model variant · Split variant of KalmanNet with separated estimation components. · `Net/models/kalman_net/skalman_net.py`
- [Fusion Kalman](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/models/fusion_net/fusion_kalman_net.py): fusion model · Fusion-oriented KalmanNet variant combining multiple sensing sources. · `Net/models/fusion_net/fusion_kalman_net.py`
- [Base trainer](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/base_trainer.py): trainer · Shared training and evaluation loop logic. · `Net/trainer/base_trainer.py`
- [Fusion trainer](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/trainer/fusion_trainer.py): trainer variant · Task-specific trainer for fusion navigation experiments. · `Net/trainer/fusion_trainer.py`
- [Metrics](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/Net/utils/metrics.py): eval utils · Loss and navigation error metrics used during training and validation. · `Net/utils/metrics.py`

### Artifacts

Saved checkpoints and exported inference models.

- [Checkpoint](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/weights/kalman560/epoch=44-val_loss=75.70-val_MSE_dB=18.79.ckpt): trained model · Saved PyTorch checkpoint for a trained KalmanNet run. · `weights/kalman560/epoch=44-val_loss=75.70-val_MSE_dB=18.79.ckpt`
- [ONNX export](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/model.onnx): exported model · Exported inference representation for deployment or offline use. · `model.onnx`

### Eval and viz

Prediction notebook and QGIS-based trajectory inspection.

- [Predict notebook](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/nclt_predict.ipynb): analysis notebook · Loads a trained model and runs prediction/postprocessing on NCLT sequences. · `nclt_predict.ipynb`
- [QGIS project](https://github.com/johnwtt/kalmannetforsensorfusion/blob/main/QGIS/20121116.qgz): visualization · Map-based trajectory inspection project and output artifacts. · `QGIS/20121116.qgz`

## Connections

- NCLT raw → Downloader: source · Raw NCLT archives are fetched by the downloader.
- Downloader → Preprocess: input · Downloaded archives are consumed by preprocessing.
- Preprocess → Processed sets: writes · Preprocessing generates train/val/test tensor files.
- Processed sets → NCLT dataset: loads · The NCLT dataset reads processed tensor splits.
- Processed sets → Track dataset: loads · Track-style dataset abstractions also consume processed sequences.
- Fusion cfgs → Params builder: configures · Experiment configs are transformed into runtime parameters.
- Params builder → Registry: resolves · Parameters are used to resolve component implementations.
- Registry → NCLT dataset: selects · Dataset implementation is selected through the registry path.
- Registry → KalmanNet: selects · Core model implementation can be selected dynamically.
- Registry → Fusion Kalman: selects · Fusion model variant can be selected dynamically.
- Registry → Fusion trainer: selects · Trainer implementation can be selected dynamically.
- Train entry → Fusion cfgs: loads · Training starts from a config-defined experiment.
- Train entry → Params builder: builds · The entry point builds structured parameters for the run.
- NCLT dataset → Base trainer: feeds · Dataset batches are consumed by the training loop.
- Track dataset → Base trainer: feeds · Trajectory dataset batches can also feed the trainer stack.
- KalmanNet → Base trainer: trained by · Base trainer optimizes the core KalmanNet model.
- Split KalmanNet → Fusion trainer: trained by · Fusion trainer can specialize around the split variant.
- Fusion Kalman → Fusion trainer: trained by · Fusion trainer drives the fusion model experiments.
- Base trainer → Metrics: evaluates · Training and validation use shared metrics.
- Fusion trainer → Metrics: evaluates · Fusion-specific evaluation also uses shared metrics.
- Base trainer → Checkpoint: saves · Trained weights are persisted as checkpoints.
- Checkpoint → Predict notebook: loads · The notebook loads saved checkpoints for inference.
- ONNX export → Predict notebook: loads · Exported ONNX artifacts support downstream inference.
- Predict notebook → QGIS project: exports · Prediction outputs are prepared for QGIS visualization.
