Skip to content

Commit

Permalink
[Bug Fix] fix cosine_similarity error in examples (PaddlePaddle#648)
Browse files Browse the repository at this point in the history
cosine_similarity is error

余弦相似度计算错误
np.linalg.norm 二范数 已经开过根号

Co-Authored-By: Chris Kong <chriskong93@163.com>
  • Loading branch information
2 people authored and felixhjh committed Nov 25, 2022
1 parent d98c360 commit ef49968
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/vision/faceid/insightface/python/infer_arcface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cosine_similarity(a, b):
mul_a = np.linalg.norm(a, ord=2)
mul_b = np.linalg.norm(b, ord=2)
mul_ab = np.dot(a, b)
return mul_ab / (np.sqrt(mul_a) * np.sqrt(mul_b))
return mul_ab / (mul_a * mul_b)


def parse_arguments():
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/faceid/insightface/python/infer_cosface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cosine_similarity(a, b):
mul_a = np.linalg.norm(a, ord=2)
mul_b = np.linalg.norm(b, ord=2)
mul_ab = np.dot(a, b)
return mul_ab / (np.sqrt(mul_a) * np.sqrt(mul_b))
return mul_ab / (mul_a * mul_b)


def parse_arguments():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cosine_similarity(a, b):
mul_a = np.linalg.norm(a, ord=2)
mul_b = np.linalg.norm(b, ord=2)
mul_ab = np.dot(a, b)
return mul_ab / (np.sqrt(mul_a) * np.sqrt(mul_b))
return mul_ab / (mul_a * mul_b)


def parse_arguments():
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/faceid/insightface/python/infer_vpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cosine_similarity(a, b):
mul_a = np.linalg.norm(a, ord=2)
mul_b = np.linalg.norm(b, ord=2)
mul_ab = np.dot(a, b)
return mul_ab / (np.sqrt(mul_a) * np.sqrt(mul_b))
return mul_ab / (mul_a * mul_b)


def parse_arguments():
Expand Down

0 comments on commit ef49968

Please sign in to comment.