Skip to content

Conversation

@tonylampada
Copy link

Fixes issue roboflow/roboflow-train#621

Problem

Training crashes with ValueError: matrix contains invalid numeric entries during Hungarian matching.

Root Cause

Empty masks in the dataset → zero-area bounding boxes [0,0,0,0] → division by zero in IoU computation → NaN values in cost matrix → linear_sum_assignment() fails.

Solution

Added epsilon (1e-7) to prevent division by zero in all IoU functions:

  • box_iou()
  • generalized_box_iou()
  • fast_diag_generalized_box_iou()
  • fast_diag_box_iou()

Now degenerate boxes produce valid numeric values (0.0) instead of NaN.

Changes

  • Modified sam3/model/box_ops.py: Added + 1e-7 to denominators in division operations

Testing

Needs testing with dataset HI0BxdvsF6yr904ixw3y that originally triggered the issue.

🤖 Generated with Claude Code

Fixes issue #621 in roboflow-train where training crashes with
"matrix contains invalid numeric entries" error.

Root cause: Empty masks in the dataset are converted to zero-area
bounding boxes [0,0,0,0]. When these boxes are used in IoU
computation during Hungarian matching, division by zero produces
NaN values that propagate to the cost matrix, causing
linear_sum_assignment to fail.

Solution: Add epsilon (1e-7) to all division operations in IoU
functions to prevent division by zero:
- box_iou(): iou = inter / (union + 1e-7)
- generalized_box_iou(): ... / (area + 1e-7)
- fast_diag_generalized_box_iou()
- fast_diag_box_iou()

This ensures valid numeric values (0.0 for empty boxes) instead of
NaN, allowing training to proceed even with degenerate boxes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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