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

Fix implementation of max distance hyperparam for track linking #83

Closed
shaikh58 opened this issue Sep 30, 2024 · 1 comment · Fixed by #103 · May be fixed by #78
Closed

Fix implementation of max distance hyperparam for track linking #83

shaikh58 opened this issue Sep 30, 2024 · 1 comment · Fixed by #103 · May be fixed by #78

Comments

@shaikh58
Copy link
Contributor

shaikh58 commented Sep 30, 2024

In inference/post_processing.py, function filter_max_center_dist attempts to modify the association matrix during the track assignment step. Its current intent is to disallow track linking if an instance is max_center_dist pixels away from all other instances in the window. However, similar to TrackMate's LAP tracker, a definition that makes more sense is to disallow track linking if an instance is max_center_dist away from the instances in just the previous frame. There are other bugs i.e. with normalizing the distance, and with units; currently distances are in units of fractions of height/width of image; we want the max_center_dist to be in pixels so scale by image height and width

Current:

def filter_max_center_dist(
    asso_output: torch.Tensor,
    max_center_dist: float = 0,
    k_boxes: torch.Tensor | None = None,
    nonk_boxes: torch.Tensor | None = None,
    id_inds: torch.Tensor | None = None,
) -> torch.Tensor:
    """Filter trajectory score by distances between objects across frames.

    Args:
        asso_output: An N_t x N association matrix
        max_center_dist: The euclidean distance threshold between bboxes
        k_boxes: The bounding boxes in the current frame
        nonk_boxes: the boxes not in the current frame
        id_inds: track ids

    Returns:
        An N_t x N association matrix
    """
    if max_center_dist is not None and max_center_dist > 0:
        assert (
            k_boxes is not None and nonk_boxes is not None and id_inds is not None
        ), "Need `k_boxes`, `nonk_boxes`, and `id_ind` to filter by `max_center_dist`"
        k_ct = (k_boxes[:, :, :2] + k_boxes[:, :, 2:]) / 2
        k_s = ((k_boxes[:, :, 2:] - k_boxes[:, :, :2]) ** 2).sum(dim=2)  # n_k

        nonk_ct = (nonk_boxes[:, :, :2] + nonk_boxes[:, :, 2:]) / 2

        dist = ((k_ct[:, None, :, :] - nonk_ct[None, :, :, :]) ** 2).sum(
            dim=-1
        )  # n_k x Np

        norm_dist = dist / (k_s[:, None, :] + 1e-8)
        norm_dist = dist.mean(axis=-1)  # n_k x Np

        valid = norm_dist < max_center_dist  # n_k x Np
        valid_assn = (
            torch.mm(valid.float(), id_inds.to(valid.device))
            .clamp_(max=1.0)
            .long()
            .bool()
        )  # n_k x M
        asso_output_filtered = asso_output.clone()
        asso_output_filtered[~valid_assn] = 0  # n_k x M
        return asso_output_filtered
    else:
        return asso_output```
@shaikh58
Copy link
Contributor Author

shaikh58 commented Dec 5, 2024

WIP on branch mustafa-fix-max-center-dist

@shaikh58 shaikh58 linked a pull request Dec 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant