Qualeams / Android-Face-Recognition-with-Deep-Learning-Library

Face Recognition library for Android devices is an Android library (module) which includes several face recognition methods.
Apache License 2.0
373 stars 134 forks source link

New face recognised with any other face add in this #13

Open eramitsharma957 opened 7 years ago

eramitsharma957 commented 7 years ago

Hi friends, I m facing an issue if any new face will recognize and then given any old user name on that face.

sladomic commented 7 years ago

Hi, a lot of people asked this same question. The implementation here is not face identification but face recognition. What you are asking for would be to have a confidence score. If the confidence score is below a threshold it would name the person as "unknown".

But this is not implemented yet, but you can find more information on how to implement it https://github.com/Qualeams/Android-Face-Recognition-with-Deep-Learning-Test-Framework/issues/14 and https://github.com/Qualeams/Android-Face-Recognition-with-Deep-Learning-Library/issues/8

eramitsharma957 commented 7 years ago

New face recognized matched with an already added old face. if new face not added in this.

eramitsharma957 commented 7 years ago

how to find confidence score

eramitsharma957 commented 7 years ago

Hi sladomic Give me any solution for how to show message to user's face not registered if new face recognize on app

eramitsharma957 commented 7 years ago

Hi sladomic Plz give m any solution for this, new face recognized without add face.

sladomic commented 7 years ago

Hi, as already mentioned, this feature is not implemented, but you can try to implement it by yourself. I will share some emails I have shared with other people already.


What you ask for is used in face identification (confidence score). A lot of people asked for this, but I’m afraid, that I don’t have any time to implement this by myself at the moment (maybe in a few months).

But I can share with you what I shared with others regarding this function.

I hope this helps for a start. Best would be if you research for confidence score and probably you can come up with an implementation of a good algorithm and even share it (commit it) to the library so anyone could benefit.

Thanks and best regards, Michael

————————————————————————————————————————— E-Mail —————————————————————————————————————————

Dear XXX,

First of all thanks for the interest and feedback.

Face recognition generally doesn't include the feature you mentioned. This is more a task of face identification.

But since a few other people already had the same question, you can try to implement a confidence score and set a threshold (experiment a bit to set it at the right point), so that you only tell the name if the confidence score is about the threshold and "unknown" if below.

https://github.com/Qualeams/Android-Face-Recognition-with-Deep-Learning-Test-Framework/issues/14

Here and especially in the last comment you can find information of how this could be implemented.

Please note that the confidence score I proposed is not 100% accurate. If you want to train it correctly you would need to implement a bit more complex algorithms.

Best regards

————————————————————————————————————————— E-Mail —————————————————————————————————————————

Hello Sir,

Can you please help me with face identification, i tried to implement confidance score using below code.


double dotProduct = featureVector.dot(featureVectorToRecognize); double normFeatureVector = Core.norm(featureVector, Core.NORM_L2); double normFeatureVectorToRecognize = Core.norm(featureVectorToRecognize, Core.NORM_L2); double cosineSimilarity = dotProduct / (normFeatureVector * normFeatureVectorToRecognize); double absoluteCosineSimilarity = Math.abs(cosineSimilarity);


But still there is not much difference that i can distuinguiss between registered and non registered faces. I have tried my best, it will be very helpfull to me if you can help me with face identification. Please help me, Thanks in advance.

————————————————————————————————————————— E-Mail —————————————————————————————————————————

Hi XXX,

Sorry, I don’t have much time at the moment.

What do you take as „featureVector“?

I just see the code here to calculate the cosineSimilarity, but not the code how you calculated the „featureVector“.

The featureVector here is the mean of all feature vectors of one person.

https://github.com/elimu-ai/authentication/blob/master/app/src/main/java/org/literacyapp/authentication/thread/TrainingThread.java on line 244 we reduce all feature vectors of one student to one feature vector (meanFeatureVector). This meanFeatureVector is then used in the cosineSimilarity calculation as „featureVector“.

So what you need to do in training is, to additionally calculate the meanFeatureVector per label/person and store this for later use (so that you don’t need to calculate it every time you do the recognition).

Then when you want to do the recognition, you load the meanFeatureVectors and after you’ve got the recognized person/label, calculate the cosineSimilarity by using the person’s meanFeatureVector and the current image (featureVectorToRecognize). Then if the value is above a threshold (e.g. 0.5), you print out the name and if it’s below, you print out „Unknown“.

Good luck and regards

eramitsharma957 commented 7 years ago

Thanks a lot I will try them :)

eramitsharma957 commented 7 years ago

hi, I am trying but not calculate confidence score so plz give m the solution..............

ashokbugude commented 7 years ago

@sladomic Please let us know in case you have implemented it .Thanks

eramitsharma957 commented 7 years ago

hi @sladomic any update about calculating confidence score. thank

ashokbugude commented 6 years ago

tensorflow_jni.cc has a function to return confidence score as shown below. Can I please know how do I make use of this function

