This repository contains the code for my Masters Thesis in "Context-Aware Pedestrian Trajectory Prediction in
Urban Scenarios Using Data-Driven Methods", which was done with Scania. This repository provides code for building pedestrian-centered trajectory
prediction datasets and training/evaluating context-aware prediction models.
The main dataset format used by the project is ped_context_map: each sample
contains the target pedestrian history, future trajectory, nearby agents, ego
motion, and vector map context.
The code supports nuScenes as the main dataset and includes the Snapshot preprocessing code for Argoverse 2 as a separate third-party component.
Create a Python environment and install the project requirements:
pip install -r requirements.txtThe model code uses PyTorch. If PyTorch is not already available in your environment, install the version that matches your CUDA setup from the official PyTorch instructions.
The nuScenes preprocessing depends on the bundled nuscenes-devkit/ folder. The
requirements file installs the devkit dependencies used by this project.
config.py Main paths and default settings
src/preprocessing/ Dataset generation scripts
src/baseline/ Dataset loaders and shared baseline utilities
src/models/ Model definitions, training scripts, and checkpoint evaluation
src/strat_eval/ Stratified evaluation tools
src/utils/ Shared training, validation, and visualization helpers
src/viz/ Visualization scripts
src/legacy/ Older scripts not required for the main workflow
nuscenes-devkit/ nuScenes devkit used for dataset access and maps
snapshot/ Snapshot preprocessing code for Argoverse 2
The most important path setting is DATASET_ROOT in config.py. By default it
points to dataset/ inside this repository. You can override it with:
export NUSCENES_DATASET_ROOT=/path/to/datasetOn Windows PowerShell:
$env:NUSCENES_DATASET_ROOT="C:\path\to\dataset"Download the official nuScenes metadata from https://www.nuscenes.org/nuscenes#download. For this project you need:
Full Dataset (v1.0) Trainvalmetadata- the nuScenes map expansion pack
You do not need the full camera videos for the preprocessing used here. The expected folder layout is:
dataset/
v1.0-trainval/
maps/
expansion/
First build the per-scene all-object tensors:
python src/preprocessing/build_all_tracks_dataset.py \
--dataset-folder v1.0-trainvalThis writes scene files to dataset/preprocessed/all_tracks/ and creates the
train/val/test scene split.
Then build the pedestrian context map dataset:
python src/preprocessing/build_ped_context_map_dataset.py \
--dataset-folder v1.0-trainval \
--output-root dataset/preprocessed/ped_context_map_v2This creates the final pedestrian-centered dataset shards, split indices, and
manifest.json under dataset/preprocessed/ped_context_map_v2/.
For a quick smoke test, use --dataset-folder v1.0-mini --max-scenes 1 in the
second command.
The snapshot/ folder contains Snapshot preprocessing code. Its own README.md
and LICENSE are kept in that folder because this part is not entirely my own
work.
To generate the Argoverse 2 data for this project:
- Follow the instructions in
snapshot/README.mdto create the standard Snapshot dataset files. - Adapt
DEFAULT_SOURCE_ROOTandDEFAULT_OUTPUT_ROOTinsnapshot/src/preprocessing/build_av2_ped_context_map.pyto your machine. - Run the additional preprocessing step:
python snapshot/src/preprocessing/build_av2_ped_context_map.pyThis creates the pedestrian context map data used by the rest of this project.
The main prediction pipeline trains a model on the generated ped_context_map
dataset and predicts future pedestrian trajectories on the test split. For
example, to train the PointNet model:
python src/models/train_ped_context_pointnet.py \
--data-root dataset/preprocessed/ped_context_map_v2The script saves the best checkpoint, test metrics, training curves, and example
prediction visualizations under dataset/models/ped_context_pointnet/.
Other models use the same dataset format and workflow. Their training scripts
are in src/models/train_ped_context_*.py, including PointNet, attention,
transformer, CVAE, multimodal, and Snapshot-style variants.
To evaluate an existing trajectory prediction run, use:
python src/models/eval_ped_checkpoint.py \
--run-dir dataset/models/ped_context_pointnet/run_001This reloads best_model.pt, evaluates the test split, and regenerates standard
visualizations. The evaluator can usually detect the model type automatically.
It also supports context ablations such as --motion-only, --ablate-map,
--ablate-neighbors, and --ablate-ego.
Typical outputs are:
best_model.pt
metrics.json
training_curves.png
visualizations/
The training and evaluation scripts already create the most important plots. For manual inspection, these scripts are also useful:
src/utils/export_ped_context_sample.pyexports one dataset sample for debugging.src/viz/visualize_model_input_anchors.pyvisualizes model input anchors.src/viz/visualize_anchor_model_prediction.pyvisualizes one model prediction.src/viz/compare_model_predictions_side_by_side.pycompares multiple model predictions on the same scene.
Crossing intention is handled as a separate binary classification task on top of the same pedestrian-context dataset:
python src/models/train_crossing_intention.py \
--data-root dataset/preprocessed/ped_context_map_v2The script trains a crossing/not-crossing classifier and writes metrics, checkpoints, and intent visualizations. Existing crossing-intention checkpoints can be evaluated with:
python src/models/eval_crossing_intention_checkpoint.py \
--run-dir dataset/models/crossing_intention/run_001The src/strat_eval/ folder contains tools for understanding where a model works
well or badly. It groups test results by trajectory shape, motion state,
crossing behavior, map proximity, and neighbor density.
python src/strat_eval/run_stratified_eval.py \
--run-dir dataset/models/ped_context_pointnet/run_001For multiple experiment folders, use run_batch_stratified_eval.py and summarize
the batch outputs with summarize_batch_stratified_eval.py.
This repository includes two external codebases that were useful for the dataset work:
nuscenes-devkit/is the official nuScenes devkit (https://github.com/nutonomy/nuscenes-devkit). The nuScenes preprocessing code depends on it for reading the dataset tables and map information.snapshot/contains the Snapshot repository for Argoverse 2 pedestrian trajectory preprocessing and modeling (https://github.com/TUMFTM/Snapshot). Its originalREADME.mdandLICENSEare kept inside the folder.
If you use the nuScenes or Argoverse 2/Snapshot parts of this repository, please also follow the citation and license instructions from the corresponding projects.
src/legacy/contains older scripts that were useful during development but are not required for the main prediction and evaluation pipeline.- Most generated files are written under
dataset/preprocessed/anddataset/models/. - The repository still contains some code for
Viscando_traffic_data. This is a proprietary dataset provided by Viscando, so the data itself is not publicly available.