question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

faceDescriptors of different faces are exactly the same? What am I doing wrong?

See original GitHub issue

Hi I am running faceapi.detectSingleFace(image).withFaceLandmarks().withAgeAndGender().withFaceDescriptor(); of different images/faces and most not all of them have the exact same faceDescriptor values. This seems wrong. Looking at their detection object, they clearly are different. What am I doing wrong?

Here is my code where I try to find unique faces.

export const detectFace = async (image, frameNumber, detectionArray, uniqueFaceArray) => {
  // detect expression
  const face = await faceapi.detectSingleFace(image).withFaceLandmarks().withAgeAndGender().withFaceDescriptor();

  console.log(frameNumber);
  // check if a face was detected
  if (face !== undefined) {
    const { age, gender, descriptor, detection } = face;
    const { relativeBox, score } = detection;
    const size = Math.round(relativeBox.height * 100);
    const scoreInPercent = Math.round(score * 100);

    // console.log(face);
    if (size < FACE_SIZE_THRESHOLD || scoreInPercent < FACE_DETECTION_CONFIDENCE_SCORE) {
      console.log('detected face below size or confidence threshold!');
      return undefined;
    }

    // create full copy of array to be pushed later
    const copyOfDescriptor = descriptor.slice();

    console.log(detection);
    console.log(uniqueFaceArray);
    // console.log(copyOfDescriptor);

    // initialise the faceId
    let faceId = 0;

    // check for uniqueness
    // if the uniqueFaceArray is empty just push the current descriptor
    // else compare the current descriptor to the ones in the uniqueFaceArray
    const uniqueFaceArrayLength = uniqueFaceArray.length;
    if (uniqueFaceArrayLength === 0) {
      uniqueFaceArray.push(copyOfDescriptor);
    } else {
      // compare descriptor value with all values in the array
      for (let i = 0; i < uniqueFaceArrayLength; i += 1) {
        const dist = faceapi.euclideanDistance(copyOfDescriptor, uniqueFaceArray[i]);
        console.log(`${faceId}, ${frameNumber}`);
        console.log(dist);
        // if no match was found add the current descriptor to the array marking a unique face
        if (dist < FACE_UNIQUENESS_THRESHOLD) {
          // console.log(`face matches face ${i}`);
          faceId = i;
          break;
        } else if (i === uniqueFaceArrayLength - 1) {
          console.log('face is unique');
          uniqueFaceArray.push(copyOfDescriptor);
          faceId = uniqueFaceArrayLength;
        }
      }
    }

    // console.log(`frameNumber: ${frameNumber}, Score: ${score}, Size: ${size}, Gender: ${gender}, Age: ${age}`);
    detectionArray.push({
      faceId,
      frameNumber,
      score: scoreInPercent,
      size,
      gender,
      age: Math.round(age),
    })
    return detection;
  }
  console.log('no face detected!');
  return undefined;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fakobcommented, Feb 7, 2020

Finally I made it work and it seems that reading the images properly also has solved the originally stated issue. I was unfortunately not successful with node-canvas, but made it work with tfjs-node. Thanks to @whyboris for the tip!

import * as tf from '@tensorflow/tfjs-node';

const input = tf.node.decodeJpeg(jpgImage);
1reaction
justadudewhohackscommented, Jan 28, 2020

exact same faceDescriptor value

This is indeed very suspicious, can you post an example image where this issue occurs?

The only two reasons I can think of is, that somethings wrong with your code, or theres something going wrong in the tfjs backend due to your system environment.

Could you give some information about your environment? (browser or nodejs, which browser / nodejs version, your OS and which backend you are using, cpu or webgl)

Read more comments on GitHub >

github_iconTop Results From Across the Web

What to do with face descriptors of the same person from ...
The question is NOT how to serialize them, but when there are hundreds of different photos of the same person, yet each yielding...
Read more >
Texture mapping, Part 2
The faceVertexUvs property is an array of an array of “face descriptors”. Each face descriptor is an array of exactly three “face texture...
Read more >
How to Perform Face Recognition With VGGFace2 in Keras
Face detection is the process of automatically locating faces in a photograph and localizing them by drawing a bounding box around their extent....
Read more >
Facial Recognition SPA for BNK48 Idol group using React and ...
Just like fingerprint, Face Descriptor is a unique value of each face. Face Descriptors of same person from different image sources should ...
Read more >
Hyperfamiliarity for faces - PMC - NCBI - NIH
Facial familiarity can be dissociated from semantic or autobiographic elements of episodic memory since we may feel that we saw a face before,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found