huangyangyu / SeqFace

SeqFace : Making full use of sequence information for face recognition
https://arxiv.org/pdf/1803.06524.pdf
MIT License
129 stars 32 forks source link

could please share the new similarity method? #11

Open anguoyang opened 5 years ago

anguoyang commented 5 years ago

It seems the result on new sim method is really good on your demo page, could you please share it? thank you

DickyQi commented 5 years ago

yes, new result is much better then simple cos distance. I am eager for new method sharing.

huangyangyu commented 5 years ago

We just use a function to map cos distance to similarity score, which is a segment linear function with two thresholds. The face pair whose cos distance is less than the first threshold are considered same, whose cos distance is larger than the second one are considered different, whose cos distance is between the two thresholds are unsure.

anguoyang commented 5 years ago

hi @huangyangyu 非常感谢。英文打字比较累,还是说中文吧,希望不要介意:) 另外,还有一个问题,我在windows/CPU编译了一下代码,运行也没问题,然后提取特征的时候,发现fc5的512个float值有些非常大,比如317.xxx之类的,然后我通过cos 计算两个array的相似度的时候,任意两张人脸的相似度都是99%,很奇怪,然后我看了一下代码: def cos_sim(v1, v2): dist = np.linalg.norm(np.array(v1)-np.array(v2)) cos = 1 - dist * dist / 2 return cos 这个貌似不是cos的计算公式吧

anguoyang commented 5 years ago

另外,我看到这个代码,貌似是在给每个float值做标准化? def get_feature(featurer, image_dir, feature_dim=512): final_feature = np.zeros(feature_dim) for name in os.listdir(image_dir): image_file = image_dir + name feature = featurer.test(image_file=image_file) if feature is not None: final_feature += feature / np.linalg.norm(feature, ord=2) final_feature /= np.linalg.norm(final_feature, ord=2) return final_feature

不太理解的是,为何要把所有图片的feature加起来,如果我只想针对单张图片提取特征呢

huangyangyu commented 5 years ago

A1: The final features are normalized. The formula can be verified equally. A2: YTF dataset is a video dataset. Each id of test set contains several faces. We just merged the face set.

anguoyang commented 5 years ago

Thank you for your response, but I really puzzled on the output of fc5 layer, because when I calculate the cos sim between two float vectors, I always get the same result, even if by the function above. I used the mtcnn for face detection, and same alignment method with insight face(but resized it into 144x144 according to your evaluate.py) The alignment method I used is: https://github.com/deepinsight/insightface/tree/master/cpp-align Could you please give me some advice on possible reason? I am sure there is no problem on your source code, even though I used C++ for inference, thank you.

anguoyang commented 5 years ago

I also tried to normalize the output of fc5, this is what I have done: 1.compiled your source code on windows, successfully 2.modified and compiled the classify demo in C++ https://github.com/BVLC/caffe/blob/master/examples/cpp_classification/classification.cpp(I DO NOT use the classify function, but the prediction: std::vector output = Predict(img);) 3.Do face detection using mtcnn and align the face with above method, and resize it into 144x144, on 2 images(each image with 1 face, they belong to different people) 4.Send the 2 aligned faces into neural network, and get the output vectors std::vector output = Predict(img); 5.Normalized and Compared 2 output vectors with cos similarity, I always get 100%, even if they belong to different people, and I tried several image pairs, the same result.

huangyangyu commented 5 years ago

Actually, i have release all the code from model sharing to feature extracting. You can refer to the detail. It seems like you have some problems in model inference. Different input images should get different output features.


发件人: goodman notifications@github.com 发送时间: 2019年6月20日 16:20 收件人: huangyangyu/SeqFace 抄送: Harry Wong; Mention 主题: Re: [huangyangyu/SeqFace] could please share the new similarity method? (#11)

I also tried to normalize the output of fc5, this is what I have done: 1.compiled your source code on windows, successfully 2.modified and compiled the classify demo in C++ https://github.com/BVLC/caffe/blob/master/examples/cpp_classification/classification.cpp(Ihttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FBVLC%2Fcaffe%2Fblob%2Fmaster%2Fexamples%2Fcpp_classification%2Fclassification.cpp(I&data=02%7C01%7C%7C23cb7b453e224f69c19408d6f55833c5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636966156503709511&sdata=1qkxeZbUADT3x4QNsJc3SQkTLfYf9ba7kPJFgrEtivQ%3D&reserved=0 DO NOT use the classify function, but the prediction: std::vector output = Predict(img);) 3.Do face detection using mtcnn and align the face with above method, and resize it into 144x144, on 2 images(each image with 1 face, they belong to different people) 4.Send the 2 aligned faces into neural network, and get the output vectors std::vector output = Predict(img); 5.Normalized and Compared 2 output vectors with cos similarity, I always get 100%, even if they belong to different people, and I tried several image pairs, the same result.

― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fhuangyangyu%2FSeqFace%2Fissues%2F11%3Femail_source%3Dnotifications%26email_token%3DACN4AU3Q4F5DR7YU3XSUE5LP3M4WDA5CNFSM4HSZUO4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYEVKTI%23issuecomment-503928141&data=02%7C01%7C%7C23cb7b453e224f69c19408d6f55833c5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636966156503719517&sdata=hTc56trNHpxMeChfl6RrcfDyl1aifPY9BNgx0oEtQpU%3D&reserved=0, or mute the threadhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACN4AUZ4C3GVEHH5ZAH5H43P3M4WDANCNFSM4HSZUO4A&data=02%7C01%7C%7C23cb7b453e224f69c19408d6f55833c5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636966156503729528&sdata=CwFYDwNAHROy1U1Y3003n6Bo66e6PJKLgol3AAMtTtI%3D&reserved=0.