Git Product home page Git Product logo

shubham0204 / facerecognition_with_facenet_android Goto Github PK

View Code? Open in Web Editor NEW
240.0 240.0 84.0 377.81 MB

Face Recognition using the FaceNet model and MLKit on Android.

Home Page: https://towardsdatascience.com/using-facenet-for-on-device-face-recognition-with-android-f84e36e19761

License: Apache License 2.0

Kotlin 100.00%
android android-application android-studio embeddings face-detection face-recognition facenet-model firebase-mlkit kotlin kotlin-android machine-learning tensorflow2

facerecognition_with_facenet_android's Introduction

github_banner

Shubham Panchal

Reach me at

Profiles

OSS Projects

Rust

  • text-predictor-android: Next word prediction and word auto-complete for Android - with the power of Rust
  • tfidf-summarizer.rs tfidf-text-summarizer downloads: Simple, efficient and cross-platform TFIDF-based text summarizer in Rust
  • postagger.rs postagger downloads: NLTK inspired Parts-of-Speech Tagger (Perceptron Tagger) in Rust
  • pq.rs: Pure Rust implementation of Product Quantization for Approximate Nearest Neighbor Search
  • diff-tool.rs: A simple terminal-based diff tool written in Rust

Web

Backend

Data Structures / Algorithms

Mobile ML

Android

Blogs

Google Colab Notebooks - Tutorials

Spotlight

Pull Requests

facerecognition_with_facenet_android's People

Contributors

dineshit avatar eduardo-avelar avatar shubham0204 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facerecognition_with_facenet_android's Issues

Works incorrectly in samsung A21s

App working correctly on all devices I have, but somehow on Samsung A21s, it is producing incorrect results.
It is nearly producing same output for all faces probability between .2 .3, for l2, cosine is also the same.

I thought maybe camera is the problem, so I embedded the pictures inside drawable and matched, but still it is producing nearly the same results for everything.

I noticed FloatArray returned from getCroppedFaceEmbedding producing different results for different phones.

My xiaomi mi9 works alright.

Do you have any ideas?

I am getting same name for every image in the frame

HI i am getting same name for every image i.e., first image name. may i know what is the problem. Please inform me is there any issue with code? If that face doesn't added in the folder also it is showing random name

[request] write detection log to a file

I apologize for asking something so basic.

How can I save in a local text file the name of the faces that the application has detected?

Thank you very much for your help.

[Error] : Getting facelist.size as 0 in FrameAnalyser.kt

Hi, i am getting facelist.size is ''0'' . may i know why this is coming.
After that one i am getting this log I/Model: Average score for each user : {}
and then it is going into cache the error in cache was

E/Model: Exception in FrameAnalyser : null

Can you explain why this is going to cache and what i have to do to work the sample properly.

I am using using your latest code.
once the app is launched it cannot show the bounding box over the face.

Please solve my issue as possible as fast.

App is hanging with 300 Images

I really appreciated this works very well with few images. How to avoid blocking UI and also to work smoothly with many no of images ?

Access denied finding property "ro.mediatek.platform"!

Hi,

I try to build the project and debug it after press USE THIS FOLDER button, suddenly the apps crash and here is the error message

