Qualeams / Android-Face-Recognition-with-Deep-Learning-Test-Framework

Face Recognition framework for Android devices can be used to test different face recognition methods.
Apache License 2.0
359 stars 160 forks source link

Errors using 'Recognition Training' using TensorFlow #18

Closed ashokbugude closed 7 years ago

ashokbugude commented 7 years ago

I have set classification method as TensorFlow in PreferencesHelper.java through following way

public String getClassificationMethod(){ return resources.getString(R.string.tensorflow); }

But when I click 'Recognition Training' button in UI after setting above, I get below error

05-26 12:03:23.790 18148-18428/ch.zhaw.facerecognition E/native: tensorflow_jni.cc:269 Error during inference: Invalid argument: Session was not created with a graph before Run()! 05-26 12:10:11.683 18148-18428/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:310 Image dimensions: 224x224 stride: 896 05-26 12:10:11.683 18148-18428/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:233 Tensorflow: Copying Data. 05-26 12:10:11.699 18148-18428/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:251 Start computing. 05-26 12:10:11.699 18148-18428/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:264 End computing. Ran in 0ms (0ms avg over 2 runs) 05-26 12:10:11.699 18148-18428/ch.zhaw.facerecognition E/native: tensorflow_jni.cc:269 Error during inference: Invalid argument: Session was not created with a graph before Run()! 05-26 12:10:11.700 18148-18428/ch.zhaw.facerecognition I/System.out: 1

FATAL EXCEPTION: Thread-2410 Process: ch.zhaw.facerecognition, PID: 2209 java.lang.NumberFormatException: Invalid float: "" at java.lang.StringToReal.invalidReal(StringToReal.java:63) at java.lang.StringToReal.parseFloat(StringToReal.java:308) at java.lang.Float.parseFloat(Float.java:306) at ch.zhaw.facerecognitionlibrary.Recognition.TensorFlow.getFeatureVector(TensorFlow.java:145) at ch.zhaw.facerecognitionlibrary.Recognition.TensorFlow.addImage(TensorFlow.java:127) at ch.zhaw.facerecognition.Activities.TrainingActivity$1.run(TrainingActivity.java:108) at java.lang.Thread.run(Thread.java:818)

sladomic commented 7 years ago

I guess the model file is missing:

See "Deep learning with Convolutional Neural Networks" in https://github.com/Qualeams/Android-Face-Recognition-with-Deep-Learning-Test-Framework/blob/master/USER%20MANUAL.md#manualfor

ashokbugude commented 7 years ago

Thanks, I have added model file now. When I click 'Recognition Training' , The white screen appears twice and the app goes back to home screen without displaying any messages like 'file no 1 imported etc'

The code stops execution at Line No 137 in TensorFlow.java , ie String s1=classifyImageBmp(inputLayer, outputLayer, outputSize, bmp);

I receive a warning message in terminal as below 05-26 12:40:06.408 13182-13413/ch.zhaw.facerecognition I/libprotobuf-native: [libprotobuf INFO external/protobuf/src/google/protobuf/io/coded_stream.cc:610] Reading dangerously large protocol message. If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.

with below messages 05-26 12:40:06.668 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:129 Creating session. 05-26 12:40:06.738 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:138 Tensorflow graph loaded from: /storage/emulated/0/Pictures/facerecognition/data/TensorFlow/vgg_faces.pb 05-26 12:40:06.738 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:143 Initialization done in 3446ms 05-26 12:40:07.098 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:310 Image dimensions: 224x224 stride: 896 05-26 12:40:07.098 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:233 Tensorflow: Copying Data. 05-26 12:40:07.108 13182-13413/ch.zhaw.facerecognition I/native: tensorflow_jni.cc:251 Start computing.

and stops after this

sladomic commented 7 years ago

How much RAM does your device have? Test the Inception model first as this is much smaller. If the Inception model works, this would mean, that you don't have enough RAM for the VGG model.

ashokbugude commented 7 years ago

I was earlier testing on 2GB RAM. Now I have tested on 4GB RAM.Its working fine. But its slow as indicated in readme file . 6.27 s / image Thanks for your help.

Do you have any idea on how to increase its speed by paralleling some of the code ( which part/section of code in TensorFlow be parallelised ? for eg Convolution) in TensorFLow

sladomic commented 7 years ago

Google announced TensorFlow Lite and also the Android Neural Network API at Google I/O. But both is not out yet. I think in the next weeks and months we will see huge improvements for mobile devices.

Also the VGG model can be optimized for mobile inference (but for me it didn't improve the overall performance much).

ashokbugude commented 7 years ago

Thanks, one last help related to this.

Can I know where is the function definition of 'session->Run(input_tensors, output_names, {}, &output_tensors);' present in the function 'ClassifyImage' in tensorflow_jni.cc.

When I go to its implementation in Android Studio, it opens a file called 'session.h' where there is only function declaration but not its implementation

After going through docs, i found that its a part of C++api , if so, can I know where is this particular Sesion api defined so that it can be modified

sladomic commented 7 years ago

It's part of the TensorFlow C++ API. Probably here https://github.com/Qualeams/Android-Face-Recognition-with-Deep-Learning-Library/blob/v1.4.0/jni-build/jni/include/tensorflow/core/common_runtime/session.cc but probably also in the compiled lib files.

ashokbugude commented 7 years ago

Thanks, Also I am not able to hit any breakpoints in c++ code for eg in tensorflow_jni.cc.Can I know if I need to write any code anywhere to enable it in Android studio