f110_scripts.train package¶
Submodules¶
f110_scripts.train.eval_nn module¶
eval_nn.py – Print a summary table of best validation metrics for all trained models.
Reads TFEvents logs from data/models/lightning_logs/ and reports the best (minimum) val/loss (MSE) and val/mae achieved across all epochs for every model version found. The reported values correspond to the checkpoint that ModelCheckpoint would have saved.
- Usage (from the repo root with the venv active):
python packages/f110_scripts/src/f110_scripts/train/eval_nn.py
- f110_scripts.train.eval_nn.main() None¶
Print a summary table of best validation metrics from TensorBoard logs.
f110_scripts.train.train_nn module¶
Advanced training script for F1Tenth LiDAR DNN models using PyTorch Lightning. Supports YAML configuration, advanced dataloading, and automatic tuning.
- class f110_scripts.train.train_nn.LidarDataModule(config: dict[str, Any])¶
Bases:
LightningDataModuleLightning DataModule managing dataset splitting and data loader creation.
- setup(stage: str | None = None) None¶
Loads and splits the dataset.
- Parameters:
stage – Current stage (fit, test, etc.).
- train_dataloader() DataLoader¶
Creates the training data loader.
- val_dataloader() DataLoader¶
Creates the validation data loader.
- class f110_scripts.train.train_nn.LidarDataset(data_path: str, target_col: str)¶
Bases:
DatasetAdvanced LiDAR Dataset with memory-resident caching.
- x¶
Normalized LiDAR scans.
- Type:
np.ndarray
- y¶
Target values (heading_error, left_wall_dist, or track_width).
- Type:
np.ndarray
- class f110_scripts.train.train_nn.LidarLightningModule(arch_id: int, **kwargs: Any)¶
Bases:
LightningModuleLightningModule wrapping the F1Tenth LiDAR neural network architectures.
- configure_optimizers() dict[str, Any]¶
Configures the optimizer and LR scheduler.
- forward(*args: Any, **kwargs: Any) Tensor¶
Performs a forward pass.
- Parameters:
*args – Should contain the input LiDAR tensor at index 0.
**kwargs – Additional keyword arguments.
- Returns:
Network output tensor.
- on_after_backward() None¶
Logs gradient norms to monitor training stability.
- on_train_batch_end(*args: Any, **kwargs: Any) None¶
Logs system metrics such as GPU memory usage.
- on_train_epoch_end() None¶
Logs weight histograms for architecture debugging.
- training_step(*args: Any, **kwargs: Any) Tensor¶
Executes a training step.
- Parameters:
*args – Should contain (batch, batch_idx).
**kwargs – Additional keyword arguments.
- Returns:
Calculated loss for the step.
- validation_step(*args: Any, **kwargs: Any) Tensor¶
Executes a validation step.
- Parameters:
*args – Should contain (batch, batch_idx).
**kwargs – Additional keyword arguments.
- Returns:
Calculated loss for the step.
- f110_scripts.train.train_nn.main() None¶
Main entry point for the training script.
- f110_scripts.train.train_nn.run_single_training(config: dict[str, Any], arch_id: int) None¶
Run a single training session for a specific architecture.
Checkpoint behaviour is controlled by two YAML flags:
- resume: true/false — whether to load model weights from the last
checkpoint. When false, training always starts from random initialisation and resume_weights_only is irrelevant.
- resume_weights_only: true — when resume is also true, load only the model
weights and start the optimizer/scheduler from scratch (useful after a cosine-schedule run where the LR has decayed to ~0). When false (default), full Lightning restore: weights + optimizer + scheduler + epoch counter are all restored.
Decision table ────────────── resume=false, resume_weights_only=any → random weights, fresh optimizer resume=true, resume_weights_only=false → weights from ckpt, optimizer from ckpt resume=true, resume_weights_only=true → weights from ckpt, fresh optimizer
f110_scripts.train.train_rl module¶
Simple script to train an RL policy for cloud scheduling.
This script uses Stable Baselines3 to learn a binary scheduler policy using the
f110_gym:f110-cloud-scheduler-v0 environment. The CLI exposes a few key
hyperparameters; the training loop is intentionally minimal.
Usage example:
python scripts/train/train_rl.py --map data/maps/F1/Oschersleben/Oschersleben_map --waypoints data/maps/F1/Oschersleben/Oschersleben_centerline.tsv --cloud-latency 10 --timesteps 1000000 --save-path data/models/cloud_scheduler.zip
The trained policy is saved in the provided --save-path.
- f110_scripts.train.train_rl.main() None¶
Entry point: parse args, build environment, train, and save the policy.
- f110_scripts.train.train_rl.parse_args() Namespace¶
Parse command-line arguments for RL training.