Skip to content

feat: collision check for data augmentation#98

Open
rej55 wants to merge 3 commits into
tier4-mainfrom
feat/augmentation_filtering
Open

feat: collision check for data augmentation#98
rej55 wants to merge 3 commits into
tier4-mainfrom
feat/augmentation_filtering

Conversation

@rej55
Copy link
Copy Markdown

@rej55 rej55 commented May 20, 2026

Description

Overview

Adds a validity filter to StatePerturbation (ego-state perturbation for data augmentation) that rejects perturbed samples where the augmented ego position would cause a physical collision.
Without this filter, a randomly perturbed ego can overlap with surrounding objects or cross a lane boundary, introducing physically impossible training examples.

Changes

diffusion_planner/utils/data_augmentation.py

New module-level geometry utilities (pure functions, no side effects):

Function Role
_cross2d 2D cross product — core primitive for intersection tests
_rect_corners Converts (x, y, cos_h, sin_h, length, width) → 4 corner points [B, 4, 2]
_sat_signed_distance SAT (Separating Axis Theorem) signed distance between two rectangles; negative = overlap
_segments_intersect_rect Checks whether any of N line segments intersects a rectangle, using both edge-crossing and point-in-polygon tests

New StatePerturbation._check_aug_validity method:

Returns a [B] bool tensor (True = invalid) based on two conditions:

  1. Ego vs. neighbor polygon — SAT signed distance < 0 for any valid neighbor agent (uses neighbor_agents_past[:, :, -1, :] for the current timestep; per-agent size from feature indices 6/7)
  2. Ego vs. lane boundary segments — left boundary (lanes[..., :2] + lanes[..., 4:6]) and right boundary (lanes[..., :2] + lanes[..., 6:8]) consecutive waypoint segments that intersect the ego rectangle. Boundary sides with offset norm ≤ 0.01 m are treated as absent and skipped.

Ego vehicle size is read from inputs["ego_shape"][:, 1:2] (length) and [:, 2:3] (width) when available, with fallback to module-level constants EGO_LENGTH = 5.0 and EGO_WIDTH = 2.0.

StatePerturbation.augment update:

collision = self._check_aug_validity(ego_current_state, inputs)
aug_flag = aug_flag & ~collision

Samples flagged as invalid retain their original (unperturbed) ego state.

diffusion_planner/tests/test_data_augmentation.py

Added 33 new tests (26 → 59 total), covering:

  • _cross2d, _rect_corners, _sat_signed_distance, _segments_intersect_rect
    • unit tests for all geometry primitives
  • _check_aug_validity
    • neighbour overlap/clear, left/right boundary cross/clear, zero-offset ignored, ego_shape override, batch mixed
  • augment integration
    • collision suppresses aug_flag, no-collision preserves it, batch selective suppression

How to test

Run the unit test suite:

cd diffusion_planner
python tests/test_data_augmentation.py
# Expected: Results: 59/59 passed, 0 failed

# or with pytest
pytest tests/test_data_augmentation.py -v

rej55 added 2 commits May 20, 2026 11:34
Signed-off-by: Fumiya Watanabe <fumiya.watanabe.44@gmail.com>
Signed-off-by: Fumiya Watanabe <fumiya.watanabe.44@gmail.com>
@rej55 rej55 marked this pull request as ready for review May 22, 2026 07:56
Comment thread diffusion_planner/diffusion_planner/utils/data_augmentation.py Outdated
Signed-off-by: Fumiya Watanabe <fumiya.watanabe.44@gmail.com>
@SakodaShintaro
Copy link
Copy Markdown

SakodaShintaro commented May 25, 2026

I've started the training. I'll check the results and merge it if there's no deterioration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants