def length(segments):
    """Computes length of segments.

    Args:
        segments (numpy array or torch tensor): shape [N, 2] holding N
            segments.
    Returns:
        a numpy array (or torch tensor) with shape [N] representing segment
        length.
    Note:
        it works with time, it would be off if using frames.
    """
    return segments[:, 1] - segments[:, 0]