Skip to content

Task/fix tracklet generation bug#103

Merged
bergsalex merged 7 commits into
mainfrom
task/fix-tracklet-generation-bug
Oct 15, 2025
Merged

Task/fix tracklet generation bug#103
bergsalex merged 7 commits into
mainfrom
task/fix-tracklet-generation-bug

Conversation

@bergsalex
Copy link
Copy Markdown
Collaborator

@bergsalex bergsalex commented Oct 14, 2025

Bug Fix: IndexError in Tracklet Matching

Problem

The vectorized tracklet matching algorithm crashes with an IndexError when processing video frames that contain zero detections. This occurs during the pose distance computation in compute_vectorized_pose_distances().

Error:

IndexError: too many indices for array: array is 1-dimensional, but 3 were indexed

Stack trace location:

File "vectorized_features.py", line 140, in compute_vectorized_pose_distances
    diff = poses1[:, None, :, :] - poses2[None, :, :, :]

Root Cause

The VectorizedDetectionFeatures._extract_poses() method incorrectly handles empty detection lists. When a frame contains zero detections:

  1. The method creates an empty list: poses = []
  2. Converts it to a NumPy array: np.array([], dtype=np.float64)
  3. This produces a 1D empty array with shape (0,) instead of the expected 3D empty array with shape (0, 12, 2)

When the vectorized distance computation attempts to broadcast arrays for comparison:

poses1[:, None, :, :]  # Shape: (n1, 1, 12, 2)
poses2[None, :, :, :]  # Expected: (1, n2, 12, 2), but got: (0,)

The indexing operation poses2[None, :, :, :] expects a 3D array but receives a 1D array, triggering the IndexError.

Solution

Added an explicit check in _extract_poses() to return a properly shaped empty array when no detections are present:

def _extract_poses(self, detections: list[Detection]) -> np.ndarray:
    """Extract pose data into a vectorized array."""
    if len(detections) == 0:
        # Return properly shaped empty array for broadcasting compatibility
        return np.zeros((0, 12, 2), dtype=np.float64)

    poses = []
    for det in detections:
        # ... existing logic ...
    return np.array(poses, dtype=np.float64)

This ensures that even when n_detections = 0, the poses array maintains the correct 3D shape (0, 12, 2), allowing NumPy broadcasting operations to work correctly.

@bergsalex bergsalex self-assigned this Oct 14, 2025
@bergsalex bergsalex added the bug Something isn't working label Oct 14, 2025
@bergsalex bergsalex marked this pull request as ready for review October 14, 2025 20:05
@bergsalex bergsalex merged commit 623d3ac into main Oct 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants