Skip to content

TemporalOrderDataset can assign both labels to zero-distance window pairs #92

Description

@gchindemi

Problem

TemporalOrderDataset can select the same frame for both the pre- and post-window in both label classes.

Positive sampling includes frame_idx_pre:

frame_idx_post = torch.randint(
    frame_idx_pre,
    self.window_selector.lengths[rec_idx_pre],
    ...
)

Strict-negative sampling also includes frame_idx_pre:

frame_idx_post = torch.randint(
    0,
    frame_idx_pre + 1,
    ...
)

Therefore, when frame_idx_post == frame_idx_pre, x_pre and x_post are identical. Their concatenation produces the same model input regardless
of whether the label is positive or negative.

This is guaranteed at certain boundaries:

  • A strict-negative sample whose pre-frame is the first frame.
  • A positive sample whose pre-frame is the final frame.

It can also occur randomly elsewhere in a recording.

This appears to be a residual ambiguity following #55 and #56 rather than the original positive-sampling bug addressed there.

Expected behavior

For the strict method, temporal relationships should be unambiguous:

  • Positive: frame_idx_post > frame_idx_pre
  • Negative: frame_idx_post < frame_idx_pre

The same pre/post pair should never receive both labels.

Suggested resolution

Exclude zero-distance pairs and handle sequence boundaries explicitly. Possible approaches include:

  1. Resample the pre-frame when the requested class is impossible at that boundary.
  2. Sample the pre-frame from a class-specific valid range.
  3. Resample the class while preserving the intended class balance.

The implementation should avoid introducing class imbalance or an unbounded retry loop for very short records.

Tests

Use the existing pre_coords and post_coords debugging attributes to verify that:

  • Positive samples always satisfy post > pre.
  • Strict-negative samples always satisfy post < pre.
  • Zero-distance pairs are never produced.
  • First-frame and final-frame boundary cases terminate correctly.
  • Seeded sampling remains deterministic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions