FaceRecognition_With_FaceNet_Android icon indicating copy to clipboard operation
FaceRecognition_With_FaceNet_Android copied to clipboard

Works incorrectly in samsung A21s

Open emreakcan opened this issue 4 years ago • 9 comments

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?

emreakcan avatar Dec 02 '21 17:12 emreakcan

if I run the L2Norm with the FloatArrays that I get from the Xiaomi, Samsung can do the calculation correctly.

emreakcan avatar Dec 02 '21 18:12 emreakcan

This is because of different device configurations. Probably switching off the GpuDelegate and XNNPack might help. In the FaceNetModel.kt class, you'll see these lines,

init {
    // Initialize TFLiteInterpreter
    val interpreterOptions = Interpreter.Options().apply {
        // Add the GPU Delegate if supported.
        // See -> https://www.tensorflow.org/lite/performance/gpu#android
        if ( CompatibilityList().isDelegateSupportedOnThisDevice ) {
            addDelegate( GpuDelegate( CompatibilityList().bestOptionsForThisDevice ))
        }
        else {
            // Number of threads for computation
            setNumThreads( 4 )
        }
        setUseXNNPACK( true )
    }
    interpreter = Interpreter(FileUtil.loadMappedFile(context, model.assetsFilename ) , interpreterOptions )
    Logger.log("Using ${model.name} model.")
}

Replace these lines with,

init {
    // Initialize TFLiteInterpreter
    val interpreterOptions = Interpreter.Options().apply {    
         setNumThreads( 4 )
    }
    interpreter = Interpreter(FileUtil.loadMappedFile(context, model.assetsFilename ) , interpreterOptions )
    Logger.log("Using ${model.name} model.")
}

shubham0204 avatar Dec 03 '21 04:12 shubham0204

@emreakcan Could you resolve the error by removing GpuDelegate?

shubham0204 avatar Dec 10 '21 11:12 shubham0204

HI @shubham0204,

I'm also facing the same issue with face recognition. Initially, it generated multiple results for the same face. But now after removing the GPUDelegate and XNNPack, for all the faces it is giving me the same result as unknown.

DineshIT avatar Apr 25 '22 02:04 DineshIT

@DineshIT can you send me some more details of the Samsung A21 device on which you're testing the app? I need these details specifically:

  1. Android OS Version
  2. GPU Renderer
  3. Supported ABIs
  4. CPU architecture

You can get these details by installing the Device Info app on the device.

shubham0204 avatar Apr 25 '22 14:04 shubham0204

Hi Shubham,

Please find the details below.

  1. Android OS Version - Android 11 - R [API Level 30]
  2. GPU Renderer - Mali-G52
  3. Supported ABIs - arm64-v8a, armeabi-v7a, armeabi
  4. CPU architecture - 8 * 2.00 Ghz

If you need any other details please let me know.

On Mon, Apr 25, 2022 at 7:52 PM Shubham Panchal @.***> wrote:

@DineshIT https://github.com/DineshIT can you send me some more details of the Samsung A21 device on which you're testing the app? I need these details specifically:

  1. Android OS Version
  2. GPU Renderer
  3. Supported ABIs
  4. CPU architecture

You can get these details by installing the Device Info https://play.google.com/store/apps/details?id=com.ytheekshana.deviceinfo app on the device.

— Reply to this email directly, view it on GitHub https://github.com/shubham0204/FaceRecognition_With_FaceNet_Android/issues/25#issuecomment-1108643191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7WWBMXE6FUFWM34CDSPTDVG2TBVANCNFSM5JHXRYAQ . You are receiving this because you were mentioned.Message ID: <shubham0204/FaceRecognition_With_FaceNet_Android/issues/25/1108643191@ github.com>

-- -With great regards Dineshkumar

DineshIT avatar Apr 25 '22 17:04 DineshIT

Hi @shubham0204

I have worked on this issue and fixed it by adding the properties in the interpreter class object.

Please check my commit in the repo and merge it to handle this issue.

Hi @emreakcan

You can make the mentioned changes in your FaceNetModel Class and verify whether this issue got fixed at your end. If you got success please share with us.

DineshIT avatar May 06 '22 05:05 DineshIT

@DineshIT Can you open a PR in this repo, so that I can review the changes?

shubham0204 avatar May 06 '22 12:05 shubham0204

PR has been created

DineshIT avatar May 09 '22 08:05 DineshIT