InternNav uses a modular architecture consisting of Models, Agents, and Trainers. To add a new navigation algorithm, you must implement these three components.
1. Custom Model
The Model implements the neural network and inference logic. It expects an observation (obs) from the ego-centric camera and returns an action.
Observation Format (obs):
obs = [{
'globalgps': [X, Y, Z], # robot location
'globalrotation': [X, Y, Z, W], # robot orientation in quaternion
'rgb': np.array(256, 256, 3), # rgb camera image
'depth': np.array(256, 256, 1) # depth image
}]
Action Format (action):
Returns a List[int] representing actions for each environment:
0: stop1: move forward2: turn left3: turn right
Configuration: Define a Config class that inherits from PretrainedConfig (see CMAModelConfig in internnav/model/cma/cma_policy.py for reference).
Registration: Register the model in internnav/model/__init__.py using get_policy and get_config.
2. Custom Agent
The Agent wraps the Model and handles environment interaction and preprocessing. Inherit from Agent and implement:
reset(): Resets internal state (e.g., RNN states).inference(obs): Performs preprocessing and calls the model.step(obs): The external interface that calls inference.
3. Custom Trainer
The Trainer manages the training loop. Inherit from Base Trainer and implement:
train_epoch(): Handles batch iteration, forward pass, and parameter updates.eval_epoch(): Evaluates on the validation set.save_checkpoint() / load_checkpoint(): Manages model weights and state.