ECAM

A Contrastive Learning Approach to Avoid Environmental Collision in Trajectory Forecasting

Human trajectory forecasting is the task of predicting where pedestrians will walk next, given where they have been. It matters for self-driving cars, social robots and video surveillance. Modern models take social interactions into account and predict several plausible futures for each person, but they often ignore the scene around them: many of the paths they predict go straight through walls, parked cars and other obstacles.

ECAM (Environmental Collision Avoidance Module) fixes this. It is a module you add to an existing forecasting model to teach it to avoid obstacles. It is only used during training, so the trained model runs exactly as fast as the original.

Two copies of the same street scene with predicted pedestrian paths. On the left, without ECAM, several predicted paths, drawn in red, run into a parked car. On the right, with ECAM, almost none do.

Predictions on the ZARA1 scene without ECAM (left) and with ECAM (right). Paths that hit an obstacle are drawn in red.

How it works

ECAM has two parts:

  • MapNCE, a contrastive learning module inspired by Social-NCE. It uses the obstacle map of the scene to generate negative examples automatically: points just around the contours of obstacles, where a pedestrian shouldn’t end up. The model’s internal representation of each pedestrian has to tell their real future position apart from these points. This pushes the model to encode where the obstacles are, instead of learning only from the positive examples in the dataset.
  • Environmental Collision loss, which penalises every predicted path that crosses an obstacle. Multi-modal models are usually trained with a best-of-N loss that only updates the prediction closest to the ground truth, and that one rarely collides. Without this extra loss the model has little reason to fix its other predictions.

The only requirement is that the underlying model takes the map as input and computes an embedding of it. For models that don’t, we added a small pre-trained CNN that encodes the map around each pedestrian.

Block diagram. An existing trajectory forecasting model encodes the pedestrian's history and the scene map into a hidden encoding, which a decoder turns into predicted paths. ECAM adds a MapNCE block whose query encoder reads the hidden encoding and whose key encoder reads one positive sample and several negative samples near obstacles. The MapNCE loss and the Environmental Collision loss are added to the model's own loss.

ECAM on top of an existing model. During training, MapNCE contrasts the true future position (green) with points near obstacles (red), and the Environmental Collision loss penalises colliding predictions.

Results

We added ECAM to three state-of-the-art models built on different architectures: EigenTrajectory-SGCN (graph convolution), EigenTrajectory-AgentFormer (transformer) and SingularTrajectory (diffusion). We evaluated them on the ETH/UCY benchmark. Collisions are measured with ECFL, the percentage of predicted paths that don’t touch an obstacle (higher is better). The better result for each model is in bold.

ModelECFL without ECAMECFL with ECAMFewer collisions
EigenTrajectory-SGCN85.91%91.97%43%
EigenTrajectory-AgentFormer87.89%93.31%45%
SingularTrajectory91.56%96.06%53%

ECAM reduced collisions for every model and every scene. The cost is a small loss in accuracy: the average displacement error grows by about 1–2 cm and the final displacement error by 3–4 cm. In safety-critical settings such as robotics, a slightly less accurate path that doesn’t go through a wall is worth more.

The ablation study on SingularTrajectory shows that both parts are needed. The collision rate drops from 8.4% to 7.4% with MapNCE alone, to 5.5% with the collision loss alone, and to 4.1% with both.

ECAM currently handles only static obstacles. Extending it to moving ones, such as vehicles, is the natural next step.

Code

The code is on GitHub. It builds on SingularTrajectory and includes the scripts to train and test each model with and without ECAM on ETH/UCY.

Citation

@inproceedings{rosin2025ecam,
  title     = {{ECAM}: A Contrastive Learning Approach to Avoid Environmental Collision in Trajectory Forecasting},
  author    = {Rosin, Giacomo and Ur Rahman, Muhammad Rameez and Vascon, Sebastiano},
  booktitle = {2025 International Joint Conference on Neural Networks (IJCNN)},
  pages     = {1--8},
  year      = {2025},
  doi       = {10.1109/IJCNN64981.2025.11229361}
}