Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect point filtering logic in load_valid_labels() #156

Open
ry-immr opened this issue Jan 21, 2025 · 0 comments
Open

Incorrect point filtering logic in load_valid_labels() #156

ry-immr opened this issue Jan 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ry-immr
Copy link

ry-immr commented Jan 21, 2025

Describe the bug

The load_valid_labels() function in yolo/tools/data_loader.py currently filters coordinates element-wise, as shown below:

valid_points = points[(points >= 0) & (points <= 1)].reshape(-1, 2)

Because some rows can be partially filtered out, this can disrupt the 2D structure of the coordinate pairs.

A more appropriate approach would be:

valid_points = points[np.all((points >= 0) & (points <= 1), axis=1)]

This ensures that each pair of coordinates (rows) is checked together, filtering only those points that satisfy the conditions (coord >= 0 and coord <= 1) across both axes.

To Reproduce

Consider the following points:

points = np.array([[0.1, 0.1], [1.1, 0.1], [1.1, 0.8], [0.1, 0.8]])

With the current logic:

>>> (points >= 0) & (points <= 1)
array([[ True,  True],
       [False,  True],
       [False,  True],
       [ True,  True]])
>>> points[(points >= 0) & (points <= 1)].reshape(-1, 2)
array([[0.1, 0.1],
       [0.1, 0.8],
       [0.1, 0.8]])

With the suggested fix, the output would be:

>>> np.all((points >= 0) & (points <= 1), axis=1)
array([ True, False, False,  True])
>>> points[np.all((points >= 0) & (points <= 1), axis=1)]
array([[0.1, 0.1],
       [0.1, 0.8]])

This fix preserves each pair of coordinates, but if a bounding box has points outside [0, 1], those points are filtered out. This can lead to incomplete bounding boxes composed only of the remaining points, which no longer meaningfully represent the original bounding box.

Expected behavior

I believe that unless all points lie entirely outside the [0, 1], we should preserve the bounding box by clipping any out-of-range coordinates to [0, 1]. This helps maintain as much of the original bounding box as possible. What are your thoughts?

Screenshots

Visualization bboxes of heads using the CrowdHuman dataset.

Current filtering logic:
Image

Fixed filtering logic:
Image

@ry-immr ry-immr added the bug Something isn't working label Jan 21, 2025
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

No branches or pull requests

1 participant