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.

Error: FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>

See original GitHub issue

The documentation for FaceMatcher throws an exception in NodeJS. Although faceapi.detectAllFaces finds faces, new faceapi.FaceMatcher(faceResults) throws an exception. Can you please let us know what we should be doing here?

Code:

  await faceapi.nets.ssdMobilenetv1.loadFromDisk(modelUrl)
  await faceapi.nets.faceLandmark68Net.loadFromDisk(modelUrl)
  await faceapi.nets.faceRecognitionNet.loadFromDisk(modelUrl)

  const faceBase64 = 'data:image/jpg;base64,' + fs.readFileSync(`./tests/data/face1.jpg`, {encoding: 'base64'})
  const faceImage = new Image()
  faceImage.src = faceBase64
  const faceResults = await faceapi.detectAllFaces(faceImage)
      .withFaceLandmarks()
      .withFaceDescriptors()

  if (!faceResults.length) { // length is 1
    return
  }
  const faceMatcher = new faceapi.FaceMatcher(faceResults) // --> Exception
Error: FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>

    at /Users/.../node_modules/face-api.js/src/globalApi/FaceMatcher.ts:40:13
    at Array.map (<anonymous>)
    at new FaceMatcher (/Users/.../node_modules/face-api.js/src/globalApi/FaceMatcher.ts:27:43)
    at ...

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
chanduthedevcommented, Jul 9, 2020

Hi @Karthik-tr , thank you for pointing out. I also faced same error after adding your code. Actually faceResults is a list with one item and not a json object. So to access descriptor, you need to specify index like faceResults[0].descriptor

Try below code, it should work.

const faceResults = await faceapi.detectAllFaces(img).withFaceLandmarks().withFaceDescriptors()
if(faceResults ) {
   descriptions = [faceResults[0].descriptor]
}
const singlelabeledDescriptor = new faceapi.LabeledFaceDescriptors(label,descriptions )
0reactions
karthik-Gopalancommented, Jul 9, 2020

Yes i use a single face detector. Hence I made the mistake of assuming that the descriptor only has one object. Mine works well. Thanks for the inputs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Float32Array - JavaScript - MDN Web Docs
Chrome Edge Float32Array Full support. Chrome7. Toggle history Full support. Edge12... Float32Array() constructor Full support. Chrome7. Toggle history Full support. Edge12... Constructor without parameters Full support....
Read more >
FaceMatcher | face-api.js
Constructors. constructor. new FaceMatcher(inputs: LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors ...
Read more >
Face recognition in javascript using face api getting "Uncaught ...
Apologies for the delay, my problem was solved by changing the images. The error was because it could not identify a face (descriptor)...
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