# feliciaxyao/navmorph architecture

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

- Interactive diagram: https://gitdiagram.com/feliciaxyao/navmorph
- Repository: https://github.com/feliciaxyao/navmorph

## Overview

1. **What this repo is**
   NavMorph is a VLN-CE system for continuous navigation in Habitat. Its core architecture combines imitation learning, a self-evolving world model, and contextual memory to improve instruction-following in unseen environments.

2. **Top-level execution**
   `run.py` is the general entrypoint, while `run_r2r/main.bash` is the main orchestration script for R2R training/evaluation. The YAML files under `run_r2r/` and `vlnce_baselines/config/r2r_configs/` select experiment variants such as Seq2Seq, CMA, augmentation, and tuning modes.

3. **Environment and simulation boundary**
   The repo depends on external Habitat-Lab/Habitat-Sim and Matterport3D scenes. `vlnce_baselines/common/environments.py` and `env_utils.py` wrap the simulator, expose episode state, and normalize camera/configuration details. This is the boundary where raw scene observations become model inputs.

4. **Data and asset layer**
   Runtime assets are kept outside the code path in `data/` and `pretrained/`: datasets, scene reconstructions, pretrained visual backbones, BERT weights, waypoint predictors, and saved checkpoints. The README’s folder structure is important because many modules load weights and dataset encodings from these paths directly.

5. **Instruction understanding**
   Natural-language instructions are handled by `vlnce_baselines/models/encoders/instruction_encoder.py`, with BERT/XLM-R-related assets under `vlnce_baselines/bert-base-uncased/` and `data/instruction/`. This produces the language embedding that conditions the navigation policy and world model.

6. **Visual perception**
   Visual features come from `vlnce_baselines/models/encoders/clip.py` and `resnet_encoders.py`. These encoders turn RGB observations into compact embeddings that are fused with language and memory state. This is the main observation-to-feature path for the agent.

7. **NavMorph core world model**
   The central policy/world-model stack lives in `vlnce_baselines/models/Policy_ViewSelection_ETP.py` and the `models/etp/` package. `vilmodel_cmt.py`, `vlnbert_init.py`, and `nerf.py` indicate a multimodal transformer plus NeRF-style latent scene modeling. This is the “self-evolving world model” that predicts how the environment changes and supports lookahead planning.

8. **Memory and context evolution**
   Contextual Evolution Memory is implemented across `utils_p/memory.py`, `utils_p/prompt.py`, and related utilities. This subsystem stores scene-contextual state across time, helping the agent adapt online instead of relying only on the current observation window.

9. **Navigation decision layer**
   The action-selection/policy boundary is in `vlnce_baselines/models/policy.py`, `graph_utils.py`, and `common/transformer.py`. These modules convert fused multimodal state into navigation actions, view selection, and trajectory decisions.

10. **Waypoint and semantic mapping support**
   The `vlnce_baselines/waypoint_networks/` package is a separate perception/planning aid. `img_segmentor_model.py`, `resnetUnet.py`, and `semantic_grid.py` build semantic spatial maps and waypoint predictions, which feed the higher-level policy and are tied to the pretrained waypoint checkpoints mentioned in the README.

11. **Training loops**
   There are multiple trainer paths: `base_il_trainer.py` for imitation-learning scaffolding, `dagger_trainer.py` for dataset aggregation, and `ss_trainer_ETP.py` for the self-supervised / world-model-oriented training path. `common/recollection_dataset.py` suggests replay/recollection data support for iterative training.

12. **Losses, metrics, and evaluation**
   `utils_p/losses.py`, `utils_p/metrics.py`, and `common/aux_losses.py` provide optimization objectives and reporting. These modules separate training signals from model code, which is useful for diagramming the system as “perception/policy/model” vs. “optimization/evaluation.”

13. **Configuration and experiment management**
   `vlnce_baselines/config/default.py` plus the task-specific YAMLs define the experiment graph: dataset choice, model variant, training mode, and evaluation behavior. The README also notes dataset-specific camera settings, which are a real architectural constraint because R2R and RxR use different HFOV/VFOV assumptions.

