justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.71k stars 3.72k forks source link

Load image take too much time #817

Closed danies8 closed 3 years ago

danies8 commented 3 years ago

Hi, I used this face-api.js (https://github.com/justadudewhohacks/face-api.js) and I have to load 10000 images when the node server is loaded for future comparison operations. This the function that I load when server is loaded, it take 0.5 second to one picture, how can I improve it ?

**// fetch first image of each class and compute their descriptors
async function createBbtFaceMatcher() {

  await faceDetectionNet.loadFromDisk(path.join(__dirname, '../weights'))
  await faceapi.nets.faceLandmark68Net.loadFromDisk(path.join(__dirname, '../weights'))
  await faceapi.nets.faceRecognitionNet.loadFromDisk(path.join(__dirname, '../weights'))

  const labeledFaceDescriptors = await Promise.all(classes.map(
    async className => {
      let descriptors: any = [];
      let uri = getFaceImageUri(className, 1);
      const img = await canvas.loadImage(uri);
      if (img) {
        let descriptor = await faceapi.computeFaceDescriptor(img);
        if (descriptor) {
          descriptors.push(descriptor);
        }
      }
      return new faceapi.LabeledFaceDescriptors(
        className,
        descriptors
      )
    }
  )) 

return new faceapi.FaceMatcher(labeledFaceDescriptors) }**

vladmandic commented 3 years ago

Faceapi uses very lightweight and quite old way of determining face descriptors. My other algorithms have improved since.

danies8 commented 3 years ago
  1. I used this link :https://github.com/vladmandic/face-api/blob/master/demo/node-image.js to register an image , is it not good enough?
  2. You said :"My other algorithms have improved since"?which?
vladmandic commented 3 years ago

I've modernized FaceAPI (and your link is correct), but ML models are still pretty dated by today's standard.
A year ago I started writing new library from scratch and by now it supersedes FaceAPI in pretty much everything:
https://github.com/vladmandic/human

danies8 commented 3 years ago

Thank you very much -:)