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

What is the threshold range of cosine similarity of reid feature? #263

Open
jiachane opened this issue Jul 3, 2023 · 0 comments
Open

Comments

@jiachane
Copy link

jiachane commented Jul 3, 2023

def _cosine_distance(a, b, data_is_normalized=False):
"""Compute pair-wise cosine distance between points in a and b.

Parameters
----------
a : array_like
    An NxM matrix of N samples of dimensionality M.
b : array_like
    An LxM matrix of L samples of dimensionality M.
data_is_normalized : Optional[bool]
    If True, assumes rows in a and b are unit length vectors.
    Otherwise, a and b are explicitly normalized to lenght 1.

Returns
-------
ndarray
    Returns a matrix of size len(a), len(b) such that eleement (i, j)
    contains the squared distance between `a[i]` and `b[j]`.

"""
if not data_is_normalized:
    a = np.asarray(a) / np.linalg.norm(a, axis=1, keepdims=True)
    b = np.asarray(b) / np.linalg.norm(b, axis=1, keepdims=True)
return 1. - np.dot(a, b.T)

When calculating the cosine similarity of feature according to the above function, the range of feature a and feature b after matrix operation is between [-1,1], and finally returns between [0,2], is this true? However, when using the test in the project, we found no similarity of more than 1 in any case, why is this?

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

No branches or pull requests

1 participant