14. **Practical dependency boundaries**
   The repo is not self-contained: it relies on Habitat, Matterport3D scenes, external pretrained encoders, and extra native/ML packages like `torch_kdtree` and `tinycudann`. Those dependencies materially shape the architecture because they determine what runs in simulation, what is learned, and what is loaded as fixed pretrained infrastructure.

Main entry points: [`vlnce_baselines/models/Policy_ViewSelection_ETP.py`](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/Policy_ViewSelection_ETP.py) (NavMorph policy), [`vlnce_baselines/common/environments.py`](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/environments.py) (env wrappers), [`vlnce_baselines/models/etp/vilmodel_cmt.py`](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/etp/vilmodel_cmt.py) (ETP stack), [`data`](https://github.com/feliciaxyao/navmorph/tree/main/data) (data & weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & runs"]
  node_run_py["run.py<br/>entrypoint<br/>[run.py]"]
  node_r2r_bash["R2R bash<br/>orchestration<br/>[main.bash]"]
end

subgraph group_env["Environment"]
  node_env_wrap["env wrappers<br/>habitat adapter<br/>[environments.py]"]
  node_env_utils["env utils<br/>simulation utils<br/>[env_utils.py]"]
end

subgraph group_models["Models"]
  node_instr_enc["instruction enc<br/>language encoder"]
  node_vis_enc["visual enc<br/>vision encoder<br/>[clip.py]"]
  node_etp_stack["ETP stack<br/>world model<br/>[vilmodel_cmt.py]"]
  node_nerf_latent["NeRF latent<br/>scene model<br/>[nerf.py]"]
  node_policy_sel["policy sel<br/>action policy<br/>[policy.py]"]
  node_policy_main["NavMorph policy<br/>policy integration"]
  node_memory_ctx["context memory<br/>online memory<br/>[memory.py]"]
  node_waypoints["waypoint net<br/>spatial planner<br/>[semantic_grid.py]"]
end

subgraph group_training["Training"]
  node_base_trainer["IL trainer<br/>[base_il_trainer.py]"]
  node_dagger["DAgger<br/>trainer<br/>[dagger_trainer.py]"]
  node_ss_etp["SS ETP<br/>trainer<br/>[ss_trainer_ETP.py]"]
  node_recollect[("recollect ds<br/>replay data")]
  node_losses["losses<br/>optimization<br/>[losses.py]"]
  node_metrics["metrics<br/>evaluation<br/>[metrics.py]"]
end

subgraph group_assets["Assets"]
  node_assets[("data & weights<br/>external assets")]
end

subgraph group_config["Config"]
  node_r2r_cfgs["R2R configs<br/>yaml variants<br/>[r2r_vlnce.yaml]"]
  node_default_cfg["default cfg<br/>config core<br/>[default.py]"]
end

node_run_py -->|"loads"| node_default_cfg
node_run_py -->|"starts"| node_env_wrap
node_r2r_bash -->|"selects"| node_r2r_cfgs
node_r2r_cfgs -->|"extends"| node_default_cfg
node_default_cfg -->|"configures"| node_env_utils
node_env_wrap -->|"uses"| node_env_utils
node_env_wrap -->|"observes"| node_instr_enc
node_env_wrap -->|"observes"| node_vis_enc
node_vis_enc -->|"features"| node_policy_main
node_instr_enc -->|"features"| node_policy_main
node_memory_ctx -->|"state"| node_policy_main
node_policy_main -->|"routes"| node_etp_stack
node_etp_stack -->|"models"| node_nerf_latent
node_etp_stack -->|"predicts"| node_policy_sel
node_waypoints -->|"guides"| node_policy_sel
node_base_trainer -->|"optimizes"| node_losses
node_base_trainer -->|"evaluates"| node_metrics
node_dagger -->|"trains on"| node_recollect
node_ss_etp -->|"trains"| node_etp_stack
node_ss_etp -->|"reuses"| node_recollect
node_policy_main -.->|"loads"| node_assets
node_instr_enc -.->|"loads"| node_assets
node_vis_enc -.->|"loads"| node_assets
node_waypoints -.->|"loads"| node_assets

click node_run_py "https://github.com/feliciaxyao/navmorph/blob/main/run.py"
click node_r2r_bash "https://github.com/feliciaxyao/navmorph/blob/main/run_r2r/main.bash"
click node_r2r_cfgs "https://github.com/feliciaxyao/navmorph/blob/main/run_r2r/r2r_vlnce.yaml"
click node_default_cfg "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/config/default.py"
click node_env_wrap "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/environments.py"
click node_env_utils "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/env_utils.py"
click node_instr_enc "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/encoders/instruction_encoder.py"
click node_vis_enc "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/encoders/clip.py"
click node_etp_stack "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/etp/vilmodel_cmt.py"
click node_nerf_latent "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/etp/nerf.py"
click node_policy_sel "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/policy.py"
click node_policy_main "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/Policy_ViewSelection_ETP.py"
click node_memory_ctx "https://github.com/feliciaxyao/navmorph/blob/main/utils_p/memory.py"
click node_waypoints "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/waypoint_networks/semantic_grid.py"
click node_base_trainer "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/base_il_trainer.py"
click node_dagger "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/dagger_trainer.py"
click node_ss_etp "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/ss_trainer_ETP.py"
click node_recollect "https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/recollection_dataset.py"
click node_losses "https://github.com/feliciaxyao/navmorph/blob/main/utils_p/losses.py"
click node_metrics "https://github.com/feliciaxyao/navmorph/blob/main/utils_p/metrics.py"
click node_assets "https://github.com/feliciaxyao/navmorph/tree/main/data"

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_run_py,node_r2r_bash toneBlue
class node_env_wrap,node_env_utils toneAmber
class node_instr_enc,node_vis_enc,node_etp_stack,node_nerf_latent,node_policy_sel,node_policy_main,node_memory_ctx,node_waypoints toneMint
class node_base_trainer,node_dagger,node_ss_etp,node_recollect,node_losses,node_metrics toneRose
class node_assets toneIndigo
class node_r2r_cfgs,node_default_cfg toneTeal
```

## Components

### Entry & runs

Top-level launch scripts and experiment selection.

- [run.py](https://github.com/feliciaxyao/navmorph/blob/main/run.py): entrypoint · General repository entrypoint. · `run.py`
- [R2R bash](https://github.com/feliciaxyao/navmorph/blob/main/run_r2r/main.bash): orchestration · Main shell orchestrator for R2R runs. · `run_r2r/main.bash`

### Environment

Habitat simulation boundary and runtime adapters.

- [env wrappers](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/environments.py): habitat adapter · Habitat environment wrappers and state normalization. · `vlnce_baselines/common/environments.py`
- [env utils](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/env_utils.py): simulation utils · Helpers for simulator setup, camera, and episode handling. · `vlnce_baselines/common/env_utils.py`

### Models

Multimodal encoders, policy, world model, and planning components.

- [instruction enc](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/encoders/instruction_encoder.py): language encoder · Encodes navigation instructions into language embeddings. · `vlnce_baselines/models/encoders/instruction_encoder.py`
- [visual enc](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/encoders/clip.py): vision encoder · RGB feature extraction via CLIP and ResNet backbones. · `vlnce_baselines/models/encoders/clip.py`
- [ETP stack](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/etp/vilmodel_cmt.py): world model · Multimodal transformer and latent scene modeling core. · `vlnce_baselines/models/etp/vilmodel_cmt.py`
- [NeRF latent](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/etp/nerf.py): scene model · NeRF-style latent scene representation used by the world model. · `vlnce_baselines/models/etp/nerf.py`
- [policy sel](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/policy.py): action policy · Navigation action selection and view choice boundary. · `vlnce_baselines/models/policy.py`
- [NavMorph policy](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/models/Policy_ViewSelection_ETP.py): policy integration · Main policy that combines encoders, memory, and ETP components. · `vlnce_baselines/models/Policy_ViewSelection_ETP.py`
- [context memory](https://github.com/feliciaxyao/navmorph/blob/main/utils_p/memory.py): online memory · Contextual evolution memory across time and episodes. · `utils_p/memory.py`
- [waypoint net](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/waypoint_networks/semantic_grid.py): spatial planner · Semantic grid and waypoint prediction support. · `vlnce_baselines/waypoint_networks/semantic_grid.py`

### Training

Training loops, datasets, losses, and evaluation support.

- [IL trainer](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/base_il_trainer.py): trainer · Imitation-learning training scaffold. · `vlnce_baselines/common/base_il_trainer.py`
- [DAgger](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/dagger_trainer.py): trainer · Dataset aggregation training path. · `vlnce_baselines/dagger_trainer.py`
- [SS ETP](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/ss_trainer_ETP.py): trainer · Self-supervised / world-model-oriented training path. · `vlnce_baselines/ss_trainer_ETP.py`
- [recollect ds](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/common/recollection_dataset.py): replay data · Recollection and replay dataset support. · `vlnce_baselines/common/recollection_dataset.py`
- [losses](https://github.com/feliciaxyao/navmorph/blob/main/utils_p/losses.py): optimization · Training objectives and auxiliary losses. · `utils_p/losses.py`
- [metrics](https://github.com/feliciaxyao/navmorph/blob/main/utils_p/metrics.py): evaluation · Reporting and success metrics. · `utils_p/metrics.py`

### Assets

External datasets, pretrained weights, and instruction resources.

- [data & weights](https://github.com/feliciaxyao/navmorph/tree/main/data): external assets · Datasets, instruction resources, pretrained backbones, and checkpoints. · `data`

### Config

Experiment configuration and task variants.

- [R2R configs](https://github.com/feliciaxyao/navmorph/blob/main/run_r2r/r2r_vlnce.yaml): yaml variants · Task and experiment variants for Seq2Seq, CMA, augmentation, and tuning. · `run_r2r/r2r_vlnce.yaml`
- [default cfg](https://github.com/feliciaxyao/navmorph/blob/main/vlnce_baselines/config/default.py): config core · Base configuration wiring for the codebase. · `vlnce_baselines/config/default.py`

## Connections

- run.py → default cfg: loads · Entry point resolves the base experiment configuration.
- run.py → env wrappers: starts · Launches training or evaluation in the Habitat environment boundary.
- R2R bash → R2R configs: selects · Shell orchestration chooses an R2R variant.
- R2R configs → default cfg: extends · Task configs build on the base configuration.
- default cfg → env utils: configures · Configuration sets simulator and camera parameters.
- env wrappers → env utils: uses · Wrappers delegate simulator setup and normalization details.
- env wrappers → instruction enc: observes · Language instructions are paired with episodes for conditioning.
- env wrappers → visual enc: observes · Raw RGB observations are exposed to visual encoders.
- visual enc → NavMorph policy: features · Vision embeddings feed the main policy stack.
- instruction enc → NavMorph policy: features · Language embeddings condition the policy and world model.
- context memory → NavMorph policy: state · Persistent context is fused into policy decisions.
- NavMorph policy → ETP stack: routes · Main policy delegates multimodal reasoning to the ETP stack.
- ETP stack → NeRF latent: models · World model maintains a latent scene representation.
- ETP stack → policy sel: predicts · Transformer outputs support action and view selection.
- waypoint net → policy sel: guides · Waypoint predictions inform navigation decisions.
- IL trainer → losses: optimizes · Trainer consumes task and auxiliary losses.
- IL trainer → metrics: evaluates · Trainer reports navigation metrics.
- DAgger → recollect ds: trains on · DAgger uses aggregated rollout data.
- SS ETP → ETP stack: trains · Self-supervised path targets the world-model stack.
- SS ETP → recollect ds: reuses · Iterative training can draw from recollection data.
- NavMorph policy → data & weights: loads · Policy and encoders rely on pretrained weights and datasets.
- instruction enc → data & weights: loads · Instruction models depend on BERT/XLM-R resources and instruction data.
- visual enc → data & weights: loads · Visual encoders use pretrained backbones and checkpoints.
- waypoint net → data & weights: loads · Waypoint module consumes pretrained waypoint models.
