concepts.vision.fm_match.diff3f.diff3f_utils.cosine_similarity_batch#

cosine_similarity_batch(a, b, batch_size=30000)[source]#

Compute the cosine similarity between two tensors in a batch manner.

Parameters:
  • a (Tensor) – A tensor of shape (N, D).

  • b (Tensor) – A tensor of shape (M, D).

  • batch_size (int) – The batch size.

Returns:

A tensor of shape (N, M) containing the cosine similarity between each pair of vectors.

Return type:

Tensor