// Returns the top N confidence values over threshold in the provided vector, // sorted by confidence in descending order. static void GetTopN( const Eigen::TensorMap<Eigen::Tensor<float, 1, Eigen::RowMajor>, Eigen::Aligned>& prediction, const int num_results, const float threshold, std::vector<std::pair<float, int> >* top_results) { // Will contain top N results in ascending order. std::priority_queue<std::pair<float, int>, std::vector<std::pair<float, int> >, std::greater<std::pair<float, int> > > top_result_pq;

const int count = prediction.size(); for (int i = 0; i < count; ++i) { const float value = prediction(i);

// Only add it if it beats the threshold and has a chance at being in
// the top N.
if (value < threshold) {
  continue;
}

top_result_pq.push(std::pair<float, int>(value, i));

// If at capacity, kick the smallest value out.
if (top_result_pq.size() > num_results) {
  top_result_pq.pop();
}

}

sladomic commented 6 years ago

Hi

That's because they use the softmax function as the last layer in the CNNs. The softmax function gives you a probability for each class.

So instead of using KNN or SVM you could add a new classifier (softmax) and should then have the ability to use confidence scores.

ashokbugude commented 6 years ago

@sladomic Thanks very much for your help . Could you PLEASE provide some inputs on how to add the 'softmax' classifier instead of using KNN or SVM in the project . I shall try to implement it

sladomic commented 6 years ago

Hmm I doubt that this will work https://www.tensorflow.org/tutorials/image_retraining

  1. I think you need more than just 20 images per person (e.g. 1000)
  2. Tensorflow for Android removes some of the functions/operations so the training might not even be possible
  3. The training might not be feasible on a mobile device (but maybe it's fast enough once the bottleneck features have been computed and stored for reuse)

If you really want to try out I would suggest you first gry it out on a PC. There the transfer learning should work with python. But for Android you would need to adapt the python code, build TensorFlow with special instructions for the operations and then it might still not be feasible. But on a PC you can try it out with lesd effort (still some effort though).

ashokbugude commented 6 years ago

@sladomic Thanks I have been looking at the link for past few days. (i am ready to implement irrespective of mobile or PC) Everything is fine, but the only problem is 'Python'.
I was looking for similar type of stuff only in C++ (need for a particular research purpose) so that it can be easily integrated in this project (or on PC) but unable to find it. :( If you find similar content for C++ , please let me know :)

ashokbugude commented 6 years ago

Could I please know if the below implementation is possible

Currently the output Image Classification is 128 numbers for each training image which is then fed to SVM for training.

Instead of providing these 128 numbers of each image as input to SVM for training, Could we provide these 128 numbers of each image as input tensorflow to create a graph/model file at runtime as shown in a link which is implemented in python http://jackytung8085.blogspot.in/2016/06/loading-tensorflow-graph-with-c-api-by.html (Create Graph section) OR http://www.wolfib.com/Image-Recognition-Intro-Part-1/

If so , how do we provide these 128 numbers of each image as input to create tensorflow graph/model file ?

sladomic commented 6 years ago

The setup would then be as follows:

  1. Detection
  2. Preprocessing (at least resize the input)
  3. Extract bottleneck features (embeddings layer in facenet)
  4. Train 1-layer NN with 128 inputs and N-classes output and softmax activation function

Yes, that should be possible on a PC but on Android only with modifications in the build of TF for Android (google for "tensorflow no opkernel android") if you want to execute step 4. Also best would be to save the features of step 3 so they don't need to be extracted every time but can be reused (extract once per image and then save the 128-vector per image to save time).

chithrabaskar commented 6 years ago

sir how can i get the recognized label name from the coding.....may i use this code for face login ??

sladomic commented 6 years ago

Dear @chithrabaskar sorry but I don't get the question.

If you want to use it for face login you need to tweak it. At least you would need to add probabilities so you could check against a threshold if the probability is high enough for the person (confidence score) and you would need to add eye tracking, so you could detect eye blinks (so the recognition cannot be fooled by a photo)

chithrabaskar commented 6 years ago

thank u sir...sorry for my late reply...how and where to add probabilities??..can you explain in detail??

Zumbalamambo commented 6 years ago

@sladomic Thanks... Modifying the architecture a bit helped me to get the confidence rate..

rautsunil commented 6 years ago

@Zumbalamambo , Great to hear you made it working ,but I am still facing the same problem to the confidence score on the Android App . I am using KNN. Could you please help me in to achieve confidence score.

innodeltech commented 5 years ago

I am trying but not change camera Orientation so please give m the solution..............

MaulyGabriel commented 5 years ago

has this functionality been implemented?

rushabhdasinfomedia commented 4 years ago

What is the confidence score below threshold value for unknown people?

venkatidssoft commented 4 years ago

hi, can anyone implemented New face recognised with out adding face add in this please mail me.. ssc,kadiyala@gmail.com

rp-star commented 4 years ago

I am using this library but probelm is that every mobile perfect work but huwai p20 and google nexus 5 crass . when take pic once click when going to detacting face now crass at a time ...my friend in japan he have 2 device nexux 5 and huwai p20 both are in crass..if you have any idea any why do work as like ..so please help me ..i am 10 days working on this problem but does not solve this isue....