ronghuaiyang / arcface-pytorch

1.74k stars 392 forks source link

how can i test on my own dataset? #46

Open ZZH2950228 opened 4 years ago

garg-7 commented 4 years ago

To test on your own dataset, you need to a 'list.txt' file (in addition to the dataset formatted in the correct form obviously). There is a text file called 'lfw_test_pair.txt' which specifies the hierarchy in which you need to arrange your dataset. Then from that, you have to create your own list.txt file which contains true (1) and false (0) pairs just like the 'lfw_test_pair.txt'. Finally, place the dataset and the text file, in the paths mentioned in the 'config\config.py' file (Lines 21 and 22 to be precise) and you should be good to go.

barcahoo commented 4 years ago

@garg-7 so how to create my own list.txt file like the 'lfw_test_pair.txt' , could you plz show the codes ,thx!

garg-7 commented 4 years ago

Sorry, I've been away for a while. @barcahoo To create your own list file, you could write a script using the os module in python to traverse the directories that contain the images and write to a list.txt file side-by-side. Ping me back if you face any issues there.

Hanmiaojun commented 3 years ago

@garg-7 Hello, I want to know how to get the test results. For example, I input a face and how to get the recognition accuracy. I only saw the verification results in the lfw data set, but I don’t understand the recognition part. How to input part of face recognition data list?

garg-7 commented 3 years ago

Hi @Houmengjun, I'm not aware of how much you know about this project but it's working like this -

  1. You input a face and the network creates an embedding (i.e. vectorized representation) of that face. You do this for a bunch of faces against which you wish to run recognition in the future. These embeddings are stored.
  2. At test time, when you come across an unknown face, it is sent to the network, that again creates an embedding which is now matched against all the embeddings that were created in Step 1.

This comparison is being done using the cosine metric. This was the working of the recognition part.

I didn't get what you meant by the last line -

How to input part of face recognition data list?

Hanmiaojun commented 3 years ago

@garg-7 I know what you mean, thank you very much! I really want to know where is the code of the recognition part you told me in the test phase of this project? The meaning of the last line is: For example, I mixed my frontal photo with many other people's face pictures and used a self-portrait as a test image. How do I enter data into this network? I know that the test done on the lfw dataset is called face verification, but I want to figure out how to get the recognition accuracy. Looking forward to your reply!

garg-7 commented 3 years ago

@Houmengjun Oh. I think I got what you're asking. For generalized testing, you'll need to make some changes to the test.py file.

What you could do is -

  1. Use line 141 as present in test.py:

    features, cnt = get_featurs(model, img_paths, batch_size=batch_size)

    What's happening here is you simply pass a list of full file paths for the reference images as img_paths and the model returns the features and the count in features, cnt respectively.

  2. Now you could save these features, say in some JSON or pickle file.

  3. Then again at test time, you run the line in step 1 for the test images. This time you just load all the features you stored in step 2. Compare the test image(s)' features against each loaded feature, using line 99 of test.py:

    def cosin_metric(x1, x2):
    return np.dot(x1, x2) / (np.linalg.norm(x1) * np.linalg.norm(x2))

    This function returns how good a match there is between two features x1 and x2. (cosine measure so inverted value in some sense.)

From this, you should be able to get an idea as to what is the degree of similarity, and then you could figure out if the scores come out as you had expected or not. With that information, you can calculate the accuracy of recognition.

Hanmiaojun commented 3 years ago

Thank you very much for your reply! I will try my best to achieve it! Thank you, my friend, can you add an email address? @garg-7 @

garg-7 commented 3 years ago

@Houmengjun Glad I could help.