` detectFacesImageByteArray.start()
Access denied finding property "ro.mediatek.platform"
detectFacesImageByteArray.end()
FATAL EXCEPTION: main
Process: com.ml.quaterion.facenetdetection, PID: 5566
java.lang.IllegalArgumentException: x must be >= 0
at android.graphics.Bitmap.checkXYSign(Bitmap.java:432)
at android.graphics.Bitmap.createBitmap(Bitmap.java:862)
at android.graphics.Bitmap.createBitmap(Bitmap.java:825)
at com.ml.quaterion.facenetdetection.BitmapUtils$Companion.cropRectFromBitmap(BitmapUtils.kt:46)
at com.ml.quaterion.facenetdetection.FileReader$getEmbedding$2.invokeSuspend(FileReader.kt:109)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4a30289, Dispatchers.Main]

Please help!

TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread

FATAL EXCEPTION: main
Process: com.ml.quaterion.facenetdetection, PID: 11467
java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: Can not open OpenCL library on this device - dlopen failed: library "libOpenCL.so" not found
Falling back to OpenGL
TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread where it was initialized.
Node number 181 (TfLiteGpuDelegateV2) failed to invoke.
at org.tensorflow.lite.NativeInterpreterWrapper.run(Native Method)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:249)
at org.tensorflow.lite.InterpreterImpl.runForMultipleInputsOutputs(InterpreterImpl.java:133)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:80)
at org.tensorflow.lite.InterpreterImpl.run(InterpreterImpl.java:126)
at org.tensorflow.lite.Interpreter.run(Interpreter.java:80)
at com.ml.quaterion.facenetdetection.model.FaceNetModel.runFaceNet(FaceNetModel.kt:87)
at com.ml.quaterion.facenetdetection.model.FaceNetModel.getFaceEmbedding(FaceNetModel.kt:79)
at com.ml.quaterion.facenetdetection.FileReader$getEmbedding$2.invokeSuspend(FileReader.kt:108)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@a0c68f4, Dispatchers.Main]

Application of tflite models and how to convert them.

Hi, I encounter the following error when using a tflite model that has been converted and quantized by toco.

Process: com.ml.quaterion.facenetdetection, PID: 4034
java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (input) with 76800 bytes from a Java Buffer with 307200 bytes.
at org.tensorflow.lite.TensorImpl.throwIfSrcShapeIsIncompatible(TensorImpl.java:416)
at org.tensorflow.lite.TensorImpl.setTo(TensorImpl.java:140)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:243)
at org.tensorflow.lite.InterpreterImpl.runForMultipleInputsOutputs(InterpreterImpl.java:107)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:80)
at org.tensorflow.lite.InterpreterImpl.run(InterpreterImpl.java:100)
at org.tensorflow.lite.Interpreter.run(Interpreter.java:80)
at com.ml.quaterion.facenetdetection.model.FaceNetModel.runFaceNet(FaceNetModel.kt:104)
at com.ml.quaterion.facenetdetection.model.FaceNetModel.getFaceEmbedding(FaceNetModel.kt:83)
at com.ml.quaterion.facenetdetection.FileReader$getEmbedding$2.invokeSuspend(FileReader.kt:108)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) 

The model is converted from facenet pretrained model to tflite by QUANTIZED_UINT8 format, the model size is reduced from 93MB to about 23MB, the problem should be caused by the mismatch between UINT8 and FLOAT, I would like to ask how to convert the tflite model in the assets directory of the project and reduce the model size while maintaining the FLOAT format.

Works on phone but not on tablet

Hello,

The application runs well in two phones that I tested but not in a tablet, when i try to install it show an error message "There was a problem parsing the package".

What could it be?

l2 Norm not working as expected.

Hi,

It was a great code thanks for it.

I am struggling from few days, but could able to achieve face recognition.

  1. I have taken 2 photos of each my 7 friends. (of 720X720, I dont thing this matter much as we crop it to 160x160)
  2. I launched and it processed it (Took some time to process it).
  3. But the detection not working well. It is giving random names.

Is it possible to have SVM integrated with this module?

Internal error: Failed to apply delegate with GpuDelegate

at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8387)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: ModifyGraphWithDelegate is disallowed when graph is immutable.
at org.tensorflow.lite.NativeInterpreterWrapper.applyDelegate(Native Method)
at org.tensorflow.lite.NativeInterpreterWrapper.applyDelegates(NativeInterpreterWrapper.java:373)
at org.tensorflow.lite.NativeInterpreterWrapper.init(NativeInterpreterWrapper.java:85)
at org.tensorflow.lite.NativeInterpreterWrapper.(NativeInterpreterWrapper.java:63)
at org.tensorflow.lite.Interpreter.(Interpreter.java:277)
at com.ml.quaterion.facenetdetection.model.FaceNetModel.(FaceNetModel.kt:73)
at com.ml.quaterion.facenetdetection.MainActivity.onCreate(MainActivity.kt:122)
at android.app.Activity.performCreate(Activity.java:8121)
at android.app.Activity.performCreate(Activity.java:8109)


private val useGpu = true
private val useXNNPack = true
private val modelInfo = Models.FACENET_QUANTIZED

Recognition is not happening

I've created the images folder as you mentioned in ReadMe document but still face recognition is not happening. I'm getting following logs

2020-09-14 22:31:51.541 26060-26060/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:51.550 26060-26060/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:51.564 26060-26060/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:51.589 26060-26093/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "persist.vendor.camera.privapp.list"
2020-09-14 22:31:51.603 26060-26078/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:51.603 26060-26078/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:51.722 26060-26093/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "persist.vendor.camera.privapp.list"
2020-09-14 22:31:51.733 26060-26078/com.ml.quaterion.facenetdetection E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2020-09-14 22:31:52.414 26060-26212/com.ml.quaterion.facenetdetection E/Infoooooooooooooo: 90
2020-09-14 22:31:53.088 26060-26212/com.ml.quaterion.facenetdetection E/Infoooooooooooooo: 90

.listfiles giving a null exception (in app error could not read images)

Hi Shubham,
I wanted to test the efficiency of facenet tf lite model so i tried running your app but it always gives the toast as " could not read images make sure you have files according to readme "

I rebuild your app and added the google services file, i added all the READ/WRITE permissions and i found that imageDir give the proper director but imageDir.listfiles return a null exception. I have directories in the images folder as specified but it is unable to list them

Thread Exception: Only the original thread that created a view hierarchy can touch its views

Hi I am trying to run it on API 21, But in FrameAnalyser.kt line no 164 boundingBoxOverlay.invalidate() will through exception.
Please help me I am a beginner Thanks in advance.

E/AndroidRuntime: FATAL EXCEPTION: Thread-3
Process: com.example.facerecognition, PID: 12921
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7809)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1338)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:5446)
at android.view.View.invalidateInternal(View.java:14749)
at android.view.View.invalidate(View.java:14713)
at android.view.View.invalidate(View.java:14697)
at com.example.facerecognition.FrameAnalyser$analyze$1$1.run(FrameAnalyser.kt:150)
at java.lang.Thread.run(Thread.java:762)

[issue] Always assign a face even if the image does not exist.

I've done the following test.

I take a photograph of a person (my friend Tom) and put it in his folder. I open the app and the app reads the folder (I only have one person).

ok, the app recognizes all people like Tom, shouldn't it show a warning that his photograph is missing or directly ignore those people?

(if necessary I can record a video showing it to you)

best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.