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

arcface人脸特征提取不同人脸,计算的相似度都一样,是怎么回事呢? #36

Closed
goldwater668 opened this issue Nov 19, 2021 · 6 comments

Comments

@goldwater668
Copy link

余弦距离计算代码:
def cosine_distance(matrix1, matrix2):
matrix1_matrix2 = np.dot(matrix1, matrix2.transpose())
matrix1_norm = np.sqrt(np.multiply(matrix1, matrix1).sum(axis=1))
matrix1_norm = matrix1_norm[:, np.newaxis]
matrix2_norm = np.sqrt(np.multiply(matrix2, matrix2).sum(axis=1))
matrix2_norm = matrix2_norm[:, np.newaxis]
cosine_distance = np.divide(matrix1_matrix2, np.dot(matrix1_norm, matrix2_norm.transpose()))
return cosine_distance

是不是没有进行归一化呢,归一化有没有好的函数推荐呢?

@shouxieai
Copy link
Owner

a = np.random.rand(1, 8)
b = np.random.rand(1, 8)
cosine_distance = (a @ b.T) / (np.linalg.norm(a) * np.linalg.norm(b))

@goldwater668
Copy link
Author

我按照你上述的公式:
train_feature=arcface.commit(train_crop,train_face.landmark).get()
test_feature=arcface.commit(test_crop,test_face.landmark).get()
dist = np.dot(train_feature,test_feature.transpose()) / (np.linalg.norm(train_feature) * np.linalg.norm(test_feature))
得出结果却是:
./face/recognize/2ys1.jpg
dist: [[1.0000001]]
dist: [[1.0000001]]
./face/recognize/2ys3.jpg
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000002]]
dist: [[1.0000001]]
dist: [[1.0000001]]
./face/recognize/2ys5.jpg
dist: [[1.0000001]]
dist: [[1.0000001]]
dist: [[1.0000001]]
./face/recognize/2ys2.jpg
dist: [[1.0000001]]

@shouxieai
Copy link
Owner

提交了arcface案例,请参考:https://github.com/shouxieai/tensorRT_Pro/blob/main/python/test_arcface.py

@goldwater668
Copy link
Author

@shouxieai AttributeError: 'trtpy.libtrtpyc.FaceBox' object has no attribute 'width'

@shouxieai
Copy link
Owner

重新编译后解决

@goldwater668
Copy link
Author

@shouxieai arcface在进行特征提取的时候,为什么需要输入人脸关键点呢?retinaface中有一个函数crop_face_and_landmark裁剪的人脸很大,我想自己裁剪人脸,然后输入到arcface中进行特征提取,应该怎么做呢,之所以这样做,是因为发现提取有些同一个
人脸特征相似度相差很大

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

2 participants